2022-06-09 19:41:41 +03:00
|
|
|
import { getEventsFromBlockPart } from './utils'
|
2022-04-22 06:05:56 +03:00
|
|
|
|
|
|
|
export async function checkExistAccount({ getters, dispatch, rootState, rootGetters }) {
|
|
|
|
const { ethAccount, netId } = rootState.metamask
|
|
|
|
|
|
|
|
if (!ethAccount) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
const rpc = rootGetters['settings/currentRpc']
|
|
|
|
const web3 = this.$provider.getWeb3(rpc.url)
|
|
|
|
const currentBlockNumber = await web3.eth.getBlockNumber()
|
|
|
|
|
2022-06-09 19:41:41 +03:00
|
|
|
const events = await getEventsFromBlockPart({
|
|
|
|
netId,
|
|
|
|
currentBlockNumber,
|
|
|
|
address: ethAccount,
|
|
|
|
echoContract: getters.echoContract
|
|
|
|
})
|
|
|
|
|
|
|
|
const isExist = Boolean(Array.isArray(events) && Boolean(events.length))
|
|
|
|
|
2022-04-22 06:05:56 +03:00
|
|
|
console.log('isExist', isExist)
|
|
|
|
|
|
|
|
dispatch('createMutation', {
|
|
|
|
type: 'CHECK_ACCOUNT',
|
|
|
|
payload: { isExist }
|
|
|
|
})
|
|
|
|
} catch (err) {
|
|
|
|
throw new Error(`Method checkExistAccount has error: ${err.message}`)
|
|
|
|
}
|
|
|
|
}
|