Skip to content

Commit

Permalink
remove splitAmount fix for "filling up the rest" behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
lollerfirst committed Jun 18, 2024
1 parent ec76cc3 commit a5e4cd2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
15 changes: 6 additions & 9 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@ import { sha256 } from '@noble/hashes/sha256';
function splitAmount(value: number, keyset: Keys, amountPreference?: Array<AmountPreference>): Array<number> {
const chunks: Array<number> = [];
if (amountPreference) {
if (amountPreference.length > 0) {
chunks.push(...getPreference(value, keyset, amountPreference));
value =
value -
chunks.reduce((curr, acc) => {
return curr + acc;
}, 0);
return chunks;
}
chunks.push(...getPreference(value, keyset, amountPreference));
value =
value -
chunks.reduce((curr, acc) => {
return curr + acc;
}, 0);
}
for (let i = 0; i < 32; i++) {
const mask: number = 1 << i;
Expand Down
6 changes: 1 addition & 5 deletions test/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ describe('test split custom amounts ', () => {
const chunks = utils.splitAmount(10, keys, tenToOneAndTwo);
expect(chunks).toStrictEqual([1, 1, 2, 2, 2, 2]);
});
const fiveTwelve: Array<AmountPreference> = [
{ amount: 512, count: 1 },
{ amount: 2, count: 1 },
{ amount: 4, count: 1}
];
const fiveTwelve: Array<AmountPreference> = [{ amount: 512, count: 2 }];
test('testing amount 518', async () => {
const chunks = utils.splitAmount(518, keys, fiveTwelve);
expect(chunks).toStrictEqual([512, 2, 4]);
Expand Down

0 comments on commit a5e4cd2

Please sign in to comment.