Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tired-socks-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@stakekit/widget": patch
---

feat(ledger): parent account handling
41 changes: 30 additions & 11 deletions packages/widget/src/providers/ledger/ledger-connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,38 @@ const createLedgerLiveConnector = ({
await getLedgerCurrencies(walletApiClient)
).unsafeCoerce();

const accounts = (
await EitherAsync(() => walletApiClient.account.list()).mapLeft((e) => {
console.log(e);
return new Error("could not get accounts");
})
const allAccounts = (
await EitherAsync(() => walletApiClient.account.list())
.map((val) => ({
accounts: val,
accountsMap: new Map<Account["id"], Account>(
val.map((v) => [v.id, v])
),
}))
.map((val) =>
val.accounts.map((acc) =>
acc.parentAccountId
? Maybe.fromNullable(val.accountsMap.get(acc.parentAccountId))
.map((parentAcc) => ({
...acc,
currency: parentAcc.currency,
}))
.orDefault(acc)
: acc
)
)
.mapLeft((e) => {
console.log(e);
return new Error("could not get accounts");
})
).unsafeCoerce();

ledgerAccounts = allAccounts.filter((a) => !a.parentAccountId);

const filteredSupportedLedgerFamiliesWithCurrency =
getFilteredSupportedLedgerFamiliesWithCurrency({
ledgerCurrencies,
accounts,
accounts: ledgerAccounts,
enabledChainsMap,
});

Expand Down Expand Up @@ -116,9 +137,7 @@ const createLedgerLiveConnector = ({
$filteredChains.next([...enabled, ...disabled]);
$disabledChains.next(disabled);

ledgerAccounts = accounts;

const accountsWithChain = accounts
const accountsWithChain = allAccounts
.reduce(
(acc, next) => {
const family = ledgerCurrencies.get(next.currency);
Expand Down Expand Up @@ -177,10 +196,10 @@ const createLedgerLiveConnector = ({
if (accId.startsWith("js:")) {
const [, , , address] = accId.split(":");

return { type: "address", address };
return { type: "address", address } as const;
}

return { type: "accountId", accountId: accId };
return { type: "accountId", accountId: accId } as const;
})
);

Expand Down