classic-ui/modules/account/store/actions/recoverAccountFromChain/recoverAccountFromChain.js
Danil Kovtonyuk 44f31f8b9f
init
2022-04-22 13:14:19 +10:00

14 lines
567 B
JavaScript

export async function recoverAccountFromChain({ dispatch, rootState }) {
const { ethAccount } = rootState.metamask
try {
const { encryptedKey, backup } = await dispatch('getAccountFromAddress', ethAccount)
const { address, publicKey, privateKey } = await dispatch('decryptAccount', encryptedKey)
this.$sessionStorage.setItem(address, privateKey)
dispatch('saveAccount', { account: { publicKey, privateKey: encryptedKey }, address, backup })
} catch (err) {
throw new Error(`Method recoverAccountFromChain has error: ${err.message}`)
}
}