From 872a0612c77f210fd51597355f4fbbf817fb50ba Mon Sep 17 00:00:00 2001 From: Ayagoumi Date: Sun, 3 Dec 2023 08:50:15 +0100 Subject: [PATCH] Refactor ClaimRewards component --- .../wallet/earn/Validate/AddValidator.vue | 13 - .../wallet/earn/Validate/ClaimRewards.vue | 222 ++++++------------ .../wallet/earn/Validate/RegisterNode.vue | 14 -- .../wallet/earn/Validate/ValidatorInfo.vue | 50 ++-- .../earn/Validate/ValidatorSuspended.vue | 14 -- src/views/wallet/Validator.vue | 107 ++++++++- 6 files changed, 179 insertions(+), 241 deletions(-) diff --git a/src/components/wallet/earn/Validate/AddValidator.vue b/src/components/wallet/earn/Validate/AddValidator.vue index a56805826..cb83a7bc2 100644 --- a/src/components/wallet/earn/Validate/AddValidator.vue +++ b/src/components/wallet/earn/Validate/AddValidator.vue @@ -893,19 +893,6 @@ label { margin-bottom: 6px; } -.disabled_input { - display: inline-block; - border-radius: var(--border-radius-sm); - color: gray; - background-color: var(--bg-light); - padding: 10px 14px; - width: 100%; -} - -.disabled_input:focus-visible { - outline: 0; -} - .input_label { margin-bottom: 0.5rem; } diff --git a/src/components/wallet/earn/Validate/ClaimRewards.vue b/src/components/wallet/earn/Validate/ClaimRewards.vue index 362317795..58f86121b 100644 --- a/src/components/wallet/earn/Validate/ClaimRewards.vue +++ b/src/components/wallet/earn/Validate/ClaimRewards.vue @@ -1,62 +1,48 @@ @@ -75,12 +61,14 @@ import Spinner from '@/components/misc/Spinner.vue' import { ava } from '@/AVA' import { bnToBigAvaxX } from '@/helpers/helper' import { WalletType } from '@/js/wallets/types' +import CamBtn from '@/components/CamBtn.vue' @Component({ components: { ModalClaimReward, PendingMultisig, Spinner, + CamBtn, }, }) export default class ClaimRewards extends Vue { @@ -102,9 +90,11 @@ export default class ClaimRewards extends Vue { } mounted() { - this.getClaimableReward() - this.getPChainAddress() - this.getPendingTransaction() + this.refresh() + } + + refresh() { + this.$emit('refresh') } beforeCloseModal(claimed: boolean) { @@ -122,27 +112,6 @@ export default class ClaimRewards extends Vue { } } - get rewardOwner() { - if (this.nodeInfo != null && this.nodeInfo != undefined) { - return this.nodeInfo.rewardOwner.addresses[0].toString() - } else { - return null - } - } - - async getClaimableReward() { - let responseClaimable = await WalletHelper.getClaimables( - this.nodeInfo.rewardOwner.addresses[0].toString(), - this.nodeInfo.txID - ) - - if (responseClaimable != null && responseClaimable != undefined) { - this.rewardAmount = responseClaimable.validatorRewards - } else { - this.rewardAmount = new BN(0) - } - } - openModalClaimReward() { this.$refs.modal_claim_reward.open() } @@ -176,34 +145,11 @@ export default class ClaimRewards extends Vue { } } - async getPChainAddress() { - try { - if (this.$store.state.activeWallet instanceof MultisigWallet) { - let activeWallet: MultisigWallet = this.$store.state.activeWallet - let address = activeWallet.getCurrentAddressPlatform() - this.pChainddress = address - this.isMultisignTx = true - } else { - let activeWallet: WalletType = this.$store.state.activeWallet - let address = await activeWallet.getAllAddressesP() - this.pChainddress = address[0] - this.isMultisignTx = false - } - } catch (e) { - console.error(e) - } - } - - async getPendingTransaction() { - if (this.isMultisignTx) { - let txClaim = this.$store.getters['Signavault/transactions'].find( - (item: any) => - item?.tx?.alias === this.pChainddress && - WalletHelper.getUnsignedTxType(item?.tx?.unsignedTx) === 'ClaimTx' - ) - this.pendingTx = txClaim + get rewardOwner() { + if (this.nodeInfo != null && this.nodeInfo != undefined) { + return this.nodeInfo.rewardOwner.addresses[0].toString() } else { - this.pendingTx = undefined + return null } } @@ -229,17 +175,17 @@ export default class ClaimRewards extends Vue { }, 100) } - async refresh() { - this.loading = true - await this.getClaimableReward() - await this.getPChainAddress() - await this.getPendingTransaction() - this.loading = false - } - get feeTx() { return bnToBigAvaxX(ava.PChain().getTxFee()) } + + getClaimableReward() { + this.$emit('getClaimableReward') + } + + getPendingTransaction() { + this.$emit('getPendingTransaction') + } } diff --git a/src/components/wallet/earn/Validate/ValidatorSuspended.vue b/src/components/wallet/earn/Validate/ValidatorSuspended.vue index c48d98e76..b9cec3468 100644 --- a/src/components/wallet/earn/Validate/ValidatorSuspended.vue +++ b/src/components/wallet/earn/Validate/ValidatorSuspended.vue @@ -64,20 +64,6 @@ h4 { } } -.disabled_input { - display: inline-block; - border-radius: var(--border-radius-sm); - color: gray; - background-color: var(--bg-light); - padding: 6px 14px; - white-space: nowrap; - width: 70%; -} - -.disabled_input:focus-visible { - outline: 0; -} - .input_label { margin-bottom: 0.5rem; } diff --git a/src/views/wallet/Validator.vue b/src/views/wallet/Validator.vue index cb4cde161..f412bc255 100644 --- a/src/views/wallet/Validator.vue +++ b/src/views/wallet/Validator.vue @@ -13,7 +13,7 @@

{{ $t('validator.info.validator_running') }}

-
+
- +
@@ -142,6 +151,8 @@ import { AvaNetwork } from '@/js/AvaNetwork' import Spinner from '@/components/misc/Spinner.vue' import moment from 'moment' import { ava } from '@/AVA' +import { MultisigWallet } from '@/js/wallets/MultisigWallet' +import { WalletType } from '@/js/wallets/types' @Component({ name: 'validator', @@ -182,6 +193,11 @@ export default class Validator extends Vue { bondedAmount: BN = new BN(0) txID: string = '' + rewardAmount: BN = new BN(0) + pChainddress: string = '' + isMultisignTx: boolean = false + pendingTx: any = undefined + // @ts-ignore helpers = this.globalHelper() @@ -371,19 +387,69 @@ export default class Validator extends Vue { } async refresh() { - if (this.multisigPendingNodeTx) { - await this.$store.dispatch('Signavault/updateTransaction') + if (this.tab == 'opt-rewards') { + await this.getClaimableReward() + } else { + if (this.multisigPendingNodeTx) { + await this.$store.dispatch('Signavault/updateTransaction') + await this.evaluateCanRegisterNode() + } + this.loadingRefreshRegisterNode = true + this.loading = true + this.$store.dispatch('updateBalances') await this.evaluateCanRegisterNode() + await this.updateValidators() + await this.$store.dispatch('Signavault/updateTransaction') + if (this.nodeInfo) await this.getInformationValidator() + this.loading = false + this.loadingRefreshRegisterNode = false + } + } + + async getPendingTransaction() { + if (this.isMultisignTx) { + let txClaim = this.$store.getters['Signavault/transactions'].find( + (item: any) => + item?.tx?.alias === this.pChainddress && + WalletHelper.getUnsignedTxType(item?.tx?.unsignedTx) === 'ClaimTx' + ) + this.pendingTx = txClaim + } else { + this.pendingTx = undefined + } + } + + async getClaimableReward() { + if (this.nodeInfo == null) return + + let responseClaimable = await WalletHelper.getClaimables( + this.nodeInfo.rewardOwner.addresses[0].toString(), + this.nodeInfo.txID + ) + + if (responseClaimable != null && responseClaimable != undefined) { + this.rewardAmount = responseClaimable.validatorRewards + } else { + this.rewardAmount = new BN(0) + } + } + + async getPChainAddress() { + try { + if (this.$store.state.activeWallet instanceof MultisigWallet) { + let activeWallet: MultisigWallet = this.$store.state.activeWallet + let address = activeWallet.getCurrentAddressPlatform() + this.pChainddress = address + this.isMultisignTx = true + } else { + let activeWallet: WalletType = this.$store.state.activeWallet + let address = await activeWallet.getAllAddressesP() + this.pChainddress = address[0] + this.isMultisignTx = false + } + } catch (e) { + console.error(e) } - this.loadingRefreshRegisterNode = true - this.loading = true - this.$store.dispatch('updateBalances') - await this.evaluateCanRegisterNode() - await this.updateValidators() - await this.$store.dispatch('Signavault/updateTransaction') - if (this.nodeInfo) await this.getInformationValidator() - this.loading = false - this.loadingRefreshRegisterNode = false } get hasValidator(): boolean { @@ -722,3 +788,18 @@ span { top: 15px; } +