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

34 lines
899 B
JavaScript
Raw Normal View History

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))
console.log('Is encrypted note events exist: ', isExist)
2022-04-22 06:05:56 +03:00
dispatch('createMutation', {
type: 'CHECK_ACCOUNT',
payload: { isExist }
})
} catch (err) {
throw new Error(`Method checkExistAccount has error: ${err.message}`)
}
}