Skip to content

Commit 79ed033

Browse files
evavirsedacpl121marc2332cpl121begonaalvarezd
authored
feat: create claimDelegationRewardsPopup (#8235)
* feat: implement logic to allow tx or not based on mana cost for the X slots * fixes and clean up * feat: add mana cost to mint, burn, send and implicitTransition * feat: improvements in mana box component * feat: add mana cost to claim activity * feat: add mana cost to create delegation * feat: add mana cost to claim shimmer * fixes * fix: add conditional chaining * feat: create claimDelegationRewardPopup * feat: update logic * fix: delegation reactivity errors * feat: remove unnecessary code * fix: closePopup * feat: improvements * minor fix * chore: minor improvements --------- Co-authored-by: cpl121 <cpeon@boxfish.studio> Co-authored-by: marc2332 <mespinsanz@gmail.com> Co-authored-by: cpl121 <100352899+cpl121@users.noreply.github.com> Co-authored-by: Begoña Álvarez de la Cruz <balvarez@boxfish.studio>
1 parent 0aaecca commit 79ed033

File tree

11 files changed

+142
-38
lines changed

11 files changed

+142
-38
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<script lang="ts">
2+
import { closePopup, updatePopupProps } from '@auxiliary/popup'
3+
import { ManaBox } from '@components'
4+
import { openUrlInBrowser } from '@core/app'
5+
import { handleError } from '@core/error/handlers'
6+
import { localize } from '@core/i18n'
7+
import { ITransactionInfoToCalculateManaCost } from '@core/network'
8+
import { getOfficialExplorerUrl } from '@core/network/utils'
9+
import { activeProfile, updateActiveWallet } from '@core/profile'
10+
import { checkActiveProfileAuth } from '@core/profile/actions'
11+
import { getDefaultTransactionOptions, selectedWallet } from '@core/wallet'
12+
import { Button, FontWeight, KeyValueBox, Text, TextType } from '@ui'
13+
import { onMount } from 'svelte'
14+
15+
export let _onMount: (..._: any[]) => Promise<void> = async () => {}
16+
export let delegationId: string
17+
export let rewards: number
18+
export let isBusy = false
19+
20+
let hasEnoughMana = false
21+
const transactionInfo: ITransactionInfoToCalculateManaCost = {}
22+
const explorerUrl = getOfficialExplorerUrl($activeProfile?.network?.id)
23+
24+
async function onConfirmClick(): Promise<void> {
25+
isBusy = true
26+
try {
27+
updatePopupProps({ isBusy })
28+
await checkActiveProfileAuth(burnDelegationOutput, { stronghold: true })
29+
} catch (error) {
30+
console.error(error)
31+
} finally {
32+
isBusy = false
33+
}
34+
}
35+
36+
async function burnDelegationOutput(): Promise<void> {
37+
try {
38+
await $selectedWallet.burn({ delegations: [delegationId] }, getDefaultTransactionOptions())
39+
updateActiveWallet($selectedWallet.id, {
40+
hasDelegationRewardClaimTransactionInProgress: true,
41+
isTransferring: true,
42+
})
43+
} catch (err) {
44+
handleError(err)
45+
}
46+
}
47+
48+
async function prepareBurnDelegationOutput(): Promise<void> {
49+
try {
50+
transactionInfo.preparedTransaction = await $selectedWallet?.prepareBurn(
51+
{ delegations: [delegationId] },
52+
getDefaultTransactionOptions()
53+
)
54+
} catch (error) {
55+
transactionInfo.preparedTransactionError = error
56+
}
57+
}
58+
59+
function onCancelClick(): void {
60+
closePopup()
61+
}
62+
63+
function onExplorerClick(): void {
64+
openUrlInBrowser(`${explorerUrl}/search/${delegationId}`)
65+
}
66+
67+
onMount(async () => {
68+
try {
69+
await _onMount()
70+
await prepareBurnDelegationOutput()
71+
} catch (err) {
72+
handleError(err.error)
73+
}
74+
})
75+
</script>
76+
77+
<div class="w-full h-full space-y-6 flex flex-auto flex-col shrink-0">
78+
<Text type={TextType.h3} fontWeight={FontWeight.semibold} classes="text-left">
79+
{localize('popups.claimDelegationRewards.title')}
80+
</Text>
81+
<button
82+
class="action w-max flex justify-start text-center font-medium text-14 text-blue-500"
83+
on:click={onExplorerClick}
84+
>
85+
{localize('general.viewOnExplorer')}
86+
</button>
87+
<div class="flex flex-col space-y-4">
88+
<KeyValueBox keyText={localize('popups.claimDelegationRewards.delegationId')} valueText={delegationId} />
89+
<KeyValueBox keyText={localize('popups.claimDelegationRewards.rewards')} valueText={rewards.toString()} />
90+
<ManaBox {transactionInfo} bind:hasEnoughMana />
91+
</div>
92+
<popup-buttons class="flex flex-row flex-nowrap w-full space-x-4">
93+
<Button classes="w-full" outline onClick={onCancelClick}>{localize('actions.cancel')}</Button>
94+
<Button
95+
classes="w-full"
96+
disabled={$selectedWallet?.isTransferring || isBusy || !hasEnoughMana}
97+
isBusy={$selectedWallet?.isTransferring || isBusy}
98+
onClick={onConfirmClick}
99+
>
100+
{localize('popups.claimDelegationRewards.confirmButton')}
101+
</Button>
102+
</popup-buttons>
103+
</div>

packages/desktop/components/popups/MintNftConfirmationPopup.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
<Tabs bind:activeTab {tabs} />
114114
{#if activeTab === Tab.Transaction}
115115
{#if quantity > 1}
116-
<KeyValueBox keyText={localize('general.quantity')} valueText={quantity} />
116+
<KeyValueBox keyText={localize('general.quantity')} valueText={quantity.toString()} />
117117
<KeyValueBox
118118
keyText={localize('general.storageDepositPerNft')}
119119
valueText={formatTokenAmountPrecise(storageDeposit, getBaseToken())}

packages/desktop/components/popups/Popup.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
import ActivateAccountPopup from './ActivateAccountPopup.svelte'
6262
import ManageKeysPopup from './ManageKeysPopup.svelte'
6363
import CreateDelegationPopup from './CreateDelegationPopup.svelte'
64+
import ClaimDelegationRewardsPopup from './ClaimDelegationRewardsPopup.svelte'
6465
6566
export let id: PopupId
6667
export let props: any
@@ -153,6 +154,7 @@
153154
[PopupId.ActivateAccount]: ActivateAccountPopup,
154155
[PopupId.ManageKeys]: ManageKeysPopup,
155156
[PopupId.CreateDelegation]: CreateDelegationPopup,
157+
[PopupId.ClaimDelegationRewards]: ClaimDelegationRewardsPopup,
156158
}
157159
158160
function onKey(event: KeyboardEvent): void {

packages/desktop/views/dashboard/delegation/Delegation.svelte

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@
1414
CopyableBox,
1515
BoxedIconWithText,
1616
PingingBadge,
17-
TextHintVariant,
1817
} from '@ui'
19-
import { activeProfile, checkActiveProfileAuth } from '@core/profile'
18+
import { activeProfile } from '@core/profile'
2019
import {
2120
formatTokenAmountBestMatch,
2221
AddressConverter,
23-
getDefaultTransactionOptions,
2422
selectedWalletAssets,
2523
EMPTY_HEX_ID,
2624
getOutputRewards,
@@ -29,7 +27,7 @@
2927
import { truncateString } from '@core/utils'
3028
import { Icon as IconEnum } from '@auxiliary/icon'
3129
import { OutputType, DelegationOutput, OutputData, DelegationId } from '@iota/sdk/out/types'
32-
import { PopupId, closePopup, openPopup } from '@auxiliary/popup'
30+
import { PopupId, openPopup } from '@auxiliary/popup'
3331
import features from '@features/features'
3432
import { api } from '@core/api'
3533
import { DEFAULT_MANA } from '@core/network'
@@ -58,8 +56,8 @@
5856
5957
$: delegationOutputs =
6058
$selectedWallet?.walletUnspentOutputs?.filter((output) => output?.output?.type === OutputType.Delegation) || []
61-
$: delegationOutputs?.length > 0 && setCurrentEpochAndCommittee()
62-
$: delegationOutputs?.length > 0 && currentEpoch && buildMappedDelegationData(delegationOutputs)
59+
$: delegationOutputs, setCurrentEpochAndCommittee()
60+
$: currentEpoch, delegationOutputs?.length > 0 && buildMappedDelegationData(delegationOutputs)
6361
$: ({ baseCoin } = $selectedWalletAssets[$activeProfile?.network.id])
6462
6563
$: rawDelegatedAmount = delegationOutputs.reduce((acc, prev) => acc + Number(prev.output.amount), 0)
@@ -105,26 +103,12 @@
105103
id: PopupId.CreateDelegation,
106104
})
107105
}
108-
109106
function handleClaimRewards(delegationId: string, rewards: number): void {
110107
openPopup({
111-
id: PopupId.Confirmation,
108+
id: PopupId.ClaimDelegationRewards,
112109
props: {
113-
title: localize('popups.claimDelegationRewards.title'),
114-
description: localize('popups.claimDelegationRewards.description', {
115-
values: { rewards, delegationId },
116-
}),
117-
confirmText: localize('popups.claimDelegationRewards.confirmButton'),
118-
variant: TextHintVariant.Success,
119-
onConfirm: async () => {
120-
await checkActiveProfileAuth(
121-
async () => {
122-
await $selectedWallet.burn({ delegations: [delegationId] }, getDefaultTransactionOptions())
123-
closePopup()
124-
},
125-
{ stronghold: true }
126-
)
127-
},
110+
delegationId,
111+
rewards,
128112
},
129113
})
130114
}
@@ -218,7 +202,7 @@
218202
{#if $selectedWallet}
219203
<delegation-container class="w-full h-full flex flex-nowrap p-8 relative space-x-4 justify-center">
220204
<Pane height={Height.Full} width={Width.Full}>
221-
<div class="flex flex-col space-y-10 max-w-7xl w-full p-8">
205+
<div class="flex flex-col space-y-10 max-w-7xl w-full h-full p-8">
222206
<div class="flex flex-row justify-between">
223207
<Text type={TextType.h2}>{localize('views.delegation.title')}</Text>
224208
<Button onClick={handleDelegate}>{localize('views.delegation.action.delegate')}</Button>
@@ -251,7 +235,7 @@
251235
</div>
252236
{#if features.delegation.delegationList.enabled}
253237
{#if delegationData.length > 0}
254-
<table class="flex flex-col w-full space-y-4 h-80">
238+
<table class="flex flex-col overflow-hidden h-full">
255239
<thead class="w-full">
256240
<tr class="flex flex-row justify-between align-items w-full">
257241
{#each Object.values(Header) as header}

packages/shared/lib/auxiliary/popup/enums/popup-id.enum.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,5 @@ export enum PopupId {
5353
WithdrawFromL2 = 'withdrawFromL2',
5454
CreateDelegation = 'createDelegation',
5555
ActivateAccount = 'activateAccount',
56+
ClaimDelegationRewards = 'claimDelegationRewardsPopup',
5657
}

packages/shared/lib/core/network/utils/getNetworkIdFromNetworkName.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function getNetworkIdFromNetworkName(networkName: string): NetworkId {
1414
case 'testnet-1':
1515
case 'testnet-2':
1616
case 'docker':
17-
case 'docker-1711022286':
17+
case 'docker-1712129396':
1818
return NetworkId.Testnet
1919
default:
2020
return NetworkId.Custom

packages/shared/lib/core/wallet/actions/buildWalletState.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export async function buildWalletState(
9393
hasConsolidatingOutputsTransactionInProgress: false,
9494
hasImplicitAccountCreationTransactionInProgress: false,
9595
hasDelegationTransactionInProgress: false,
96+
hasDelegationRewardClaimTransactionInProgress: false,
9697
isTransferring: false,
9798
votingPower,
9899
walletOutputs,

packages/shared/lib/core/wallet/actions/events-handlers/handleNewOutputEvent.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ export async function handleNewOutputEventInternal(walletId: string, payload: Ne
107107
}
108108
}
109109

110-
// TODO: update this logic when available balance is fixed
111110
if (_isDelegationOutput) {
112111
if (wallet?.hasDelegationTransactionInProgress) {
113112
updateActiveWallet(walletId, {

packages/shared/lib/core/wallet/actions/events-handlers/handleSpentOutputEvent.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
ActivityType,
66
WalletApiEventHandler,
77
allWalletActivities,
8+
isDelegationOutput,
89
syncBalance,
910
updateAsyncDataByTransactionId,
1011
validateWalletApiEvent,
@@ -13,6 +14,7 @@ import { SpentOutputWalletEvent, WalletEvent, WalletEventType } from '@iota/sdk/
1314
import { nodeInfoProtocolParameters } from '@core/network'
1415
import { getUnixTimestampFromNodeInfoAndSlotIndex } from '@core/network/helpers/getSlotInfoFromNodeProtocolParameters'
1516
import { get } from 'svelte/store'
17+
import { closePopup } from 'shared/lib/auxiliary/popup'
1618

1719
export function handleSpentOutputEvent(walletId: string): WalletApiEventHandler {
1820
return async (error: Error, rawEvent: WalletEvent) => {
@@ -26,6 +28,8 @@ export function handleSpentOutputEvent(walletId: string): WalletApiEventHandler
2628
export async function handleSpentOutputEventInternal(walletId: string, payload: SpentOutputWalletEvent): Promise<void> {
2729
const wallet = get(activeWallets)?.find((wallet) => wallet.id === walletId)
2830
const output = payload.output
31+
const _isDelegationOutput = isDelegationOutput(output)
32+
2933
await syncBalance(walletId, true)
3034
if (wallet) {
3135
const walletOutputs = await wallet.outputs()
@@ -61,4 +65,12 @@ export async function handleSpentOutputEventInternal(walletId: string, payload:
6165
updateNftInAllWalletNfts(walletId, activity.nftId, { isSpendable: false })
6266
}
6367
}
68+
69+
if (_isDelegationOutput && wallet?.hasDelegationRewardClaimTransactionInProgress) {
70+
updateActiveWallet(walletId, {
71+
hasDelegationRewardClaimTransactionInProgress: false,
72+
isTransferring: false,
73+
})
74+
closePopup() // close claimDelegationRewardsPopup when the account output is burned
75+
}
6476
}

packages/shared/lib/core/wallet/interfaces/wallet-state.interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export interface IWalletState extends IWallet, IPersistedWalletData {
1313
hasConsolidatingOutputsTransactionInProgress: boolean
1414
hasImplicitAccountCreationTransactionInProgress: boolean
1515
hasDelegationTransactionInProgress: boolean
16+
hasDelegationRewardClaimTransactionInProgress: boolean
1617
votingPower: string
1718
walletOutputs: OutputData[]
1819
walletUnspentOutputs: OutputData[]

packages/shared/locales/en.json

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -661,13 +661,13 @@
661661
"title": "Step 2",
662662
"body": "Fund confirmation",
663663
"view": {
664-
"eyebrow": "Wallet avaible balance:",
664+
"eyebrow": "Wallet available balance:",
665665
"generatedMana": "Generated Mana:",
666666
"title": "Funds arrived:",
667-
"subtitle": "Generating mana...",
668-
"action": "Activate Account",
667+
"subtitle": "Generating Mana...",
668+
"action": "Activate account",
669669
"walletAddress": {
670-
"description": "Send funds to your wallet address to speed up the mana generation",
670+
"description": "Send funds to your wallet address to speed up the Mana generation",
671671
"show": "Show Address",
672672
"copy": "Copy"
673673
}
@@ -837,7 +837,7 @@
837837
},
838838
"mana": {
839839
"title": "Mana",
840-
"subtitle": "Total mana"
840+
"subtitle": "Total Mana"
841841
},
842842
"lockedMana": {
843843
"title": "Locked Mana",
@@ -1276,8 +1276,9 @@
12761276
},
12771277
"claimDelegationRewards": {
12781278
"title": "Claim Rewards",
1279-
"description": "Claim all the rewards, {rewards} Mana, of this delegation output {delegationId}",
1280-
"confirmButton": "Claim"
1279+
"confirmButton": "Claim",
1280+
"rewards": "Rewards",
1281+
"delegationId": "Delegation ID"
12811282
}
12821283
},
12831284
"actions": {
@@ -1670,7 +1671,7 @@
16701671
"copiedToClipboard": "Copied to clipboard",
16711672
"total": "Total: {balance}",
16721673
"availableBalanceWithValue": "Available balance: {balance}",
1673-
"availableManaWithValue": "Available mana: {mana}",
1674+
"availableManaWithValue": "Available Mana: {mana}",
16741675
"availableBalance": "Available balance",
16751676
"availableBalanceTooltip": "An asset's total balance minus any funds that are required to cover the storage deposit (i.e. funds that are locked in pending transactions, reserved for Native Tokens, or reserved for NFTs).",
16761677
"amountClaimed": "{amount} claimed",
@@ -1731,9 +1732,9 @@
17311732
"custom": "Custom",
17321733
"verifyLedgerDepositAddress": "Please check the ledger device and verify that the deposit address matches the one displayed on the ledger device",
17331734
"manaCost": "Estimated Mana cost",
1734-
"availableMana": "Available mana",
1735+
"availableMana": "Available Mana",
17351736
"insufficientMana": "Insufficient {availableMana}.",
1736-
"secondsToRefreshManaCost": "{seconds} seconds to refresh the mana cost",
1737+
"secondsToRefreshManaCost": "{seconds} seconds to refresh the Mana cost",
17371738
"mana": "Mana"
17381739
},
17391740
"filters":{

0 commit comments

Comments
 (0)