Skip to content

Commit

Permalink
Fix send amount in tx
Browse files Browse the repository at this point in the history
  • Loading branch information
leonbit2022 committed Sep 6, 2023
1 parent b35acc4 commit 09f7bbf
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/example/src/hook/useTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const useTransaction = ({ size, offset }: UseTransaction) => {

const refresh = () => {
setError(undefined);
if(!loading) {
if (!loading) {
setCount(count + 1);
}
};
Expand All @@ -33,15 +33,15 @@ export const useTransaction = ({ size, offset }: UseTransaction) => {
useEffect(() => {
if (current && currentWalletType === WalletType.BitcoinWallet) {
setLoading(true);
queryActivities({ coin: current.coinCode, count: size, loadMoreTxs: lastTx })
queryActivities({ coin: current.coinCode, count: size * 2, loadMoreTxs: lastTx })
.then(res =>
res.activities.map(tx => {
const isReceive = tx.action === 'recv_external';
return {
ID: tx.txid,
type: isReceive ? TransactionTypes.Received : TransactionTypes.Sent,
status: tx.status === ActivityStatus.Complete ? TransactionStatus.Confirmed : TransactionStatus.Pending,
amount: Math.abs(tx.amount),
amount: (isReceive ? Math.abs(tx.amount) : tx.receiverAddresses?.[0]?.[1]) || 0,
address: (isReceive ? tx.senderAddresses?.[0] : tx.receiverAddresses?.[0]?.[0]) || '',
date: tx.createdTime * 1000,
fee: tx.fee,
Expand All @@ -53,6 +53,15 @@ export const useTransaction = ({ size, offset }: UseTransaction) => {
confirmThreshold: tx.confirmThreshold,
};
})
.reduce((list, cur) => {
if (list.some(tx => tx.ID === cur.ID)) {
// filter out the transaction indicates receiving, which is actually the transaction sent to change address,
// only keep the sending one for the same ID
return [...list, cur].filter(tx => tx.ID !== cur.ID || tx.type !== TransactionTypes.Received);
}
return [...list, cur];
}, [] as TransactionDetail[])
.slice(0, size)
)
.then((txList: TransactionDetail[]) => {
setTxList(txList);
Expand Down

0 comments on commit 09f7bbf

Please sign in to comment.