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

33 lines
875 B
JavaScript

import { numberToHex } from 'web3-utils'
import { packEncryptedMessage } from '@/utils'
export async function saveEncryptedAccount({ getters, dispatch }, { from, encryptedData, callback }) {
try {
const contract = getters.echoContract
const data = packEncryptedMessage(encryptedData)
const callData = contract.getCallData(data)
const gas = await contract.estimateGas({ from, data })
const callParams = {
method: 'eth_sendTransaction',
params: {
data: callData,
to: contract.address,
gas: numberToHex(gas + 10000)
},
watcherParams: {
title: 'accountSaving',
successTitle: 'accountSaved',
onSuccess: callback
},
isSaving: false
}
await dispatch('metamask/sendTransaction', callParams, { root: true })
} catch (err) {
throw new Error(err.message)
}
}