fix: withdraw modal

This commit is contained in:
Danil Kovtonyuk 2022-07-05 20:33:29 +10:00
parent 756b544dee
commit 8ab6c3026f
No known key found for this signature in database
GPG Key ID: E72A919BF08C3746
3 changed files with 31 additions and 63 deletions

View File

@ -189,7 +189,7 @@ export default {
} }
}, },
computed: { computed: {
...mapState('application', ['note', 'errors', 'withdrawType', 'ethToReceive']), ...mapState('application', ['note', 'withdrawType', 'ethToReceive']),
...mapState('relayer', ['isLoadingRelayers']), ...mapState('relayer', ['isLoadingRelayers']),
...mapGetters('txHashKeeper', ['txExplorerUrl']), ...mapGetters('txHashKeeper', ['txExplorerUrl']),
...mapGetters('application', ['isNotEnoughTokens', 'selectedStatisticCurrency']), ...mapGetters('application', ['isNotEnoughTokens', 'selectedStatisticCurrency']),
@ -291,24 +291,6 @@ export default {
} }
} }
}, },
errors: {
handler(errors) {
console.log('error', errors)
this.error = {
type: errors.length ? this.$t('error') : null,
message: errors[errors.length - 1]
}
if (this.error.message) {
this.$store.dispatch('notice/addNoticeWithInterval', {
notice: {
untranslatedTitle: this.error.message,
type: 'warning'
}
})
}
},
deep: true
},
withdrawNote: { withdrawNote: {
async handler(withdrawNote) { async handler(withdrawNote) {
this.error = { this.error = {
@ -450,7 +432,7 @@ export default {
console.log(`Get logs: ${err.message}`) console.log(`Get logs: ${err.message}`)
} }
}, },
onWithdraw() { async onWithdraw() {
const note = this.withdrawNote.split('-')[4] const note = this.withdrawNote.split('-')[4]
if (note.length !== 126) { if (note.length !== 126) {
this.error = { this.error = {
@ -459,14 +441,26 @@ export default {
} }
return return
} }
try { try {
this.withdrawAddress = toChecksumAddress(this.withdrawAddress) this.withdrawAddress = toChecksumAddress(this.withdrawAddress)
this.$store.dispatch('application/prepareWithdraw', { } catch {
this.error = {
type: this.$t('validationError'),
message: this.$t('recipientAddressIsInvalid')
}
return
}
try {
this.$store.dispatch('loading/enable', { message: this.$t('generatingProof') })
await this.$store.dispatch('application/prepareWithdraw', {
note: this.withdrawNote, note: this.withdrawNote,
recipient: this.withdrawAddress recipient: this.withdrawAddress
}) })
this.error.type = null
this.currentModal = this.$buefy.modal.open({ this.$buefy.modal.open({
parent: this, parent: this,
component: WithdrawModalBox, component: WithdrawModalBox,
hasModalCard: true, hasModalCard: true,
@ -476,12 +470,20 @@ export default {
withdrawType: this.withdrawType withdrawType: this.withdrawType
} }
}) })
} catch (e) { } catch (err) {
this.error = { this.error = {
type: this.$t('validationError'), type: this.$t('error'),
message: this.$t('recipientAddressIsInvalid') message: err.message
} }
console.error('error', e)
this.$store.dispatch('notice/addNoticeWithInterval', {
notice: {
untranslatedTitle: err.message,
type: 'warning'
}
})
} finally {
this.$store.dispatch('loading/disable')
} }
}, },
onSettings() { onSettings() {

View File

@ -5,7 +5,7 @@
<button type="button" class="delete" @click="$emit('close')" /> <button type="button" class="delete" @click="$emit('close')" />
</header> </header>
<div class="note" data-test="withdrawal_confirmation_text"> <div class="note" data-test="withdrawal_confirmation_text">
{{ message }} {{ $t('yourZkSnarkProofHasBeenSuccesfullyGenerated') }}
</div> </div>
<b-button type="is-primary is-fullwidth" data-test="withdrawal_confirm_button" @click="_sendWithdraw"> <b-button type="is-primary is-fullwidth" data-test="withdrawal_confirm_button" @click="_sendWithdraw">
{{ $t('confirm') }} {{ $t('confirm') }}
@ -14,7 +14,6 @@
</template> </template>
<script> <script>
/* eslint-disable no-console */ /* eslint-disable no-console */
import { mapState } from 'vuex'
export default { export default {
props: { props: {
@ -27,13 +26,7 @@ export default {
required: true required: true
} }
}, },
data() {
return {
message: ''
}
},
computed: { computed: {
...mapState('application', ['notes', 'errors']),
withdrawalMethod() { withdrawalMethod() {
if (this.withdrawType === 'wallet') { if (this.withdrawType === 'wallet') {
return 'application/withdraw' return 'application/withdraw'
@ -42,24 +35,6 @@ export default {
return 'relayer/relayTornadoWithdraw' return 'relayer/relayTornadoWithdraw'
} }
}, },
watch: {
notes(newNotes) {
if (newNotes[this.note]) {
this.$store.dispatch('loading/disable')
this.message = this.$t('yourZkSnarkProofHasBeenSuccesfullyGenerated')
}
},
errors: {
handler(type) {
this.$store.dispatch('loading/disable')
this.$parent.close()
},
deep: true
}
},
beforeCreate() {
this.$store.dispatch('loading/enable', { message: this.$t('generatingProof') })
},
methods: { methods: {
async _sendWithdraw() { async _sendWithdraw() {
this.$store.dispatch('loading/enable', { message: this.$t('preparingTransactionData') }) this.$store.dispatch('loading/enable', { message: this.$t('preparingTransactionData') })

View File

@ -55,7 +55,6 @@ const state = () => {
note: null, note: null,
commitment: null, commitment: null,
prefix: null, prefix: null,
errors: [],
notes: {}, notes: {},
statistic: defaultStatistics, statistic: defaultStatistics,
ip: {}, ip: {},
@ -80,12 +79,6 @@ const mutations = {
REMOVE_PROOF(state, { note }) { REMOVE_PROOF(state, { note }) {
this._vm.$delete(state.notes, note) this._vm.$delete(state.notes, note)
}, },
SAVE_ERROR(state, message) {
state.errors.push(message)
},
REMOVE_ERRORS(state) {
this._vm.$set(state, 'errors', [])
},
SAVE_LAST_INDEX(state, { nextDepositIndex, anonymitySet, currency, amount }) { SAVE_LAST_INDEX(state, { nextDepositIndex, anonymitySet, currency, amount }) {
const currentState = state.statistic[currency][amount] const currentState = state.statistic[currency][amount]
this._vm.$set(state.statistic[currency], `${amount}`, { ...currentState, nextDepositIndex, anonymitySet }) this._vm.$set(state.statistic[currency], `${amount}`, { ...currentState, nextDepositIndex, anonymitySet })
@ -765,7 +758,6 @@ const actions = {
return { args, proof } return { args, proof }
}, },
async prepareWithdraw({ dispatch, getters, commit }, { note, recipient }) { async prepareWithdraw({ dispatch, getters, commit }, { note, recipient }) {
commit('REMOVE_ERRORS')
commit('REMOVE_PROOF', { note }) commit('REMOVE_PROOF', { note })
try { try {
const parsedNote = parseNote(note) const parsedNote = parseNote(note)
@ -789,7 +781,7 @@ const actions = {
commit('SAVE_PROOF', { proof, args, note }) commit('SAVE_PROOF', { proof, args, note })
} catch (e) { } catch (e) {
console.error('prepareWithdraw', e) console.error('prepareWithdraw', e)
commit('SAVE_ERROR', e.message) throw new Error(e.message)
} }
}, },
async withdraw({ state, rootState, dispatch, getters }, { note }) { async withdraw({ state, rootState, dispatch, getters }, { note }) {
@ -951,7 +943,6 @@ const actions = {
} }
} catch (e) { } catch (e) {
console.error(`Method loadWithdrawalData has error: ${e}`) console.error(`Method loadWithdrawalData has error: ${e}`)
commit('SAVE_ERROR', e.message)
} }
}, },
calculateEthToReceive({ commit, state, rootGetters }, { currency }) { calculateEthToReceive({ commit, state, rootGetters }, { currency }) {