diff --git a/components/Step.vue b/components/Step.vue index 09db41a..807b7e1 100644 --- a/components/Step.vue +++ b/components/Step.vue @@ -67,7 +67,28 @@
-

{{ data.description }}

+

+ {{ data.description }} +

+
+
+
+ Address: + + {{ airdrop.address }} + +
+ Value: {{ airdrop.value }} vTORN +
+
+
diff --git a/components/Steps.vue b/components/Steps.vue index fd05f40..ef71967 100644 --- a/components/Steps.vue +++ b/components/Steps.vue @@ -1,6 +1,6 @@ @@ -14,6 +14,23 @@ export default { }, computed: { ...mapState('steps', ['steps']), + ...mapState('airdrop', ['airdrops']), + getData() { + if (Array.isArray(this.airdrops)) { + return this.steps.map((step, index) => { + if (step.contract === 'Airdrop.sol') { + return { + ...step, + airdrops: this.airdrops[index - this.airdrops.length + 2], + } + } + + return step + }) + } + + return this.steps + }, }, } diff --git a/layouts/default.vue b/layouts/default.vue index 3514544..5750df7 100644 --- a/layouts/default.vue +++ b/layouts/default.vue @@ -38,9 +38,12 @@ export default { this.fetchDeploymentStatus() this.statusPooling() this.fetchGasPrice() + + this.setAirdropAddresses() }, methods: { ...mapActions('provider', ['initProvider']), + ...mapActions('airdrop', ['setAirdropAddresses']), ...mapActions('steps', ['statusPooling', 'fetchDeploymentStatus']), ...mapActions('gasPrice', ['fetchGasPrice']), }, diff --git a/store/airdrop/actions.js b/store/airdrop/actions.js new file mode 100644 index 0000000..fc400e1 --- /dev/null +++ b/store/airdrop/actions.js @@ -0,0 +1,19 @@ +import { localStorage } from '@/utillites' + +import { SET_AIRDROP } from './constant' + +export default { + setAirdropAddresses({ getters, commit }) { + const savedActions = localStorage.getItem('actions') + + if (savedActions) { + commit(SET_AIRDROP, savedActions) + return + } + + const actions = getters.selectAirdropData + + localStorage.setItem('actions', actions) + commit(SET_AIRDROP, actions) + }, +} diff --git a/store/airdrop/constant.js b/store/airdrop/constant.js new file mode 100644 index 0000000..cbb73d3 --- /dev/null +++ b/store/airdrop/constant.js @@ -0,0 +1 @@ +export const SET_AIRDROP = 'airdrop/SET_BALANCE' diff --git a/store/airdrop/getters.js b/store/airdrop/getters.js new file mode 100644 index 0000000..0fa1592 --- /dev/null +++ b/store/airdrop/getters.js @@ -0,0 +1,31 @@ +import { fromWei } from 'web3-utils' + +import deploymentActions from '~/static/deploymentActions.json' + +export default { + getAirdrops: (state) => { + return state.airdrops + }, + selectAirdropsActions: () => { + return deploymentActions.actions.filter( + (action) => action.contract === 'Airdrop.sol' + ) + }, + selectAirdropData: (state, getters) => { + const actions = getters.selectAirdropsActions + + return actions.map((action) => { + const data = action.bytecode.split(state.secretCode)[1] + + // eslint-disable-next-line no-unused-vars + const [_, ...addressInfo] = data.match(/.{128}/g) + + return addressInfo.map((info) => { + return { + address: `0x${info.slice(24, 64)}`, + value: fromWei(info.slice(64, 128)), + } + }) + }) + }, +} diff --git a/store/airdrop/mutations.js b/store/airdrop/mutations.js new file mode 100644 index 0000000..4292e62 --- /dev/null +++ b/store/airdrop/mutations.js @@ -0,0 +1,7 @@ +import { SET_AIRDROP } from './constant' + +export default { + [SET_AIRDROP](state, airdrops) { + this._vm.$set(state, 'airdrops', airdrops) + }, +} diff --git a/store/airdrop/state.js b/store/airdrop/state.js new file mode 100644 index 0000000..529cfab --- /dev/null +++ b/store/airdrop/state.js @@ -0,0 +1,5 @@ +export default () => ({ + airdrops: [], + secretCode: + 'd6d5ad7ec98c44fe89ef66c3277ef0ec7b1acbd7e0134bc1291fd952d7ff6030', +})