WalletAPIServer uses a bit of rxjs (version 7) to handle data coming in from ledger live.
You should be familiar with it (if not, start here (opens in a new tab)). In case you just need a refresher, you'll find below all the different rxjs operators and functions used in wallet-api-server.

map (opens in a new tab)

observable (opens in a new tab)

BehaviorSubject (opens in a new tab)

Requires an initial value and emits the current value to new subscribers

// RxJS v6+
import { BehaviorSubject } from "rxjs";
const subject = new BehaviorSubject(123);
// two new subscribers will get initial value => output: 123, 123
// two subscribers will get new value => output: 456, 456;
// new subscriber will get latest value (456) => output: 456
// all three subscribers will get new value => output: 789, 789, 789;
// output: 123, 123, 456, 456, 456, 789, 789, 789

combineLatest (opens in a new tab)

When any observable emits a value, emit the last emitted value from each.

let's look at this function

const allowedCurrencies$ = new BehaviorSubject([]);
  [this.allCurrencies$, this.permissions.currencyIds$],

Here, allowedCurrencies emit first an empty array, then it emits a new value: anytime, this.allCurrencies$ or this.permissions.currencyIds$ changes Those two values are passed to a projection function (which simply finds the currencies we have defined here)

(opens in a new tab)

firstValueFrom (opens in a new tab)

Converts an observable to a promise by subscribing to the observable, and returning a promise that will resolve as soon as the first value arrives from the observable. The subscription will then be closed.

(opens in a new tab)

Copyright © Ledger SAS. All rights reserved. Ledger, Ledger Nano S, Ledger Vault, Bolos are registered trademarks of Ledger SAS