Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: claim rewards from delegation outputs #8136

Merged
merged 18 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
97bad15
feat: claim rewards from delegation outputs
cpl121 Mar 5, 2024
c5388fd
Merge branches 'feat/claim-rewards-from-delegation-outputs' and 'deve…
cpl121 Mar 6, 2024
7bc75c9
feat: update logic to claim delegation rewards
cpl121 Mar 6, 2024
511cee0
Merge branch 'develop-iota2.0' into feat/claim-rewards-from-delegatio…
cpl121 Mar 8, 2024
86024ee
Merge branches 'feat/claim-rewards-from-delegation-outputs' and 'deve…
cpl121 Mar 11, 2024
ec4fe98
fix: improve error to handle onClick button action
cpl121 Mar 11, 2024
c4f23d2
feat: add a TODO comment with new task to fix the claim rewards
cpl121 Mar 11, 2024
877d7c4
fix: use computeAccountId to generate delegationId
cpl121 Mar 12, 2024
dd1e9f9
feat: add computeDelegationId
cpl121 Mar 12, 2024
f5ea00f
Merge branches 'feat/claim-rewards-from-delegation-outputs' and 'deve…
cpl121 Mar 12, 2024
384f3c9
Update packages/shared/lib/core/api/interfaces/api.interface.ts
cpl121 Mar 12, 2024
c0c7ac8
Merge branch 'develop-iota2.0' into feat/claim-rewards-from-delegatio…
cpl121 Mar 12, 2024
c93c98b
Merge branch 'feat/claim-rewards-from-delegation-outputs' of github.c…
cpl121 Mar 12, 2024
7256688
Merge branch 'develop-iota2.0' of github.com:iotaledger/firefly into …
cpl121 Mar 12, 2024
d674021
Merge branches 'feat/claim-rewards-from-delegation-outputs' and 'deve…
cpl121 Mar 12, 2024
8657243
Merge branch 'develop-iota2.0' into feat/claim-rewards-from-delegatio…
cpl121 Mar 12, 2024
33c03d6
feat: improve delegationId and add the rewards con confirmation popup
cpl121 Mar 12, 2024
46b49c0
feat: add Mana to description of claimDelegationRewards
cpl121 Mar 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 39 additions & 8 deletions packages/desktop/views/dashboard/delegation/Delegation.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,23 @@
ButtonSize,
CopyableBox,
BoxedIconWithText,
TextHintVariant,
} from '@ui'
import { activeProfile } from '@core/profile'
import { formatTokenAmountBestMatch, AddressConverter, getClient, selectedWalletAssets } from '@core/wallet'
import { activeProfile, checkActiveProfileAuth } from '@core/profile'
import {
formatTokenAmountBestMatch,
AddressConverter,
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, openPopup } from '@auxiliary/popup'
import { PopupId, closePopup, openPopup } from '@auxiliary/popup'
import features from '@features/features'
import { api } from '@core/api'

let delegationData: IDelegationTable[] = []

Expand Down Expand Up @@ -62,15 +71,15 @@
[Header.Epoch]:
delegationOutput.endEpoch === 0 ? 0 : delegationOutput.endEpoch - delegationOutput.startEpoch,
[Header.Address]: AddressConverter.addressToBech32(delegationOutput.validatorAddress),
[Header.Action]: handleClaimRewards,
[Header.Action]: () => handleClaimRewards(output.outputId, delegationOutput.delegationId),
}
}) || []
delegationData = await Promise.all(result)
}

async function getOutputRewards(outputId: string): Promise<number> {
const client = await getClient()
const rewards = await client.getRewards(outputId)
const rewards = await client.getOutputManaRewards(outputId)
return Number(rewards)
}

Expand All @@ -80,8 +89,30 @@
})
}

function handleClaimRewards(): void {
// TODO: add logic to claim reward
function handleClaimRewards(outputId: string, delegationId: string): void {
if (delegationId === EMPTY_HEX_ID) {
delegationId = api.computeDelegationId(outputId)
}
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.burn({ delegations: [delegationId] }, getDefaultTransactionOptions())
closePopup()
},
{ stronghold: true }
)
},
},
})
}

function renderCellValue(value: any, header: string): { component: any; props: any; text?: string } {
Expand Down Expand Up @@ -136,7 +167,7 @@
return {
component: Button,
props: { size: ButtonSize.Small, onClick: value, outline: true },
text: 'Claim Rewards',
text: localize('popups.claimDelegationRewards.title'),
}
default:
return {
Expand Down
2 changes: 2 additions & 0 deletions packages/shared/lib/core/api/interfaces/api.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
Bech32Address,
ProtocolParameters,
DecayedMana,
DelegationId,
} from '@iota/sdk/out/types'
import { IWallet } from '@core/profile/interfaces'

Expand Down Expand Up @@ -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
cpl121 marked this conversation as resolved.
Show resolved Hide resolved
outputHexBytes(output: Output): HexEncodedString
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ export function getDefaultTransactionOptions(
value: new AccountAddress(accountId),
},
allowMicroAmount: true,
allowAllottingFromAccountMana: true,
}
}
5 changes: 5 additions & 0 deletions packages/shared/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,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": {
Expand Down
Loading