From 97bad1555a596d0d7f2923ab8aa35c53ef4a1f7d Mon Sep 17 00:00:00 2001 From: cpl121 Date: Tue, 5 Mar 2024 18:35:22 +0100 Subject: [PATCH 1/9] feat: claim rewards from delegation outputs --- .../dashboard/delegation/Delegation.svelte | 36 ++++++++++++++----- .../utils/getDefaultTransactionOptions.ts | 1 - packages/shared/locales/en.json | 5 +++ 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/packages/desktop/views/dashboard/delegation/Delegation.svelte b/packages/desktop/views/dashboard/delegation/Delegation.svelte index 73b613c259e..625ac11db1e 100644 --- a/packages/desktop/views/dashboard/delegation/Delegation.svelte +++ b/packages/desktop/views/dashboard/delegation/Delegation.svelte @@ -12,8 +12,9 @@ ButtonSize, CopyableBox, BoxedIconWithText, + TextHintVariant, } from '@ui' - import { activeProfile } from '@core/profile' + import { activeProfile, checkActiveProfileAuth } from '@core/profile' import { formatTokenAmountBestMatch, getBech32AddressFromAddressTypes, @@ -23,7 +24,7 @@ import { truncateString } from '@core/utils' import { Icon as IconEnum } from '@auxiliary/icon' import { OutputType, DelegationOutput, AccountAddress, OutputData } from '@iota/sdk/out/types' - import { PopupId, openPopup } from '@auxiliary/popup' + import { PopupId, closePopup, openPopup } from '@auxiliary/popup' import features from '@features/features' let delegationData: IDelegationTable[] = [] @@ -43,7 +44,7 @@ [Header.Rewards]: number [Header.Epoch]: number [Header.Address]: string - [Header.Action]: () => void + [Header.Action]: void } // TODO: update interface when available @@ -67,7 +68,7 @@ [Header.Epoch]: delegationOutput.endEpoch === 0 ? 0 : delegationOutput.endEpoch - delegationOutput.startEpoch, [Header.Address]: getBech32AddressFromAddressTypes(delegationOutput.validatorAddress), - [Header.Action]: handleClaimRewards, + [Header.Action]: handleClaimRewards(delegationOutput.delegationId), } }) || [] delegationData = await Promise.all(result) @@ -75,7 +76,7 @@ async function getOutputRewards(outputId: string): Promise { const client = await getClient() - const rewards = await client.getRewards(outputId) + const rewards = await client.getOutputManaRewards(outputId) return Number(rewards) } @@ -85,8 +86,27 @@ }) } - function handleClaimRewards(): void { - // TODO: add logic to claim reward + function handleClaimRewards(delegationId: string): void { + openPopup({ + id: PopupId.Confirmation, + props: { + title: localize('popups.claimDelegationRewards.title'), + description: localize('popups.claimDelegationRewards.description', { + values: { delegationId }, + }), + confirmText: localize('popups.claimDelegationRewards.confirmButton'), + variant: TextHintVariant.Success, + onConfirm: async () => { + await checkActiveProfileAuth( + async () => { + await $selectedWallet.delayDelegationClaiming(delegationId, false) + closePopup() + }, + { stronghold: true } + ) + }, + }, + }) } function renderCellValue(value: any, header: string): { component: any; props: any; text?: string } { @@ -141,7 +161,7 @@ return { component: Button, props: { size: ButtonSize.Small, onClick: value, outline: true }, - text: 'Claim Rewards', + text: localize('popups.claimDelegationRewards.title'), } default: return { diff --git a/packages/shared/lib/core/wallet/utils/getDefaultTransactionOptions.ts b/packages/shared/lib/core/wallet/utils/getDefaultTransactionOptions.ts index 3c2721bb497..a17a6101fbd 100644 --- a/packages/shared/lib/core/wallet/utils/getDefaultTransactionOptions.ts +++ b/packages/shared/lib/core/wallet/utils/getDefaultTransactionOptions.ts @@ -11,6 +11,5 @@ export function getDefaultTransactionOptions( value: new AccountAddress(accountId), }, allowMicroAmount: true, - allowAllottingFromAccountMana: true, } } diff --git a/packages/shared/locales/en.json b/packages/shared/locales/en.json index b02769906b4..8cd1c2b2231 100644 --- a/packages/shared/locales/en.json +++ b/packages/shared/locales/en.json @@ -1254,6 +1254,11 @@ "title": "Account Address", "description": "Account Address for the validator" } + }, + "claimDelegationRewards": { + "title": "Claim Rewards", + "description": "Claim the rewards of all epochs of this delegation output {delegationId}", + "confirmButton": "Claim" } }, "actions": { From 7bc75c9de492098e906bfd9d71e226af75f9ec1b Mon Sep 17 00:00:00 2001 From: cpl121 Date: Wed, 6 Mar 2024 19:44:01 +0100 Subject: [PATCH 2/9] feat: update logic to claim delegation rewards --- packages/desktop/views/dashboard/delegation/Delegation.svelte | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/desktop/views/dashboard/delegation/Delegation.svelte b/packages/desktop/views/dashboard/delegation/Delegation.svelte index 625ac11db1e..90106574e2b 100644 --- a/packages/desktop/views/dashboard/delegation/Delegation.svelte +++ b/packages/desktop/views/dashboard/delegation/Delegation.svelte @@ -19,6 +19,7 @@ formatTokenAmountBestMatch, getBech32AddressFromAddressTypes, getClient, + getDefaultTransactionOptions, selectedWalletAssets, } from '@core/wallet' import { truncateString } from '@core/utils' @@ -99,7 +100,7 @@ onConfirm: async () => { await checkActiveProfileAuth( async () => { - await $selectedWallet.delayDelegationClaiming(delegationId, false) + await $selectedWallet.burn({ delegations: [delegationId] }, getDefaultTransactionOptions()) closePopup() }, { stronghold: true } From ec4fe985acdd5513910ff0692475b13c32a29943 Mon Sep 17 00:00:00 2001 From: cpl121 Date: Mon, 11 Mar 2024 14:01:07 +0100 Subject: [PATCH 3/9] fix: improve error to handle onClick button action --- packages/desktop/views/dashboard/delegation/Delegation.svelte | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/desktop/views/dashboard/delegation/Delegation.svelte b/packages/desktop/views/dashboard/delegation/Delegation.svelte index 08fda5de732..2399a7d90ef 100644 --- a/packages/desktop/views/dashboard/delegation/Delegation.svelte +++ b/packages/desktop/views/dashboard/delegation/Delegation.svelte @@ -45,7 +45,7 @@ [Header.Rewards]: number [Header.Epoch]: number [Header.Address]: string - [Header.Action]: void + [Header.Action]: () => void } // TODO: update interface when available @@ -69,7 +69,7 @@ [Header.Epoch]: delegationOutput.endEpoch === 0 ? 0 : delegationOutput.endEpoch - delegationOutput.startEpoch, [Header.Address]: AddressConverter.addressToBech32(delegationOutput.validatorAddress), - [Header.Action]: handleClaimRewards(delegationOutput.delegationId), + [Header.Action]: () => handleClaimRewards(delegationOutput.delegationId), } }) || [] delegationData = await Promise.all(result) From c4f23d225dbac9b44a132a2763f934553337da36 Mon Sep 17 00:00:00 2001 From: cpl121 Date: Mon, 11 Mar 2024 14:42:26 +0100 Subject: [PATCH 4/9] feat: add a TODO comment with new task to fix the claim rewards --- packages/desktop/views/dashboard/delegation/Delegation.svelte | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/desktop/views/dashboard/delegation/Delegation.svelte b/packages/desktop/views/dashboard/delegation/Delegation.svelte index 2399a7d90ef..16c9fc51af0 100644 --- a/packages/desktop/views/dashboard/delegation/Delegation.svelte +++ b/packages/desktop/views/dashboard/delegation/Delegation.svelte @@ -100,6 +100,7 @@ onConfirm: async () => { await checkActiveProfileAuth( async () => { + // TODO: Update the delegationId when https://github.com/iotaledger/firefly/issues/8188 is merged await $selectedWallet.burn({ delegations: [delegationId] }, getDefaultTransactionOptions()) closePopup() }, From 877d7c48a80d8adb8fb63b7937333940e2d60b01 Mon Sep 17 00:00:00 2001 From: cpl121 Date: Tue, 12 Mar 2024 14:06:33 +0100 Subject: [PATCH 5/9] fix: use computeAccountId to generate delegationId --- .../views/dashboard/delegation/Delegation.svelte | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/desktop/views/dashboard/delegation/Delegation.svelte b/packages/desktop/views/dashboard/delegation/Delegation.svelte index 16c9fc51af0..8082a4a8e6a 100644 --- a/packages/desktop/views/dashboard/delegation/Delegation.svelte +++ b/packages/desktop/views/dashboard/delegation/Delegation.svelte @@ -21,12 +21,14 @@ getClient, getDefaultTransactionOptions, selectedWalletAssets, + EMPTY_HEX_ID, } from '@core/wallet' import { truncateString } from '@core/utils' import { Icon as IconEnum } from '@auxiliary/icon' import { OutputType, DelegationOutput, AccountAddress, OutputData } from '@iota/sdk/out/types' import { PopupId, closePopup, openPopup } from '@auxiliary/popup' import features from '@features/features' + import { api } from '@core/api' let delegationData: IDelegationTable[] = [] @@ -69,7 +71,7 @@ [Header.Epoch]: delegationOutput.endEpoch === 0 ? 0 : delegationOutput.endEpoch - delegationOutput.startEpoch, [Header.Address]: AddressConverter.addressToBech32(delegationOutput.validatorAddress), - [Header.Action]: () => handleClaimRewards(delegationOutput.delegationId), + [Header.Action]: () => handleClaimRewards(output.outputId, delegationOutput.delegationId), } }) || [] delegationData = await Promise.all(result) @@ -87,7 +89,11 @@ }) } - function handleClaimRewards(delegationId: string): void { + function handleClaimRewards(outputId: string, delegationId: string): void { + if (delegationId === EMPTY_HEX_ID) { + // TODO: Update with computeDelegationId when https://github.com/iotaledger/firefly/issues/8188 is merged + delegationId = api.computeAccountId(outputId) + } openPopup({ id: PopupId.Confirmation, props: { @@ -100,7 +106,6 @@ onConfirm: async () => { await checkActiveProfileAuth( async () => { - // TODO: Update the delegationId when https://github.com/iotaledger/firefly/issues/8188 is merged await $selectedWallet.burn({ delegations: [delegationId] }, getDefaultTransactionOptions()) closePopup() }, From dd1e9f901d9eca1c4ddc691ae51a16676c2d2d0a Mon Sep 17 00:00:00 2001 From: cpl121 Date: Tue, 12 Mar 2024 17:08:41 +0100 Subject: [PATCH 6/9] feat: add computeDelegationId --- packages/desktop/views/dashboard/delegation/Delegation.svelte | 3 +-- packages/shared/lib/core/api/interfaces/api.interface.ts | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/desktop/views/dashboard/delegation/Delegation.svelte b/packages/desktop/views/dashboard/delegation/Delegation.svelte index 8082a4a8e6a..7b05c157c76 100644 --- a/packages/desktop/views/dashboard/delegation/Delegation.svelte +++ b/packages/desktop/views/dashboard/delegation/Delegation.svelte @@ -91,8 +91,7 @@ function handleClaimRewards(outputId: string, delegationId: string): void { if (delegationId === EMPTY_HEX_ID) { - // TODO: Update with computeDelegationId when https://github.com/iotaledger/firefly/issues/8188 is merged - delegationId = api.computeAccountId(outputId) + delegationId = api.computeDelegationId(outputId) } openPopup({ id: PopupId.Confirmation, diff --git a/packages/shared/lib/core/api/interfaces/api.interface.ts b/packages/shared/lib/core/api/interfaces/api.interface.ts index 6d3d9a7e023..571ceaa2372 100644 --- a/packages/shared/lib/core/api/interfaces/api.interface.ts +++ b/packages/shared/lib/core/api/interfaces/api.interface.ts @@ -12,6 +12,7 @@ import { Bech32Address, ProtocolParameters, DecayedMana, + DelegationId, } from '@iota/sdk/out/types' import { IWallet } from '@core/profile/interfaces' @@ -45,5 +46,6 @@ export interface IApi { computeFoundryId(accountId: AccountId, serialNumber: number, tokenSchemeType: number): FoundryId computeNftId(outputId: string): NftId computeOutputId(id: TransactionId, index: number): OutputId + computeDelegationId(outputId: string): DelegationId outputHexBytes(output: Output): HexEncodedString } From 384f3c9199e45f5e2982765843642431e5a69616 Mon Sep 17 00:00:00 2001 From: cpl121 <100352899+cpl121@users.noreply.github.com> Date: Tue, 12 Mar 2024 17:32:19 +0100 Subject: [PATCH 7/9] Update packages/shared/lib/core/api/interfaces/api.interface.ts Co-authored-by: Marc Espin --- packages/shared/lib/core/api/interfaces/api.interface.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/shared/lib/core/api/interfaces/api.interface.ts b/packages/shared/lib/core/api/interfaces/api.interface.ts index 571ceaa2372..43ea69c46f5 100644 --- a/packages/shared/lib/core/api/interfaces/api.interface.ts +++ b/packages/shared/lib/core/api/interfaces/api.interface.ts @@ -46,6 +46,6 @@ export interface IApi { computeFoundryId(accountId: AccountId, serialNumber: number, tokenSchemeType: number): FoundryId computeNftId(outputId: string): NftId computeOutputId(id: TransactionId, index: number): OutputId - computeDelegationId(outputId: string): DelegationId + computeDelegationId(outputId: OutputId): DelegationId outputHexBytes(output: Output): HexEncodedString } From 33c03d6f4466e70fdeaca9566bf9040a969390c9 Mon Sep 17 00:00:00 2001 From: cpl121 Date: Tue, 12 Mar 2024 18:59:23 +0100 Subject: [PATCH 8/9] feat: improve delegationId and add the rewards con confirmation popup --- .../dashboard/delegation/Delegation.svelte | 20 ++++++++++--------- packages/shared/locales/en.json | 2 +- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/desktop/views/dashboard/delegation/Delegation.svelte b/packages/desktop/views/dashboard/delegation/Delegation.svelte index 9f963e9dd69..9ae02f6c067 100644 --- a/packages/desktop/views/dashboard/delegation/Delegation.svelte +++ b/packages/desktop/views/dashboard/delegation/Delegation.svelte @@ -27,7 +27,7 @@ } from '@core/wallet' import { truncateString } from '@core/utils' import { Icon as IconEnum } from '@auxiliary/icon' - import { OutputType, DelegationOutput, OutputData } from '@iota/sdk/out/types' + import { OutputType, DelegationOutput, OutputData, DelegationId } from '@iota/sdk/out/types' import { PopupId, closePopup, openPopup } from '@auxiliary/popup' import features from '@features/features' import { api } from '@core/api' @@ -75,13 +75,18 @@ const delegationOutput = output.output as DelegationOutput // Until the first epoch in which it was delegated ends, no rewards are obtained const epochsDelegating = currentEpoch - delegationOutput.startEpoch + let delegationId: DelegationId = delegationOutput.delegationId + if (delegationId === EMPTY_HEX_ID) { + delegationId = api.computeDelegationId(output.outputId) + } + const rewards = await getOutputRewards(output.outputId) return { - [Header.DelegationId]: delegationOutput.delegationId, + [Header.DelegationId]: delegationId, [Header.DelegatedFunds]: Number(delegationOutput.delegatedAmount), - [Header.Rewards]: await getOutputRewards(output.outputId), + [Header.Rewards]: rewards, [Header.Epochs]: epochsDelegating > 0 ? epochsDelegating : 0, [Header.DelegatedAddress]: AddressConverter.addressToBech32(delegationOutput.validatorAddress), - [Header.Action]: () => handleClaimRewards(output.outputId, delegationOutput.delegationId), + [Header.Action]: () => handleClaimRewards(delegationId, rewards), } }) || [] delegationData = await Promise.all(result) @@ -98,16 +103,13 @@ }) } - function handleClaimRewards(outputId: string, delegationId: string): void { - if (delegationId === EMPTY_HEX_ID) { - delegationId = api.computeDelegationId(outputId) - } + function handleClaimRewards(delegationId: string, rewards: number): void { openPopup({ id: PopupId.Confirmation, props: { title: localize('popups.claimDelegationRewards.title'), description: localize('popups.claimDelegationRewards.description', { - values: { delegationId }, + values: { rewards, delegationId }, }), confirmText: localize('popups.claimDelegationRewards.confirmButton'), variant: TextHintVariant.Success, diff --git a/packages/shared/locales/en.json b/packages/shared/locales/en.json index 2bc27f08574..f664880ddc5 100644 --- a/packages/shared/locales/en.json +++ b/packages/shared/locales/en.json @@ -1265,7 +1265,7 @@ }, "claimDelegationRewards": { "title": "Claim Rewards", - "description": "Claim the rewards of all epochs of this delegation output {delegationId}", + "description": "Claim the rewards of all epochs, {rewards} of this delegation output {delegationId}", "confirmButton": "Claim" } }, From 46b49c0796c493ab47f18f582daf520179c183fe Mon Sep 17 00:00:00 2001 From: cpl121 Date: Tue, 12 Mar 2024 19:07:19 +0100 Subject: [PATCH 9/9] feat: add Mana to description of claimDelegationRewards --- packages/shared/locales/en.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/shared/locales/en.json b/packages/shared/locales/en.json index f664880ddc5..943f581a256 100644 --- a/packages/shared/locales/en.json +++ b/packages/shared/locales/en.json @@ -1265,7 +1265,7 @@ }, "claimDelegationRewards": { "title": "Claim Rewards", - "description": "Claim the rewards of all epochs, {rewards} of this delegation output {delegationId}", + "description": "Claim all the rewards, {rewards} Mana, of this delegation output {delegationId}", "confirmButton": "Claim" } },