-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(wallet,wallet-dashboard): fix total stake/unstake amount in timel…
…ocks transaction summary (#4824) * fix: display banner correctly * fix total stake/unstake amount in timelocks transaction summary * feat: update to use events instead of event and move logic to StakeTransactionDetails * feat: use reduce * fix: display correctly unstake amount * remove principalAmount and rewardAmount * fix: improvements * feat: improve naming
- Loading branch information
1 parent
9527118
commit a85d8cd
Showing
12 changed files
with
120 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { STAKING_REQUEST_EVENT } from '../../constants'; | ||
import { StakeEventJson } from '../../interfaces'; | ||
import type { IotaEvent } from '@iota/iota-sdk/client'; | ||
|
||
export function getStakeDetailsFromEvents(events: IotaEvent[]): { | ||
totalStakedAmount: string; | ||
validatorAddress: string; | ||
epoch: number; | ||
} { | ||
const stakeEvent = events.find((event) => event.type === STAKING_REQUEST_EVENT); | ||
|
||
const eventJson = stakeEvent?.parsedJson as StakeEventJson; | ||
const totalStakedAmount = events?.reduce((sum, event) => { | ||
return sum + Number((event.parsedJson as { amount: number }).amount || 0); | ||
}, 0); | ||
return { | ||
totalStakedAmount: totalStakedAmount.toString(), | ||
validatorAddress: eventJson.validator_address || '', | ||
epoch: Number(eventJson.epoch || '0'), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { UNSTAKING_REQUEST_EVENT } from '../../constants'; | ||
import { UnstakeEventJson } from '../../interfaces'; | ||
import type { IotaEvent } from '@iota/iota-sdk/client'; | ||
|
||
export function getUnstakeDetailsFromEvents(events: IotaEvent[]): { | ||
validatorAddress: string; | ||
unstakeAmount: bigint; | ||
totalUnstakeAmount: bigint; | ||
unstakeRewards: bigint; | ||
} { | ||
const unstakeEvent = events.find(({ type }) => type === UNSTAKING_REQUEST_EVENT); | ||
const unstakeEventJson = unstakeEvent?.parsedJson as UnstakeEventJson; | ||
|
||
const unstakeAmount = events?.reduce((sum, event) => { | ||
return ( | ||
sum + Number((event.parsedJson as { principal_amount: number }).principal_amount || 0) | ||
); | ||
}, 0); | ||
|
||
const unstakeRewards = events?.reduce((sum, event) => { | ||
return sum + Number((event.parsedJson as { reward_amount: number }).reward_amount || 0); | ||
}, 0); | ||
|
||
const totalUnstakeAmount = BigInt(unstakeAmount) + BigInt(unstakeRewards); | ||
|
||
return { | ||
validatorAddress: unstakeEventJson.validator_address || '', | ||
unstakeAmount: BigInt(unstakeAmount), | ||
unstakeRewards: BigInt(unstakeRewards), | ||
totalUnstakeAmount, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters