getBallotsLimits after the wallet was enabled
This commit is contained in:
parent
9559fe4273
commit
c8047f9520
|
@ -43,7 +43,7 @@ class App extends Component {
|
|||
const { commonStore, contractsStore } = this.props
|
||||
|
||||
if (!commonStore.loading) {
|
||||
enableWallet(contractsStore.setKeys)
|
||||
enableWallet(contractsStore.updateKeys)
|
||||
.then(() => {
|
||||
if (!contractsStore.injectedWeb3) {
|
||||
swal({
|
||||
|
|
|
@ -378,7 +378,7 @@ export class BallotCard extends React.Component {
|
|||
const { commonStore, contractsStore, id, votingType, ballotsStore, pos } = this.props
|
||||
|
||||
try {
|
||||
await enableWallet(contractsStore.setKeys)
|
||||
await enableWallet(contractsStore.updateKeys)
|
||||
} catch (error) {
|
||||
swal('Error', error.message, 'error')
|
||||
return
|
||||
|
@ -475,7 +475,7 @@ export class BallotCard extends React.Component {
|
|||
const contract = this.getContract(contractsStore, votingType)
|
||||
|
||||
try {
|
||||
await enableWallet(contractsStore.setKeys)
|
||||
await enableWallet(contractsStore.updateKeys)
|
||||
} catch (error) {
|
||||
swal('Error', error.message, 'error')
|
||||
return
|
||||
|
@ -546,7 +546,7 @@ export class BallotCard extends React.Component {
|
|||
const { push } = this.props.routing
|
||||
|
||||
try {
|
||||
await enableWallet(contractsStore.setKeys)
|
||||
await enableWallet(contractsStore.updateKeys)
|
||||
} catch (error) {
|
||||
swal('Error', error.message, 'error')
|
||||
return
|
||||
|
|
|
@ -255,7 +255,7 @@ export class NewBallot extends React.Component {
|
|||
const { push } = this.props.routing
|
||||
|
||||
try {
|
||||
await enableWallet(contractsStore.setKeys)
|
||||
await enableWallet(contractsStore.updateKeys)
|
||||
} catch (error) {
|
||||
swal('Error', error.message, 'error')
|
||||
return
|
||||
|
|
10
src/index.js
10
src/index.js
|
@ -38,7 +38,7 @@ class AppMainRouter extends Component {
|
|||
|
||||
initChain = () => {
|
||||
const netId = window.localStorage.netId
|
||||
getWeb3(netId, this.onAccountChange)
|
||||
getWeb3(netId, contractsStore.updateKeys)
|
||||
.then(async web3Config => {
|
||||
await this.initialize(web3Config)
|
||||
commonStore.hideLoading()
|
||||
|
@ -108,12 +108,10 @@ class AppMainRouter extends Component {
|
|||
this.initChain()
|
||||
}
|
||||
|
||||
onAccountChange = account => {
|
||||
this.setKeys(account)
|
||||
}
|
||||
|
||||
setKeys = async account => {
|
||||
await contractsStore.setKeys(account)
|
||||
await contractsStore.setMiningKey(account)
|
||||
await contractsStore.setVotingKey(account)
|
||||
|
||||
console.log('votingKey', contractsStore.votingKey)
|
||||
console.log('miningKey', contractsStore.miningKey)
|
||||
}
|
||||
|
|
|
@ -214,10 +214,17 @@ class ContractsStore {
|
|||
}
|
||||
}
|
||||
|
||||
@action('Set keys')
|
||||
setKeys = async account => {
|
||||
@action('Update keys')
|
||||
updateKeys = async account => {
|
||||
if (this.votingKey === account) return
|
||||
|
||||
this.setVotingKey(account)
|
||||
await this.setMiningKey(account)
|
||||
|
||||
console.log('votingKey', this.votingKey)
|
||||
console.log('miningKey', this.miningKey)
|
||||
|
||||
await this.getBallotsLimits()
|
||||
}
|
||||
|
||||
@action('Get all keys ballots')
|
||||
|
@ -415,6 +422,7 @@ class ContractsStore {
|
|||
@action
|
||||
async getBallotsLimits() {
|
||||
return new Promise(async resolve => {
|
||||
console.log('>>>>>>>>>>>>>>>>>>>>>>>')
|
||||
if (this.web3Instance && this.netId) {
|
||||
const limitPerValidator = await this.ballotsStorage.instance.methods.getBallotLimitPerValidator().call()
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import messages from './messages'
|
|||
|
||||
const defaultNetId = helpers.netIdByBranch(constants.CORE)
|
||||
|
||||
export async function enableWallet(setKeys) {
|
||||
export async function enableWallet(updateKeys) {
|
||||
if (window.ethereum) {
|
||||
try {
|
||||
await window.ethereum.enable()
|
||||
|
@ -17,12 +17,12 @@ export async function enableWallet(setKeys) {
|
|||
const accounts = await web3.eth.getAccounts()
|
||||
|
||||
if (accounts[0]) {
|
||||
await setKeys(accounts[0])
|
||||
await updateKeys(accounts[0])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default async function getWeb3(netId = defaultNetId, onAccountChange) {
|
||||
export default async function getWeb3(netId = defaultNetId, updateKeys) {
|
||||
let web3 = null
|
||||
netId = Number(netId)
|
||||
|
||||
|
@ -55,7 +55,7 @@ export default async function getWeb3(netId = defaultNetId, onAccountChange) {
|
|||
const account = obj.selectedAddress
|
||||
if (account && account !== currentAccount) {
|
||||
currentAccount = account
|
||||
onAccountChange(account)
|
||||
updateKeys(account)
|
||||
}
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue