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