-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
service worker crashes might cause infinite loader show button to reload extension on: - unhandled errors in service worker - unhandled promise rejections in service worker - any error in BaseWallet observables
- Loading branch information
1 parent
6258a10
commit 20e57a0
Showing
18 changed files
with
196 additions
and
21 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
apps/browser-extension-wallet/src/components/Crash/Crash.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
@import '../../../../../packages/common/src/ui/styles/theme.scss'; | ||
|
||
.crashContainer { | ||
@include flex-center; | ||
flex-direction: column; | ||
height: 100%; | ||
gap: size_unit(2); | ||
|
||
.crashText { | ||
color: var(--text-color-primary); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
apps/browser-extension-wallet/src/components/Crash/Crash.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React from 'react'; | ||
import classNames from 'classnames'; | ||
import { useTranslation } from 'react-i18next'; | ||
import styles from './Crash.module.scss'; | ||
import { Button } from '@input-output-hk/lace-ui-toolkit'; | ||
import { useRuntime } from '@hooks/useRuntime'; | ||
|
||
export const Crash = (): React.ReactElement => { | ||
const { t } = useTranslation(); | ||
const runtime = useRuntime(); | ||
|
||
return ( | ||
<div className={classNames([styles.crashContainer])} data-testid="crash"> | ||
<p className={styles.crashText} data-testid="crash-text"> | ||
{t('general.errors.crash')} | ||
</p> | ||
<Button.CallToAction | ||
onClick={() => runtime.reload()} | ||
label={t('general.errors.reloadExtension')} | ||
data-testid="crash-reload" | ||
/> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './Crash'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { ObservableWallet } from '@cardano-sdk/wallet'; | ||
import { useObservable } from '@lace/common'; | ||
import { useBackgroundServiceAPIContext } from '@providers'; | ||
import { useWalletStore } from '@src/stores'; | ||
import { useMemo } from 'react'; | ||
import { catchError, take, of, merge, EMPTY } from 'rxjs'; | ||
import { toEmpty } from '@cardano-sdk/util-rxjs'; | ||
import { getErrorMessage } from '@src/utils/get-error-message'; | ||
|
||
const anyError = (wallet: ObservableWallet | undefined) => | ||
wallet | ||
? merge( | ||
wallet.addresses$, | ||
wallet.assetInfo$, | ||
wallet.balance.rewardAccounts.deposit$, | ||
wallet.balance.rewardAccounts.rewards$, | ||
wallet.balance.utxo.available$, | ||
wallet.balance.utxo.total$, | ||
wallet.balance.utxo.unspendable$, | ||
wallet.currentEpoch$, | ||
wallet.delegation.distribution$, | ||
wallet.delegation.portfolio$, | ||
wallet.delegation.rewardAccounts$, | ||
wallet.delegation.rewardsHistory$, | ||
wallet.eraSummaries$, | ||
wallet.genesisParameters$, | ||
wallet.handles$, | ||
wallet.protocolParameters$, | ||
wallet.governance.isRegisteredAsDRep$, | ||
wallet.publicStakeKeys$, | ||
wallet.syncStatus.isAnyRequestPending$, | ||
wallet.syncStatus.isSettled$, | ||
wallet.syncStatus.isUpToDate$, | ||
wallet.tip$, | ||
wallet.transactions.history$, | ||
wallet.transactions.rollback$, | ||
wallet.utxo.available$, | ||
wallet.utxo.total$, | ||
wallet.utxo.unspendable$ | ||
).pipe( | ||
toEmpty, | ||
catchError((error) => of({ type: 'base-wallet-error', message: getErrorMessage(error) })), | ||
take(1) | ||
) | ||
: EMPTY; | ||
|
||
type FatalError = { | ||
type: string; | ||
message: string; | ||
}; | ||
|
||
export const useFatalError = (): FatalError | undefined => { | ||
const backgroundService = useBackgroundServiceAPIContext(); | ||
const unhandledServiceWorkerError = useObservable(backgroundService.unhandledError$); | ||
const { cardanoWallet } = useWalletStore(); | ||
const walletError$ = useMemo(() => anyError(cardanoWallet?.wallet), [cardanoWallet?.wallet]); | ||
const walletError = useObservable(walletError$); | ||
return unhandledServiceWorkerError || walletError; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { runtime } from 'webextension-polyfill'; | ||
|
||
export type LaceRuntime = { reload: () => void }; | ||
|
||
export const useRuntime = (): LaceRuntime => ({ | ||
reload: runtime.reload | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const getErrorMessage = (error: unknown): string => | ||
error && typeof error.toString === 'function' ? error.toString() : ''; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.