init
This commit is contained in:
commit
44f31f8b9f
402 changed files with 47865 additions and 0 deletions
57
modules/account/store/getters/Contract.js
Normal file
57
modules/account/store/getters/Contract.js
Normal file
|
@ -0,0 +1,57 @@
|
|||
import Web3 from 'web3'
|
||||
|
||||
const ABI = [
|
||||
{
|
||||
anonymous: false,
|
||||
inputs: [
|
||||
{ indexed: true, internalType: 'address', name: 'who', type: 'address' },
|
||||
{ indexed: false, internalType: 'bytes', name: 'data', type: 'bytes' }
|
||||
],
|
||||
name: 'Echo',
|
||||
type: 'event'
|
||||
},
|
||||
{
|
||||
inputs: [{ internalType: 'bytes', name: '_data', type: 'bytes' }],
|
||||
name: 'echo',
|
||||
outputs: [],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
}
|
||||
]
|
||||
|
||||
export class EchoContract {
|
||||
constructor({ rpcUrl, address }) {
|
||||
this.web3 = new Web3(rpcUrl)
|
||||
|
||||
this.contract = new this.web3.eth.Contract(ABI, address)
|
||||
this.address = this.contract._address
|
||||
}
|
||||
|
||||
async getEvents({ address, fromBlock = 0, toBlock = 'latest' }) {
|
||||
try {
|
||||
return await this.contract.getPastEvents('Echo', {
|
||||
toBlock,
|
||||
fromBlock,
|
||||
filter: { who: address }
|
||||
})
|
||||
} catch (err) {
|
||||
throw new Error(`Method getEvents has error: ${err.message}`)
|
||||
}
|
||||
}
|
||||
|
||||
async estimateGas({ from, data }) {
|
||||
try {
|
||||
return await this.contract.methods.echo(data).estimateGas({ from })
|
||||
} catch (err) {
|
||||
throw new Error(`Method estimateGas has error: ${err.message}`)
|
||||
}
|
||||
}
|
||||
|
||||
getCallData(data) {
|
||||
try {
|
||||
return this.contract.methods.echo(data).encodeABI()
|
||||
} catch (err) {
|
||||
throw new Error(`Method getCallData has error: ${err.message}`)
|
||||
}
|
||||
}
|
||||
}
|
81
modules/account/store/getters/index.js
Normal file
81
modules/account/store/getters/index.js
Normal file
|
@ -0,0 +1,81 @@
|
|||
import { EchoContract } from './Contract'
|
||||
|
||||
import networkConfig from '@/networkConfig'
|
||||
|
||||
export const getters = {
|
||||
echoContract: (state, getters, rootState, rootGetters) => {
|
||||
const netId = rootState.metamask.netId
|
||||
const { url } = rootGetters['settings/currentRpc']
|
||||
const address = networkConfig[`netId${netId}`].echoContractAccount
|
||||
|
||||
return new EchoContract({ rpcUrl: url, address })
|
||||
},
|
||||
// selectors
|
||||
selectUi: (state, getters, rootState) => (key) => {
|
||||
const { netId } = rootState.metamask
|
||||
return state.ui[`netId${netId}`][key]
|
||||
},
|
||||
selectDomain: (state, getters, rootState) => (key) => {
|
||||
const { netId } = rootState.metamask
|
||||
return state.domain[`netId${netId}`][key]
|
||||
},
|
||||
// ui store
|
||||
isExistAccount: (state, getters) => {
|
||||
return getters.selectUi('isExistAccount')
|
||||
},
|
||||
accounts: (state, getters) => {
|
||||
return getters.selectUi('addresses')
|
||||
},
|
||||
statistic: (state, getters) => {
|
||||
const data = getters.selectUi('statistic')
|
||||
|
||||
if (Array.isArray(data)) {
|
||||
return data
|
||||
} else {
|
||||
return []
|
||||
}
|
||||
},
|
||||
noteAccountBalance: (state, getters, rootState, rootGetters) => {
|
||||
let balance = 0
|
||||
const nativeCurrency = rootGetters['metamask/nativeCurrency']
|
||||
|
||||
getters.statistic.forEach(({ currency, amount }) => {
|
||||
if (currency === nativeCurrency) {
|
||||
balance += Number(amount)
|
||||
}
|
||||
})
|
||||
|
||||
return balance
|
||||
},
|
||||
isSetupAccount: (state, getters) => {
|
||||
return Boolean(getters.selectUi('encryptedPublicKey'))
|
||||
},
|
||||
encryptedPublicKey: (state, getters) => {
|
||||
return getters.selectUi('encryptedPublicKey')
|
||||
},
|
||||
encryptedPrivateKey: (state, getters) => {
|
||||
return getters.selectUi('encryptedPrivateKey')
|
||||
},
|
||||
isEnabledSaveFile: (state, getters) => {
|
||||
return getters.selectUi('isEnabledSaveFile')
|
||||
},
|
||||
isHighlightedNoteAccount: (state, getters) => {
|
||||
return getters.selectUi('isHighlightedNoteAccount')
|
||||
},
|
||||
// domain store
|
||||
setupAccountRequest: (state, getters) => {
|
||||
return getters.selectDomain('setupAccount')
|
||||
},
|
||||
recoverAccountRequest: (state, getters) => {
|
||||
return getters.selectDomain('recoverAccountFromChain')
|
||||
},
|
||||
removeAccountRequest: (state, getters) => {
|
||||
return getters.selectDomain('removeAccount')
|
||||
},
|
||||
decryptNotesRequest: (state, getters) => {
|
||||
return getters.selectDomain('decryptNotes')
|
||||
},
|
||||
recoverAccountFromKeyRequest: (state, getters) => {
|
||||
return getters.selectDomain('recoverAccountFromKey')
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue