Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REF] improve handling incorrect token contract addr #1496

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions src/navigation/tabs/shop/components/GiftCardCatalog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import {Platform, View, TouchableOpacity} from 'react-native';
import {useForm, Controller} from 'react-hook-form';
import {ActiveOpacity, WIDTH} from '../../../../components/styled/Containers';
import ShopCarouselList, {ShopCarouselItem} from './ShopCarouselList';
import {BaseText, Paragraph, TextAlign} from '../../../../components/styled/Text';
import {
BaseText,
Paragraph,
TextAlign,
} from '../../../../components/styled/Text';
import GiftCardItem from './GiftCardItem';
import {
CardConfig,
Expand Down Expand Up @@ -221,13 +225,13 @@ export default ({
{purchasedGiftCards.length ? (
<>
<MyGiftCards supportedGiftCards={supportedGiftCards} />
{ availableGiftCards.length ? <SectionDivider /> : null }
{availableGiftCards.length ? <SectionDivider /> : null}
<SectionSpacer height={20} />
</>
) : (
<SectionSpacer height={40} />
)}
{ availableGiftCards.length ? (
{availableGiftCards.length ? (
<>
<SectionContainer>
<Controller
Expand Down Expand Up @@ -284,9 +288,14 @@ export default ({
</NoResultsImgContainer>
<Paragraph>
{t("We couldn't find a match for ")}
<BaseText style={{fontWeight: 'bold'}}>{searchVal}</BaseText>.
<BaseText style={{fontWeight: 'bold'}}>
{searchVal}
</BaseText>
.
</Paragraph>
<Paragraph>
{t('Please try searching something else.')}
</Paragraph>
<Paragraph>{t('Please try searching something else.')}</Paragraph>
</NoResultsContainer>
)}
</HideableView>
Expand All @@ -300,7 +309,9 @@ export default ({
onPress={() => setIsFilterSheetShown(!isFilterSheetShown)}>
<SectionHeaderButton>
{t('Filter')}
{numSelectedCategories ? ` (${numSelectedCategories})` : null}
{numSelectedCategories
? ` (${numSelectedCategories})`
: null}
</SectionHeaderButton>
</TouchableOpacity>
</SectionHeaderContainer>
Expand All @@ -325,7 +336,9 @@ export default ({
<ZeroState>
<TextAlign align={'center'}>
<Paragraph>
{t('No gift cards are currently available for purchase in your region. Please check back later.')}
{t(
'No gift cards are currently available for purchase in your region. Please check back later.',
)}
</Paragraph>
</TextAlign>
</ZeroState>
Expand Down
9 changes: 6 additions & 3 deletions src/navigation/wallet/components/BalanceDetailsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,12 @@ const BalanceDetailsModal = ({isVisible, closeModal, wallet}: Props) => {
</Row>
<LabelTip type="info">
<LabelTipText>
{t('The XRP ledger requires that all wallets maintain a minimum balance of XRP. This non-refundable XRP will remain permanently locked in your wallet.', {
lockedBalance: wallet.cryptoConfirmedLockedBalance,
})}
{t(
'The XRP ledger requires that all wallets maintain a minimum balance of XRP. This non-refundable XRP will remain permanently locked in your wallet.',
{
lockedBalance: wallet.cryptoConfirmedLockedBalance,
},
)}
</LabelTipText>
</LabelTip>
</>
Expand Down
8 changes: 6 additions & 2 deletions src/navigation/wallet/screens/AddCustomToken.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ const AddCustomToken = ({
const [currencyAbbreviation, setCurrencyAbbreviation] = useState<
string | undefined
>();
const [invalidTokenAddress, setInvalidTokenAddress] =
useState<boolean>(false);

const DESCRIPTIONS: Record<string, string> = {
eth: t('TokensOnEthereumNetworkDescription'),
Expand Down Expand Up @@ -487,8 +489,10 @@ const AddCustomToken = ({
addrData?.coin.toLowerCase() && network === addrData?.network;

if (!isValid) {
setInvalidTokenAddress(true);
return;
}
setInvalidTokenAddress(false);

let tokenContractInfo =
tokenOptionsByAddress?.[getCurrencyAbbreviation(tokenAddress, chain)];
Expand Down Expand Up @@ -620,7 +624,7 @@ const AddCustomToken = ({
onChangeText={(text: string) => {
setTokenInfo(text);
}}
error={errors.walletName?.message}
error={errors.walletName?.message || invalidTokenAddress}
value={tokenAddress}
/>
</View>
Expand All @@ -644,7 +648,7 @@ const AddCustomToken = ({
<ButtonContainer>
<Button
accessibilityLabel="add-custom-token-button"
disabled={!walletNameValue}
disabled={!walletNameValue || invalidTokenAddress}
onPress={add}
buttonStyle={'primary'}>
{t('Add Custom Token')}
Expand Down
9 changes: 8 additions & 1 deletion src/navigation/wallet/screens/AddWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,14 @@ const AddWallet = ({
);
}
} catch (err: any) {
dispatch(LogActions.error(JSON.stringify(err)));
const errstring =
err instanceof Error
? err.message
: err !== undefined
? JSON.stringify(err)
: 'An unknown error occurred';

dispatch(LogActions.debug(`Error adding wallet: ${errstring}`));
}
});

Expand Down
6 changes: 3 additions & 3 deletions src/store/wallet/effects/create/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -577,15 +577,15 @@ const createTokenWallet =
associatedWallet.credentials.chain,
);

const currentTokenOpts = tokenOptsByAddress[tokenAddressWithSuffix];
const currentTokenOpts = tokenOptsByAddress?.[tokenAddressWithSuffix];

if (!currentTokenOpts) {
dispatch(
LogActions.debug(
`Could not find tokenOpts for token: ${tokenAddressWithSuffix}. Avoid token creation...`,
),
);
return reject();
return reject(new Error(`Could not find token: ${tokenAddress}`));
}

const tokenCredentials: Credentials =
Expand Down Expand Up @@ -654,7 +654,7 @@ const createTokenWallet =
const errstring =
err instanceof Error ? err.message : JSON.stringify(err);
dispatch(LogActions.error(`Error creating token wallet: ${errstring}`));
reject();
reject(err);
}
});
};
Expand Down