-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TW-1646 Add extra anti-exception logic for some functions
- Loading branch information
1 parent
f5170e5
commit 7e6d46c
Showing
5 changed files
with
51 additions
and
44 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,33 +1,50 @@ | ||
import React, { memo } from 'react'; | ||
import React, { memo, useCallback } from 'react'; | ||
import { StyleProp, Text, View, ViewStyle } from 'react-native'; | ||
|
||
import { formatSize } from 'src/styles/format-size'; | ||
import { useColors } from 'src/styles/use-colors'; | ||
import { copyStringToClipboard } from 'src/utils/clipboard.utils'; | ||
import { isDefined } from 'src/utils/is-defined'; | ||
import { isString } from 'src/utils/is-string'; | ||
|
||
import { ButtonMedium } from '../button/button-medium/button-medium'; | ||
import { ButtonSmallTryAgain } from '../button/button-small/button-small-try-again'; | ||
import { Icon } from '../icon/icon'; | ||
import { IconNameEnum } from '../icon/icon-name.enum'; | ||
|
||
import { useErrorBoundaryContentStyles } from './content.styles'; | ||
|
||
interface ErrorBoundaryContentProps { | ||
errorMessage: string; | ||
error: Error; | ||
whileMessage?: string; | ||
style?: StyleProp<ViewStyle>; | ||
onTryAgainClick: EmptyFn; | ||
} | ||
|
||
export const ErrorBoundaryContent = memo<ErrorBoundaryContentProps>(({ errorMessage, style, onTryAgainClick }) => { | ||
const styles = useErrorBoundaryContentStyles(); | ||
const colors = useColors(); | ||
|
||
return ( | ||
<View style={[styles.root, style]}> | ||
<View style={styles.content}> | ||
<Icon name={IconNameEnum.AlertTriangle} size={formatSize(64)} color={colors.destructive} /> | ||
<Text style={styles.header}>Oops!</Text> | ||
<Text style={styles.errorText}>{errorMessage}</Text> | ||
<ButtonSmallTryAgain title="Try again" onPress={onTryAgainClick} /> | ||
// TODO: set to `false` before release | ||
const SHOULD_SHOW_ERROR_DETAILS = true; | ||
|
||
export const ErrorBoundaryContent = memo<ErrorBoundaryContentProps>( | ||
({ error, whileMessage, style, onTryAgainClick }) => { | ||
const errorMessage = isString(whileMessage) ? `Something went wrong while ${whileMessage}` : 'Something went wrong'; | ||
const styles = useErrorBoundaryContentStyles(); | ||
const colors = useColors(); | ||
|
||
const copyErrorStack = useCallback(() => copyStringToClipboard(error.stack), []); | ||
|
||
return ( | ||
<View style={[styles.root, style]}> | ||
<View style={styles.content}> | ||
<Icon name={IconNameEnum.AlertTriangle} size={formatSize(64)} color={colors.destructive} /> | ||
<Text style={styles.header}>Oops!</Text> | ||
<Text style={styles.errorText}>{errorMessage}</Text> | ||
{SHOULD_SHOW_ERROR_DETAILS && <Text style={styles.errorText}>{error.message ?? 'No error message'}</Text>} | ||
<ButtonSmallTryAgain title="Try again" onPress={onTryAgainClick} /> | ||
{SHOULD_SHOW_ERROR_DETAILS && isDefined(error.stack) && ( | ||
<ButtonMedium title="Copy error stack" iconName={IconNameEnum.Copy} onPress={copyErrorStack} /> | ||
)} | ||
</View> | ||
</View> | ||
</View> | ||
); | ||
}); | ||
); | ||
} | ||
); |
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 |
---|---|---|
@@ -1,9 +1,18 @@ | ||
import { BigNumber } from 'bignumber.js'; | ||
|
||
import { isDefined } from './is-defined'; | ||
import { ZERO } from './number.util'; | ||
import { mutezToTz } from './tezos.util'; | ||
|
||
export const getDollarValue = (balance: string, decimals: number, exchangeRate = 0) => { | ||
const dollarValue = mutezToTz(new BigNumber(balance), decimals).multipliedBy(exchangeRate); | ||
export const getDollarValue = ( | ||
balance: string | nullish, | ||
decimals: number | nullish, | ||
exchangeRate: number | nullish | ||
) => { | ||
const dollarValue = | ||
isDefined(balance) && isDefined(decimals) && isDefined(exchangeRate) | ||
? mutezToTz(new BigNumber(balance), decimals).multipliedBy(exchangeRate) | ||
: ZERO; | ||
|
||
return dollarValue.isNaN() ? new BigNumber(0) : dollarValue; | ||
return dollarValue.isNaN() ? ZERO : dollarValue; | ||
}; |
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