From b97b2312fa46d0cdc946eef247db38a9ea28f9a9 Mon Sep 17 00:00:00 2001 From: Danil Kovtonyuk Date: Tue, 3 Nov 2020 23:33:33 +1000 Subject: [PATCH] update fetchDeploymentStatus --- layouts/default.vue | 8 +++----- store/steps.js | 29 +++++++++++++++++++++-------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/layouts/default.vue b/layouts/default.vue index 675e1b8..8b541c8 100644 --- a/layouts/default.vue +++ b/layouts/default.vue @@ -27,17 +27,15 @@ export default { Loading, Notices, }, - mounted() { - this.fetchDeploymentStatus() - + async mounted() { const result = localStorage.getItem('provider') if (result && result.name) { - this.initProvider({ + await this.initProvider({ name: result.name, network: result.network, }) } - + this.fetchDeploymentStatus() this.fetchGasPrice() }, methods: { diff --git a/store/steps.js b/store/steps.js index 75ebef4..c5c4eca 100644 --- a/store/steps.js +++ b/store/steps.js @@ -1,4 +1,6 @@ /* eslint-disable no-console */ +import Web3 from 'web3' +import deploymentActions from '../static/deploymentActions.json' const state = () => { return { @@ -105,20 +107,31 @@ const getters = { const SET_DEPLOYER = 'SET_DEPLOYER' const mutations = { [SET_DEPLOYER](state, { stepIndex, deployerAddress }) { - console.log('SET_DEPLOYER', stepIndex, deployerAddress) - console.log('state.steps[stepIndex]', state.steps[stepIndex]) this._vm.$set(state.steps[stepIndex], 'deployerAddress', deployerAddress) }, } const actions = { - fetchDeploymentStatus({ state, dispatch, commit }) { + async fetchDeploymentStatus({ state, dispatch, commit, rootGetters }) { + const { rpcUrls } = rootGetters['provider/getNetwork'] + const web3 = new Web3(rpcUrls.Infura.url) + try { - // todo collect data from chain - commit(SET_DEPLOYER, { - stepIndex: 0, - deployerAddress: '0x03Ebd0748Aa4D1457cF479cce56309641e0a98F5', - }) + for (const [stepIndex, step] of state.steps.entries()) { + const { expectedAddress } = deploymentActions.actions.find((action) => { + return action.domain === step.domain + }) + + const code = await web3.eth.getCode(expectedAddress) + + if (code !== '0x') { + // todo collect deployerAddress from chain + commit(SET_DEPLOYER, { + stepIndex, + deployerAddress: '0x03Ebd0748Aa4D1457cF479cce56309641e0a98F5', + }) + } + } } catch (e) { console.error('fetchDeploymentStatus', e.message) }