Skip to content

Commit

Permalink
Fix utxos sorting to sort before grouping
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidTranDucVL committed Oct 18, 2021
1 parent cfd8bb6 commit a67db76
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
20 changes: 7 additions & 13 deletions app/frontend/wallet/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,11 @@ const Account = ({config, cryptoProvider, blockchainExplorer, accountIndex}: Acc
}

const arrangeUtxos = (utxos: UTxO[], txPlanArgs: TxPlanArgs): UTxO[] => {
const sortUtxos = (utxos: UTxO[]): UTxO[] =>
utxos.sort((a, b) =>
a.txHash === b.txHash ? a.outputIndex - b.outputIndex : a.txHash.localeCompare(b.txHash)
)
const nonStakingUtxos = utxos.filter(({address}) => !isBase(addressToHex(address)))
const baseAddressUtxos = utxos.filter(({address}) => isBase(addressToHex(address)))
const sortedUtxos = utxos.sort((a, b) =>
a.txHash === b.txHash ? a.outputIndex - b.outputIndex : a.txHash.localeCompare(b.txHash)
)
const nonStakingUtxos = sortedUtxos.filter(({address}) => !isBase(addressToHex(address)))
const baseAddressUtxos = sortedUtxos.filter(({address}) => isBase(addressToHex(address)))
const adaOnlyUtxos = baseAddressUtxos.filter(({tokenBundle}) => tokenBundle.length === 0)
const tokenUtxos = baseAddressUtxos.filter(({tokenBundle}) => tokenBundle.length > 0)

Expand All @@ -302,14 +301,9 @@ const Account = ({config, cryptoProvider, blockchainExplorer, accountIndex}: Acc
({tokenBundle}) =>
!tokenBundle.some((token) => token.policyId === policyId && token.assetName === assetName)
)
return sortUtxos([
...targetTokenUtxos,
...nonStakingUtxos,
...adaOnlyUtxos,
...nonTargetTokenUtxos,
])
return [...targetTokenUtxos, ...nonStakingUtxos, ...adaOnlyUtxos, ...nonTargetTokenUtxos]
}
return sortUtxos([...nonStakingUtxos, ...adaOnlyUtxos, ...tokenUtxos])
return [...nonStakingUtxos, ...adaOnlyUtxos, ...tokenUtxos]
}

const getTxPlan = async (txPlanArgs: TxPlanArgs, utxos: UTxO[]): Promise<TxPlanResult> => {
Expand Down
2 changes: 1 addition & 1 deletion app/tests/src/wallet/account/utxo-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ export const utxoSettings = {
txType: TxType.SEND_ADA,
},
availableUtxos: [utxos.adaOnly, utxos.withTokens2, utxos.legacy, utxos.withTokens1],
selectedUtxos: [utxos.legacy, utxos.adaOnly, utxos.withTokens1, utxos.withTokens2],
selectedUtxos: [utxos.withTokens1, utxos.legacy, utxos.adaOnly, utxos.withTokens2],
},
}

0 comments on commit a67db76

Please sign in to comment.