From 07f118e591c781e37be879e75ce2439746b26d29 Mon Sep 17 00:00:00 2001 From: Marcel Ebert Date: Tue, 1 Sep 2020 16:59:52 +0200 Subject: [PATCH] Don't rethrow error in wellknown accounts hook --- src/Generic/hooks/stellar-ecosystem.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Generic/hooks/stellar-ecosystem.ts b/src/Generic/hooks/stellar-ecosystem.ts index 0ed4aae85..7555cae37 100644 --- a/src/Generic/hooks/stellar-ecosystem.ts +++ b/src/Generic/hooks/stellar-ecosystem.ts @@ -13,7 +13,8 @@ export function useTickerAssets(testnet: boolean) { } export function useWellKnownAccounts(testnet: boolean) { - let accounts: AccountRecord[] + const [error, setError] = React.useState(undefined) + let accounts: AccountRecord[] = [] const forceRerender = useForceRerender() const fetchAccounts = () => fetchWellknownAccounts(testnet) @@ -23,22 +24,24 @@ export function useWellKnownAccounts(testnet: boolean) { } catch (thrown) { if (thrown && typeof thrown.then === "function") { // Promise thrown to suspend component – prevent suspension - accounts = [] thrown.then(forceRerender, trackError) + accounts = [] } else { - // It's an error – re-throw - throw thrown + if (!error || error.message !== thrown.message) { + setError(thrown) + } } } const wellknownAccounts = React.useMemo(() => { return { accounts, + error, lookup(publicKey: string): AccountRecord | undefined { return accounts.find(account => account.address === publicKey) } } - }, [accounts]) + }, [accounts, error]) return wellknownAccounts }