How to use the @ledgerhq/live-common/lib/bridge.getCurrencyBridge function in @ledgerhq/live-common

To help you get started, weā€™ve selected a few @ledgerhq/live-common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github LedgerHQ / ledger-live-mobile / src / screens / MigrateAccounts / 03-Progress.js View on Github external
const startScanAccountsDevice = useCallback(() => {
    const syncConfig = {
      // TODO later we need to paginate only a few ops, not all (for add accounts)
      // paginationConfig will come from redux
      paginationConfig: {},
    };
    unsub();
    scanSubscription.current = getCurrencyBridge(currency)
      .scanAccounts({ currency, deviceId, syncConfig })
      .pipe(
        reduce(
          (all: Account[], event: ScanAccountEvent) =>
            all.concat(event.account),
          [],
        ),
      )
      .subscribe({
        next: scannedAccounts => {
          setAccounts(
            migrateAccounts({ scannedAccounts, existingAccounts: accounts }),
          );
          setStatus("done");
        },
        error: err => {
github LedgerHQ / ledger-live-desktop / src / components / modals / AddAccounts / steps / 03-step-import.js View on Github external
startScanAccountsDevice() {
    this.unsub()
    const { currency, device, setScanStatus, setScannedAccounts } = this.props
    if (!currency || !device) return
    const mainCurrency = currency.type === 'TokenCurrency' ? currency.parentCurrency : currency
    try {
      const bridge = getCurrencyBridge(mainCurrency)

      // TODO: use the real device
      const devicePath = device.path

      // will be set to false if an existing account is found
      let onlyNewAccounts = true

      this.scanSubscription = bridge
        .scanAccountsOnDevice(mainCurrency, devicePath)
        .pipe(
          filter(e => e.type === 'discovered'),
          map(e => e.account),
        )
        .subscribe({
          next: account => {
            const { scannedAccounts, checkedAccountsIds, existingAccounts } = this.props
github LedgerHQ / ledger-live-mobile / src / screens / AddAccounts / 03-Accounts.js View on Github external
startSubscription = () => {
    const { navigation } = this.props;
    const currency = navigation.getParam("currency");
    const deviceId = navigation.getParam("deviceId");
    const bridge = getCurrencyBridge(currency);
    const syncConfig = {
      // TODO later we need to paginate only a few ops, not all (for add accounts)
      // paginationConfig will come from redux
      paginationConfig: {},
    };
    this.scanSubscription = concat(
      from(prepareCurrency(currency)).pipe(ignoreElements()),
      bridge.scanAccounts({ currency, deviceId, syncConfig }),
    ).subscribe({
      next: ({ account }) =>
        this.setState(
          ({ scannedAccounts, selectedIds }, { existingAccounts }) => {
            const hasAlreadyBeenScanned = !!scannedAccounts.find(
              a => account.id === a.id,
            );
            const hasAlreadyBeenImported = !!existingAccounts.find(
github LedgerHQ / ledger-live-common / cli / src / __tests__ / bridges.js View on Github external
currenciesRelated.map(({ currencyData, currency, impl }) => {
  const bridge = getCurrencyBridge(currency);
  describe(impl + " " + currency.id + " currency bridge", () => {
    test("functions are defined", () => {
      expect(typeof bridge.scanAccounts).toBe("function");
      expect(typeof bridge.preload).toBe("function");
      expect(typeof bridge.hydrate).toBe("function");
    });

    test("preload and rehydrate", async () => {
      const data1 = await bridge.preload();
      const serialized = JSON.stringify(data1);
      if (data1) {
        expect(serialized).toBeDefined();
        const data2 = await bridge.preload();
        expect(data1).toMatchObject(data2);
        expect(JSON.parse(serialized)).toMatchObject(data2);
        bridge.hydrate(data1);
github LedgerHQ / ledger-live-mobile / src / bridge / cache.js View on Github external
export async function hydrateCurrency(currency: CryptoCurrency) {
  const value = await getCurrencyCache(currency);
  const bridge = getCurrencyBridge(currency);
  bridge.hydrate(value);
}
github LedgerHQ / ledger-live-desktop / src / bridge / cache.js View on Github external
async currency => {
    const bridge = getCurrencyBridge(currency)
    const preloaded = await bridge.preload()
    setCurrencyCache(currency, preloaded)
  },
  currency => currency.id,
github LedgerHQ / ledger-live-mobile / src / bridge / cache.js View on Github external
async currency => {
    log("bridge/cache", "prepareCurrency " + currency.id + "...");
    const bridge = getCurrencyBridge(currency);
    const preloaded = await bridge.preload();
    await setCurrencyCache(currency, preloaded);
    log("bridge/cache", "prepareCurrency " + currency.id + " DONE.");
  },
  currency => currency.id,
github LedgerHQ / ledger-live-common / cli / src / scan.js View on Github external
spendableBalance: new BigNumber(0),
              operationsCount: 0,
              operations: [],
              pendingOperations: []
            };
            return account;
          })
        ).pipe(
          concatMap(account =>
            getAccountBridge(account, null)
              .sync(account, syncConfig)
              .pipe(reduce((a: Account, f: *) => f(a), account))
          )
        );
      }
      return getCurrencyBridge(cur)
        .scanAccounts({
          currency: cur,
          deviceId: device || "",
          scheme: scheme && asDerivationMode(scheme),
          syncConfig
        })
        .pipe(
          filter(e => e.type === "discovered"),
          map(e => e.account)
        );
    }),
    skip(index || 0),