forked from MystenLabs/sui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[explorer] - restore transaction amount (MystenLabs#10498)
## Description Add amount back to TransactionView ## Test Plan How did you test the new or updated feature? --- If your changes are not user-facing and not a breaking change, you can skip the following section. Otherwise, please indicate what changed, and then add to the Release Notes section as highlighted during the release process. ### Type of Change (Check all that apply) - [ ] user-visible impact - [ ] breaking change for a client SDKs - [ ] breaking change for FNs (FN binary must upgrade) - [ ] breaking change for validators or node operators (must upgrade binaries) - [ ] breaking change for on-chain data layout - [ ] necessitate either a data wipe or data migration ### Release notes
- Loading branch information
1 parent
e3d11d6
commit d7454a2
Showing
5 changed files
with
64 additions
and
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import { | ||
SUI_TYPE_ARG, | ||
SuiTransactionBlockResponse, | ||
getTotalGasUsed, | ||
getTransactionSender, | ||
} from '@mysten/sui.js'; | ||
import { useMemo } from 'react'; | ||
|
||
export function useGetTransferAmount(txnData: SuiTransactionBlockResponse) { | ||
const { balanceChanges } = txnData; | ||
const sender = getTransactionSender(txnData); | ||
const gas = getTotalGasUsed(txnData); | ||
const changes = useMemo( | ||
() => | ||
balanceChanges | ||
? balanceChanges?.map(({ coinType, owner, amount }) => ({ | ||
coinType, | ||
address: | ||
owner === 'Immutable' | ||
? 'Immutable' | ||
: 'AddressOwner' in owner | ||
? owner.AddressOwner | ||
: 'ObjectOwner' in owner | ||
? owner.ObjectOwner | ||
: '', | ||
amount: | ||
coinType === SUI_TYPE_ARG && BigInt(amount) < 0n | ||
? BigInt(amount) + BigInt(gas ?? 0n) | ||
: BigInt(amount), | ||
})) | ||
: [], | ||
[balanceChanges, gas] | ||
); | ||
// take absolute value of the first balance change entry for display | ||
const [change] = changes; | ||
const amount = change?.amount | ||
? change.amount < 0n | ||
? -change.amount | ||
: change.amount | ||
: 0n; | ||
|
||
return { | ||
balanceChanges: changes, | ||
coinType: change.coinType, | ||
gas, | ||
sender, | ||
amount, | ||
}; | ||
} |
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