Skip to content

Commit 4afb2ce

Browse files
committed
feat: create claimDelegationRewardPopup
1 parent 1e7af29 commit 4afb2ce

File tree

5 files changed

+75
-23
lines changed

5 files changed

+75
-23
lines changed

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 {
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<script lang="ts">
2+
import { Button, Text, FontWeight, TextType, KeyValueBox } from '@ui'
3+
import { localize } from '@core/i18n'
4+
import { closePopup } from '@auxiliary/popup'
5+
import { getDefaultTransactionOptions, selectedWallet } from '@core/wallet'
6+
import { checkActiveProfileAuth } from '@core/profile/actions'
7+
import { PreparedTransaction } from '@iota/sdk/out/types'
8+
import { ManaBox } from '@components'
9+
10+
export let delegationId: string
11+
export let rewards: number
12+
13+
let isBusy = false
14+
let hasEnoughMana = false
15+
let preparedTransaction: PreparedTransaction
16+
17+
async function onConfirmClick(): Promise<void> {
18+
try {
19+
isBusy = true
20+
await checkActiveProfileAuth(
21+
async () => {
22+
const burnOutput = await $selectedWallet.burn(
23+
{ delegations: [delegationId] },
24+
getDefaultTransactionOptions()
25+
)
26+
if (burnOutput) {
27+
closePopup()
28+
}
29+
},
30+
{ stronghold: true }
31+
)
32+
} catch (error) {
33+
console.error(error)
34+
} finally {
35+
isBusy = false
36+
}
37+
}
38+
39+
function onCancelClick(): void {
40+
closePopup()
41+
}
42+
</script>
43+
44+
<div class="w-full h-full space-y-6 flex flex-auto flex-col shrink-0">
45+
<Text type={TextType.h3} fontWeight={FontWeight.semibold} classes="text-left">
46+
{localize('popups.claimDelegationRewards.title')}
47+
</Text>
48+
<div class="flex flex-col space-y-4">
49+
<KeyValueBox keyText={localize('popups.claimDelegationRewards.delegationId')} valueText={delegationId} />
50+
<KeyValueBox keyText={localize('popups.claimDelegationRewards.rewards')} valueText={rewards.toString()} />
51+
<ManaBox {preparedTransaction} bind:hasEnoughMana />
52+
</div>
53+
<popup-buttons class="flex flex-row flex-nowrap w-full space-x-4">
54+
<Button classes="w-full" outline onClick={onCancelClick}>{localize('actions.cancel')}</Button>
55+
<Button
56+
classes="w-full"
57+
disabled={$selectedWallet?.isTransferring || isBusy || !hasEnoughMana}
58+
isBusy={$selectedWallet?.isTransferring || isBusy}
59+
onClick={onConfirmClick}
60+
>
61+
{localize('popups.claimDelegationRewards.confirmButton')}
62+
</Button>
63+
</popup-buttons>
64+
</div>

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

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@
1313
ButtonSize,
1414
CopyableBox,
1515
BoxedIconWithText,
16-
TextHintVariant,
1716
} from '@ui'
18-
import { activeProfile, checkActiveProfileAuth } from '@core/profile'
17+
import { activeProfile } from '@core/profile'
1918
import {
2019
formatTokenAmountBestMatch,
2120
AddressConverter,
22-
getDefaultTransactionOptions,
2321
selectedWalletAssets,
2422
EMPTY_HEX_ID,
2523
getOutputRewards,
@@ -28,7 +26,7 @@
2826
import { truncateString } from '@core/utils'
2927
import { Icon as IconEnum } from '@auxiliary/icon'
3028
import { OutputType, DelegationOutput, OutputData, DelegationId } from '@iota/sdk/out/types'
31-
import { PopupId, closePopup, openPopup } from '@auxiliary/popup'
29+
import { PopupId, openPopup } from '@auxiliary/popup'
3230
import features from '@features/features'
3331
import { api } from '@core/api'
3432
import { DEFAULT_MANA } from '@core/network'
@@ -102,26 +100,12 @@
102100
id: PopupId.CreateDelegation,
103101
})
104102
}
105-
106103
function handleClaimRewards(delegationId: string, rewards: number): void {
107104
openPopup({
108-
id: PopupId.Confirmation,
105+
id: PopupId.claimDelegationRewards,
109106
props: {
110-
title: localize('popups.claimDelegationRewards.title'),
111-
description: localize('popups.claimDelegationRewards.description', {
112-
values: { rewards, delegationId },
113-
}),
114-
confirmText: localize('popups.claimDelegationRewards.confirmButton'),
115-
variant: TextHintVariant.Success,
116-
onConfirm: async () => {
117-
await checkActiveProfileAuth(
118-
async () => {
119-
await $selectedWallet.burn({ delegations: [delegationId] }, getDefaultTransactionOptions())
120-
closePopup()
121-
},
122-
{ stronghold: true }
123-
)
124-
},
107+
delegationId,
108+
rewards,
125109
},
126110
})
127111
}

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/locales/en.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,8 +1263,9 @@
12631263
},
12641264
"claimDelegationRewards": {
12651265
"title": "Claim Rewards",
1266-
"description": "Claim all the rewards, {rewards} Mana, of this delegation output {delegationId}",
1267-
"confirmButton": "Claim"
1266+
"confirmButton": "Claim",
1267+
"rewards": "Rewards",
1268+
"delegationId": "Delegation output ID"
12681269
}
12691270
},
12701271
"actions": {

0 commit comments

Comments
 (0)