From 5b361aae3be8a1d587b13ff4f7f3421650d53b81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Vitor=20de=20Lima=20Matos?= Date: Sat, 9 Oct 2021 20:53:53 -0300 Subject: [PATCH] sdk: small fix to allow LC to start on registries without TNs If starting with userDepositContractAddress as contract's entrypoint, it'd crash if the `TokenNetworkRegistry` didn't have any registered `TokenNetwork`. This fix allows the client to start, so one can use `registerToken` to register a TN from this session. --- raiden-ts/CHANGELOG.md | 2 ++ raiden-ts/src/helpers.ts | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/raiden-ts/CHANGELOG.md b/raiden-ts/CHANGELOG.md index 281ed7bfec..d3a1953f80 100644 --- a/raiden-ts/CHANGELOG.md +++ b/raiden-ts/CHANGELOG.md @@ -8,8 +8,10 @@ - [#2965] Remove `options.subkey` on certain `Raiden` public methods; if you need to force subkey or main account usage for single txs, set `config.subkey` then reset after tx is sent; default behavior is kept ### Fixed +- [#2913] Fix crash when starting client with `userDepositContractAddress` as contracts entrypoint on a `TokenNetworkRegistry` with no registered tokens yet - [#2963] Don't set channel as `closing` upon `channelClose.request`, allowing user to cancel Metamask's prompt and keep an usable channel; Channel becomes `closing` only after tx is sent +[#2913]: https://github.com/raiden-network/light-client/issues/2913 [#2949]: https://github.com/raiden-network/light-client/issues/2949 [#2952]: https://github.com/raiden-network/light-client/issues/2952 [#2953]: https://github.com/raiden-network/light-client/pull/2953 diff --git a/raiden-ts/src/helpers.ts b/raiden-ts/src/helpers.ts index 6a9a3e9500..508fdd59cb 100644 --- a/raiden-ts/src/helpers.ts +++ b/raiden-ts/src/helpers.ts @@ -410,14 +410,14 @@ export async function fetchContractsInfo( const serviceRegistry = (await monitoringServiceContract.service_registry()) as Address; const toBlock = await provider.getBlockNumber(); - let firstBlock = await firstValueFrom( + const firstBlock = await firstValueFrom( getLogsByChunk$(provider, { ...tokenNetworkRegistryContract.filters.TokenNetworkCreated(null, null), fromBlock: 1, toBlock, }).pipe(pluck('blockNumber'), filter(isntNil)), + { defaultValue: toBlock }, ); - firstBlock ??= 0; const oneToN = (await userDepositContract.one_to_n_address()) as Address;