From 99bd3b1ff6b0c050fcfbcfd9bd650a140566edb7 Mon Sep 17 00:00:00 2001 From: cpl121 Date: Thu, 7 Mar 2024 01:46:11 +0100 Subject: [PATCH 1/8] feat: modify name column by delegationId --- .../dashboard/delegation/Delegation.svelte | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/packages/desktop/views/dashboard/delegation/Delegation.svelte b/packages/desktop/views/dashboard/delegation/Delegation.svelte index 73b613c259e..ac66b6e8ea4 100644 --- a/packages/desktop/views/dashboard/delegation/Delegation.svelte +++ b/packages/desktop/views/dashboard/delegation/Delegation.svelte @@ -29,7 +29,7 @@ let delegationData: IDelegationTable[] = [] enum Header { - Name = 'name', + DelegationId = 'delegationId', DelegatedFunds = 'delegatedFunds', Rewards = 'rewards', Epoch = 'epoch', @@ -38,7 +38,7 @@ } interface IDelegationTable { - [Header.Name]: string + [Header.DelegationId]: string [Header.DelegatedFunds]: number [Header.Rewards]: number [Header.Epoch]: number @@ -58,10 +58,10 @@ async function mappedDelegationData(delegationOutputs: OutputData[]): Promise { const result = - delegationOutputs?.map(async (output, index) => { + delegationOutputs?.map(async (output) => { const delegationOutput = output.output as DelegationOutputTemp return { - [Header.Name]: `Delegation ${index + 1}`, + [Header.DelegationId]: delegationOutput.delegationId, [Header.DelegatedFunds]: Number(delegationOutput.delegatedAmount), [Header.Rewards]: await getOutputRewards(output.outputId), [Header.Epoch]: @@ -91,11 +91,17 @@ function renderCellValue(value: any, header: string): { component: any; props: any; text?: string } { switch (header as Header) { - case Header.Name: + case Header.DelegationId: return { - component: Text, - props: { type: TextType.h5, fontWeight: FontWeight.semibold }, - text: value, + component: CopyableBox, + props: { + value: value, + isCopyable: true, + clearBoxPadding: true, + clearBackground: true, + classes: 'text-gray-600 dark:text-white text-xs font-semibold', + }, + text: truncateString(value, 5, 5, 3), } case Header.DelegatedFunds: return { From 7e930aee6ac0a4834668b21e77ae72989c48cfda Mon Sep 17 00:00:00 2001 From: cpl121 Date: Thu, 7 Mar 2024 01:47:49 +0100 Subject: [PATCH 2/8] feat: rename "address" column header to "delegated to" --- .../desktop/views/dashboard/delegation/Delegation.svelte | 8 ++++---- packages/shared/locales/en.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/desktop/views/dashboard/delegation/Delegation.svelte b/packages/desktop/views/dashboard/delegation/Delegation.svelte index ac66b6e8ea4..a73f6a9247f 100644 --- a/packages/desktop/views/dashboard/delegation/Delegation.svelte +++ b/packages/desktop/views/dashboard/delegation/Delegation.svelte @@ -33,7 +33,7 @@ DelegatedFunds = 'delegatedFunds', Rewards = 'rewards', Epoch = 'epoch', - Address = 'address', + DelegatedAddress = 'delegatedAddress', Action = 'action', } @@ -42,7 +42,7 @@ [Header.DelegatedFunds]: number [Header.Rewards]: number [Header.Epoch]: number - [Header.Address]: string + [Header.DelegatedAddress]: string [Header.Action]: () => void } @@ -66,7 +66,7 @@ [Header.Rewards]: await getOutputRewards(output.outputId), [Header.Epoch]: delegationOutput.endEpoch === 0 ? 0 : delegationOutput.endEpoch - delegationOutput.startEpoch, - [Header.Address]: getBech32AddressFromAddressTypes(delegationOutput.validatorAddress), + [Header.DelegatedAddress]: getBech32AddressFromAddressTypes(delegationOutput.validatorAddress), [Header.Action]: handleClaimRewards, } }) || [] @@ -131,7 +131,7 @@ props: { color: 'gray-600', fontWeight: FontWeight.medium, fontSize: '12', type: TextType.p }, text: value + ' epochs', } - case Header.Address: + case Header.DelegatedAddress: return { component: CopyableBox, props: { diff --git a/packages/shared/locales/en.json b/packages/shared/locales/en.json index b02769906b4..09e24b09ad9 100644 --- a/packages/shared/locales/en.json +++ b/packages/shared/locales/en.json @@ -734,7 +734,7 @@ "delegatedFunds": "Delegated Funds", "rewards": "Rewards", "epoch": "Epoch", - "address": "Address", + "delegatedAddress": "Delegated to", "action": "Action" } } From afcf76bc71d8f9b7c138a8756e1f0d059d0cc749 Mon Sep 17 00:00:00 2001 From: cpl121 Date: Thu, 7 Mar 2024 01:51:16 +0100 Subject: [PATCH 3/8] feat: rename epoch by epochs --- .../views/dashboard/delegation/Delegation.svelte | 14 +++++++++----- packages/shared/locales/en.json | 5 ++++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/desktop/views/dashboard/delegation/Delegation.svelte b/packages/desktop/views/dashboard/delegation/Delegation.svelte index a73f6a9247f..bfc08c0d252 100644 --- a/packages/desktop/views/dashboard/delegation/Delegation.svelte +++ b/packages/desktop/views/dashboard/delegation/Delegation.svelte @@ -32,7 +32,7 @@ DelegationId = 'delegationId', DelegatedFunds = 'delegatedFunds', Rewards = 'rewards', - Epoch = 'epoch', + Epochs = 'epochs', DelegatedAddress = 'delegatedAddress', Action = 'action', } @@ -41,7 +41,7 @@ [Header.DelegationId]: string [Header.DelegatedFunds]: number [Header.Rewards]: number - [Header.Epoch]: number + [Header.Epochs]: number [Header.DelegatedAddress]: string [Header.Action]: () => void } @@ -64,7 +64,7 @@ [Header.DelegationId]: delegationOutput.delegationId, [Header.DelegatedFunds]: Number(delegationOutput.delegatedAmount), [Header.Rewards]: await getOutputRewards(output.outputId), - [Header.Epoch]: + [Header.Epochs]: delegationOutput.endEpoch === 0 ? 0 : delegationOutput.endEpoch - delegationOutput.startEpoch, [Header.DelegatedAddress]: getBech32AddressFromAddressTypes(delegationOutput.validatorAddress), [Header.Action]: handleClaimRewards, @@ -125,11 +125,15 @@ height: 20, }, } - case Header.Epoch: + case Header.Epochs: return { component: Text, props: { color: 'gray-600', fontWeight: FontWeight.medium, fontSize: '12', type: TextType.p }, - text: value + ' epochs', + text: localize('views.delegation.table.body.epochs', { + values: { + epochs: value, + }, + }), } case Header.DelegatedAddress: return { diff --git a/packages/shared/locales/en.json b/packages/shared/locales/en.json index 09e24b09ad9..271195ec5a2 100644 --- a/packages/shared/locales/en.json +++ b/packages/shared/locales/en.json @@ -733,9 +733,12 @@ "name": "Name", "delegatedFunds": "Delegated Funds", "rewards": "Rewards", - "epoch": "Epoch", + "epochs": "Epochs", "delegatedAddress": "Delegated to", "action": "Action" + }, + "body": { + "epochs": "{epochs} epochs" } } } From 84bbf60b228076bfbcc354928fd9476b7e37d6ff Mon Sep 17 00:00:00 2001 From: cpl121 Date: Thu, 7 Mar 2024 02:07:38 +0100 Subject: [PATCH 4/8] feat: update epochs logic --- .../views/dashboard/delegation/Delegation.svelte | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/desktop/views/dashboard/delegation/Delegation.svelte b/packages/desktop/views/dashboard/delegation/Delegation.svelte index bfc08c0d252..757cf6ec40d 100644 --- a/packages/desktop/views/dashboard/delegation/Delegation.svelte +++ b/packages/desktop/views/dashboard/delegation/Delegation.svelte @@ -27,6 +27,7 @@ import features from '@features/features' let delegationData: IDelegationTable[] = [] + let currentEpoch = 0 enum Header { DelegationId = 'delegationId', @@ -53,7 +54,8 @@ $: delegationOutputs = $selectedWallet?.walletOutputs?.filter((output) => output?.output?.type === OutputType.Delegation) || [] - $: delegationOutputs?.length > 0 && mappedDelegationData(delegationOutputs) + $: delegationOutputs?.length > 0 && getCurrentEpoch() + $: delegationOutputs?.length > 0 && currentEpoch && mappedDelegationData(delegationOutputs) $: ({ baseCoin } = $selectedWalletAssets[$activeProfile?.network.id]) async function mappedDelegationData(delegationOutputs: OutputData[]): Promise { @@ -64,8 +66,7 @@ [Header.DelegationId]: delegationOutput.delegationId, [Header.DelegatedFunds]: Number(delegationOutput.delegatedAmount), [Header.Rewards]: await getOutputRewards(output.outputId), - [Header.Epochs]: - delegationOutput.endEpoch === 0 ? 0 : delegationOutput.endEpoch - delegationOutput.startEpoch, + [Header.Epochs]: currentEpoch - delegationOutput.startEpoch - 2, [Header.DelegatedAddress]: getBech32AddressFromAddressTypes(delegationOutput.validatorAddress), [Header.Action]: handleClaimRewards, } @@ -79,6 +80,12 @@ return Number(rewards) } + async function getCurrentEpoch(): Promise { + const client = await getClient() + const comittee = await client.getCommittee() + currentEpoch = comittee.epoch + } + function handleDelegate(): void { openPopup({ id: PopupId.CreateDelegation, From 552497dee6fbde0c22c442efc49866b344786121 Mon Sep 17 00:00:00 2001 From: cpl121 Date: Fri, 8 Mar 2024 12:30:34 +0100 Subject: [PATCH 5/8] feat: check if the validator address belongs to the validator committee --- .../dashboard/delegation/Delegation.svelte | 30 +++++++++++++++---- packages/shared/locales/en.json | 2 +- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/packages/desktop/views/dashboard/delegation/Delegation.svelte b/packages/desktop/views/dashboard/delegation/Delegation.svelte index 62cd6a9e932..429e25e663d 100644 --- a/packages/desktop/views/dashboard/delegation/Delegation.svelte +++ b/packages/desktop/views/dashboard/delegation/Delegation.svelte @@ -12,6 +12,7 @@ ButtonSize, CopyableBox, BoxedIconWithText, + PingingBadge, } from '@ui' import { activeProfile } from '@core/profile' import { @@ -28,6 +29,7 @@ let delegationData: IDelegationTable[] = [] let currentEpoch = 0 + let committeeAddress: string[] = [] enum Header { DelegationId = 'delegationId', @@ -54,7 +56,8 @@ $: delegationOutputs = $selectedWallet?.walletOutputs?.filter((output) => output?.output?.type === OutputType.Delegation) || [] - $: delegationOutputs?.length > 0 && getCurrentEpoch() + // TODO: update this per each epoch + $: delegationOutputs?.length > 0 && getCurrentEpochAndCommittee() $: delegationOutputs?.length > 0 && currentEpoch && mappedDelegationData(delegationOutputs) $: ({ baseCoin } = $selectedWalletAssets[$activeProfile?.network.id]) @@ -80,10 +83,11 @@ return Number(rewards) } - async function getCurrentEpoch(): Promise { + async function getCurrentEpochAndCommittee(): Promise { const client = await getClient() - const comittee = await client.getCommittee() - currentEpoch = comittee.epoch + const committeeResponse = await client.getCommittee() + currentEpoch = committeeResponse?.epoch + committeeAddress = committeeResponse?.committee?.map((committee) => committee.address) || [] } function handleDelegate(): void { @@ -96,7 +100,7 @@ // TODO: add logic to claim reward } - function renderCellValue(value: any, header: string): { component: any; props: any; text?: string } { + function renderCellValue(value: any, header: string): { component: any; props: any; text?: string; slot?: any } { switch (header as Header) { case Header.DelegationId: return { @@ -150,7 +154,20 @@ isCopyable: true, clearBoxPadding: true, clearBackground: true, - classes: 'text-gray-600 dark:text-white text-xs font-medium', + classes: + 'flex flex-row justify-start items-center space-x-2 text-gray-600 dark:text-white text-xs font-medium', + }, + slot: { + component: PingingBadge, + props: { + classes: 'relative', + innerColor: committeeAddress?.some((address) => address === value) + ? 'green-600' + : 'red-500', + outerColor: committeeAddress?.some((address) => address === value) + ? 'green-400' + : 'red-300', + }, }, text: truncateString(value, 5, 5, 3), } @@ -232,6 +249,7 @@ {#if renderCell.text} + {renderCell.slot} {renderCell.text} {:else} diff --git a/packages/shared/locales/en.json b/packages/shared/locales/en.json index 1160a8463a7..76518d6e4a3 100644 --- a/packages/shared/locales/en.json +++ b/packages/shared/locales/en.json @@ -730,7 +730,7 @@ }, "table": { "header": { - "name": "Name", + "delegationId": "Delegation Id", "delegatedFunds": "Delegated Funds", "rewards": "Rewards", "epochs": "Epochs", From 3c4805cab9eef7c94ad3db4054bc522c951605ce Mon Sep 17 00:00:00 2001 From: cpl121 Date: Mon, 11 Mar 2024 13:51:55 +0100 Subject: [PATCH 6/8] feat: improve delegation list --- .../dashboard/delegation/Delegation.svelte | 19 ++++++++----------- packages/shared/locales/en.json | 2 +- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/packages/desktop/views/dashboard/delegation/Delegation.svelte b/packages/desktop/views/dashboard/delegation/Delegation.svelte index 56906c0907f..7c6cce5c878 100644 --- a/packages/desktop/views/dashboard/delegation/Delegation.svelte +++ b/packages/desktop/views/dashboard/delegation/Delegation.svelte @@ -17,7 +17,7 @@ import { formatTokenAmountBestMatch, AddressConverter, getClient, selectedWalletAssets } 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 { OutputType, DelegationOutput, OutputData } from '@iota/sdk/out/types' import { PopupId, openPopup } from '@auxiliary/popup' import features from '@features/features' @@ -42,11 +42,6 @@ [Header.Action]: () => void } - // TODO: update interface when available - interface DelegationOutputTemp extends DelegationOutput { - validatorAddress: AccountAddress - } - $: delegationOutputs = $selectedWallet?.walletUnspentOutputs?.filter((output) => output?.output?.type === OutputType.Delegation) || [] $: delegationOutputs?.length > 0 && getCurrentEpoch() @@ -56,12 +51,14 @@ async function mappedDelegationData(delegationOutputs: OutputData[]): Promise { const result = delegationOutputs?.map(async (output) => { - const delegationOutput = output.output as DelegationOutputTemp + 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 return { [Header.DelegationId]: delegationOutput.delegationId, [Header.DelegatedFunds]: Number(delegationOutput.delegatedAmount), [Header.Rewards]: await getOutputRewards(output.outputId), - [Header.Epochs]: currentEpoch - delegationOutput.startEpoch - 2, + [Header.Epochs]: epochsDelegating > 0 ? epochsDelegating : 0, [Header.DelegatedAddress]: AddressConverter.addressToBech32(delegationOutput.validatorAddress), [Header.Action]: handleClaimRewards, } @@ -71,14 +68,14 @@ 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) } async function getCurrentEpoch(): Promise { const client = await getClient() - const comittee = await client.getCommittee() - currentEpoch = comittee.epoch + const committee = await client.getCommittee() + currentEpoch = committee.epoch } function handleDelegate(): void { diff --git a/packages/shared/locales/en.json b/packages/shared/locales/en.json index 1160a8463a7..76518d6e4a3 100644 --- a/packages/shared/locales/en.json +++ b/packages/shared/locales/en.json @@ -730,7 +730,7 @@ }, "table": { "header": { - "name": "Name", + "delegationId": "Delegation Id", "delegatedFunds": "Delegated Funds", "rewards": "Rewards", "epochs": "Epochs", From 0da2383138fa37372c2f95572ca9738a8fc3eb4f Mon Sep 17 00:00:00 2001 From: cpl121 Date: Mon, 11 Mar 2024 14:40:38 +0100 Subject: [PATCH 7/8] fix: error to show PingingBadge --- .../views/dashboard/delegation/Delegation.svelte | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/desktop/views/dashboard/delegation/Delegation.svelte b/packages/desktop/views/dashboard/delegation/Delegation.svelte index 67605aded65..4ff34f58189 100644 --- a/packages/desktop/views/dashboard/delegation/Delegation.svelte +++ b/packages/desktop/views/dashboard/delegation/Delegation.svelte @@ -146,8 +146,7 @@ isCopyable: true, clearBoxPadding: true, clearBackground: true, - classes: - 'flex flex-row justify-start items-center space-x-2 text-gray-600 dark:text-white text-xs font-medium', + classes: 'flex flex-row items-center text-gray-600 dark:text-white text-xs font-medium gap-2', }, slot: { component: PingingBadge, @@ -241,7 +240,12 @@ {#if renderCell.text} - {renderCell.slot} + {#if renderCell.slot} + + {/if} {renderCell.text} {:else} From c7a202044dfebe56ebc6eb29857fef3ccfa73e4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bego=C3=B1a=20Alvarez?= Date: Thu, 21 Mar 2024 12:30:19 +0100 Subject: [PATCH 8/8] chore: rename var --- .../desktop/views/dashboard/delegation/Delegation.svelte | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/desktop/views/dashboard/delegation/Delegation.svelte b/packages/desktop/views/dashboard/delegation/Delegation.svelte index 57983f11b76..4fb6ef64d46 100644 --- a/packages/desktop/views/dashboard/delegation/Delegation.svelte +++ b/packages/desktop/views/dashboard/delegation/Delegation.svelte @@ -36,7 +36,7 @@ let delegationData: IDelegationTable[] = [] let currentEpoch = 0 - let committeeAddress: string[] = [] + let committeeAddresses: string[] = [] enum Header { DelegationId = 'delegationId', @@ -97,7 +97,7 @@ async function setCurrentEpochAndCommittee(): Promise { const committeeResponse = await getCommitteeInfo() currentEpoch = committeeResponse?.epoch - committeeAddress = committeeResponse?.committee?.map((committee) => committee.address) || [] + committeeAddresses = committeeResponse?.committee?.map((committee) => committee.address) || [] } function handleDelegate(): void { @@ -189,10 +189,10 @@ component: PingingBadge, props: { classes: 'relative', - innerColor: committeeAddress?.some((address) => address === value) + innerColor: committeeAddresses?.some((address) => address === value) ? 'green-600' : 'red-500', - outerColor: committeeAddress?.some((address) => address === value) + outerColor: committeeAddresses?.some((address) => address === value) ? 'green-400' : 'red-300', },