Skip to content

Commit

Permalink
feat: fix all amount of transfer in Nexa
Browse files Browse the repository at this point in the history
  • Loading branch information
huhuanming committed May 10, 2024
1 parent df18e81 commit c3c5a94
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/engine/src/vaults/impl/nexa/Vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,12 @@ export default class Vault extends VaultBase {
getConfirmedUTXOs<T extends { value: string | number }>(
utxos: T[],
amount: string,
fee: string,
minTransferAmount = '0',
): T[] {
const transactionAmount = new BigNumber(amount).plus(minTransferAmount);
const transactionAmount = new BigNumber(amount)
.plus(fee)
.plus(minTransferAmount);
const confirmedUTXOs = utxos.sort((a, b) =>
new BigNumber(b.value).gt(a.value) ? 1 : -1,
);
Expand All @@ -260,9 +263,15 @@ export default class Vault extends VaultBase {
break;
}
}

// all amount
if (sum.eq(amount) && i === confirmedUTXOs.length) {
return utxos;
}
if (sum.lt(transactionAmount)) {
return [];
}

return confirmedUTXOs.slice(0, i + 1);
}

Expand Down Expand Up @@ -332,8 +341,8 @@ export default class Vault extends VaultBase {
})),
new BigNumber(encodedTx.transferInfo?.amount || 0)
.shiftedBy(network.decimals)
.plus(encodedTx?.gas || 0)
.toFixed(),
new BigNumber(encodedTx?.gas || 0).toFixed(),
await this.getMinTransferAmount(),
);

Expand Down Expand Up @@ -380,6 +389,7 @@ export default class Vault extends VaultBase {
new BigNumber(encodedTx.transferInfo?.amount || 0)
.shiftedBy(network.decimals)
.toFixed(),
'0',
await this.getMinTransferAmount(),
).length;
const estimateSizedSize = estimateSize(vinLength, encodedTx.outputs);
Expand Down

0 comments on commit c3c5a94

Please sign in to comment.