/
ModalWithdrawAllRewards.vue
92 lines (89 loc) · 2.18 KB
/
ModalWithdrawAllRewards.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<template>
<action-modal
id="modal-withdraw-all-rewards"
ref="actionModal"
:submit-fn="submitForm"
:simulate-fn="simulateForm"
title="Withdraw"
class="modal-withdraw-rewards"
submission-error-prefix="Withdrawal failed"
>
<tm-form-group
class="action-modal-form-group"
field-id="amount"
field-label="Amount"
>
<span class="input-suffix">{{ num.viewDenom(bondDenom) }}</span>
<tm-field
id="amount"
v-model="totalRewards"
type="number"
readonly="readonly"
/>
</tm-form-group>
</action-modal>
</template>
<script>
import { mapGetters } from "vuex"
import num, { uatoms, atoms } from "../../scripts/num.js"
import ActionModal from "common/ActionModal"
import TmField from "common/TmField"
import TmFormGroup from "common/TmFormGroup"
export default {
name: `modal-withdraw-all-rewards`,
components: {
ActionModal,
TmField,
TmFormGroup
},
data: () => ({
num
}),
computed: {
...mapGetters([`bondDenom`, `distribution`, `lastHeader`, `session`]),
totalRewards({ bondDenom, distribution } = this) {
const rewards = distribution.totalRewards[bondDenom]
return (rewards && atoms(rewards)) || 0
}
},
watch: {
lastHeader: {
immediate: true,
handler() {
if (
this.session.signedIn &&
this.$refs.actionModal &&
this.$refs.actionModal.show
) {
this.$store.dispatch(`getTotalRewards`)
}
}
}
},
methods: {
open() {
this.$refs.actionModal.open()
},
async simulateForm() {
return await this.$store.dispatch(`simulateWithdrawAllRewards`)
},
async submitForm(gasEstimate, gasPrice, password, submitType) {
await this.$store.dispatch(`withdrawAllRewards`, {
gas: String(gasEstimate),
gas_prices: [
{
amount: String(uatoms(gasPrice)),
denom: this.bondDenom
}
],
submitType,
password
})
this.$store.commit(`notify`, {
title: `Successful withdrawal!`,
body: `You have successfully withdrawn your rewards.`
})
}
}
}
</script>