classic-ui/modules/account/store/actions/checkExistAccount.js

34 lines
874 B
JavaScript
Raw Normal View History

2022-06-09 12:41:41 -04:00
import { getEventsFromBlockPart } from './utils'
2022-04-21 23:05:56 -04: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 12:41:41 -04:00
const events = await getEventsFromBlockPart({
netId,
currentBlockNumber,
address: ethAccount,
echoContract: getters.echoContract
})
const isExist = Boolean(Array.isArray(events) && Boolean(events.length))
2022-04-21 23:05:56 -04:00
console.log('isExist', isExist)
dispatch('createMutation', {
type: 'CHECK_ACCOUNT',
payload: { isExist }
})
} catch (err) {
throw new Error(`Method checkExistAccount has error: ${err.message}`)
}
}