-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(wallet): address tracker addresses$ now always emits addresses s…
…orted by derivation index
- Loading branch information
1 parent
143461f
commit 4fa3bd5
Showing
4 changed files
with
69 additions
and
33 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { GroupedAddress } from '@cardano-sdk/key-management'; | ||
|
||
/** | ||
* Sorts an array of addresses by their primary index and, if available, by the | ||
* index of their stakeKeyDerivationPath. | ||
* | ||
* @param addresses - The array of addresses to sort. | ||
* @returns A new sorted array of addresses. | ||
*/ | ||
export const sortAddresses = (addresses: GroupedAddress[]): GroupedAddress[] => | ||
[...addresses].sort((a, b) => { | ||
if (a.index !== b.index) { | ||
return a.index - b.index; | ||
} | ||
|
||
if (a.stakeKeyDerivationPath && b.stakeKeyDerivationPath) { | ||
return a.stakeKeyDerivationPath.index - b.stakeKeyDerivationPath.index; | ||
} | ||
|
||
if (a.stakeKeyDerivationPath && !b.stakeKeyDerivationPath) { | ||
return -1; | ||
} | ||
|
||
if (!a.stakeKeyDerivationPath && b.stakeKeyDerivationPath) { | ||
return 1; | ||
} | ||
|
||
return 0; | ||
}); |
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