Skip to content

Commit

Permalink
[REF] simplify adding new chains
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielbazan7 committed Sep 27, 2022
1 parent 89a879b commit 29f9623
Show file tree
Hide file tree
Showing 80 changed files with 1,927 additions and 1,217 deletions.
5 changes: 4 additions & 1 deletion src/components/amount/Amount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const CurrencyText = styled(BaseText)`
export interface AmountProps {
cryptoCurrencyAbbreviation?: string;
fiatCurrencyAbbreviation?: string;
chain?: string;
context?: string;
buttonState?: ButtonState;

Expand All @@ -95,6 +96,7 @@ export interface AmountProps {
const Amount: React.VFC<AmountProps> = ({
cryptoCurrencyAbbreviation,
fiatCurrencyAbbreviation,
chain,
context,
buttonState,
onSubmit,
Expand Down Expand Up @@ -150,7 +152,7 @@ const Amount: React.VFC<AmountProps> = ({
const updateAmount = (_val: string) => {
const val = Number(_val);

if (isNaN(val) || !cryptoCurrencyAbbreviation) {
if (isNaN(val) || !cryptoCurrencyAbbreviation || !chain) {
updateAmountConfig(current => ({
...current,
displayAmount: _val,
Expand All @@ -167,6 +169,7 @@ const Amount: React.VFC<AmountProps> = ({
ParseAmount(
primaryIsFiat ? val / rate : val,
cryptoCurrencyAbbreviation.toLowerCase(),
chain,
),
).amount;

Expand Down
4 changes: 2 additions & 2 deletions src/components/currency-image/CurrencyImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const CurrencyImageContainer = styled.View`
`;

const BadgeContainer = styled.View<{size?: number}>`
height: ${({size = 56}) => size}%;
width: ${({size = 56}) => size}%;
height: ${({size = 54}) => size}%;
width: ${({size = 54}) => size}%;
position: absolute;
right: 0;
bottom: 0;
Expand Down
5 changes: 3 additions & 2 deletions src/components/list/ContactRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const RowContainer = styled.View`
export interface ContactRowProps {
address: string;
coin: string;
chain: string;
network: string;
name: string;
tag?: number; // backward compatibility
Expand All @@ -47,12 +48,12 @@ interface Props {
const ContactRow = ({contact, onPress}: Props) => {
const theme = useTheme();
const underlayColor = theme.dark ? '#121212' : '#fbfbff';
const {coin, name, email, address} = contact;
const {coin, name, email, address, chain} = contact;
return (
<ContactContainer underlayColor={underlayColor} onPress={onPress}>
<RowContainer>
<ContactImageContainer>
<ContactIcon name={name} coin={coin} size={45} />
<ContactIcon name={name} coin={coin} size={45} chain={chain} />
</ContactImageContainer>
<ContactColumn>
<H5>{name}</H5>
Expand Down
47 changes: 31 additions & 16 deletions src/components/list/CurrencySelectionRow.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {memo, useCallback} from 'react';
import React, {memo, ReactElement, useCallback} from 'react';
import {useTranslation} from 'react-i18next';
import {ImageRequireSource, View} from 'react-native';
import styled from 'styled-components/native';
Expand All @@ -12,6 +12,7 @@ import {
Slate30,
SlateDark,
} from '../../styles/colors';
import {getBadgeImg} from '../../utils/helper-methods';
import Checkbox from '../checkbox/Checkbox';
import {CurrencyImage} from '../currency-image/CurrencyImage';
import haptic from '../haptic-feedback/haptic';
Expand All @@ -23,6 +24,7 @@ export type CurrencySelectionItem = Pick<
SupportedCurrencyOption,
'id' | 'currencyAbbreviation' | 'currencyName' | 'img' | 'isToken'
> & {
chain: string;
imgSrc?: ImageRequireSource | undefined;
selected?: boolean;
disabled?: boolean;
Expand All @@ -34,7 +36,7 @@ export type CurrencySelectionRowProps = {
description?: string;
hideCheckbox?: boolean;
selectionMode?: CurrencySelectionMode;
onToggle?: (id: string) => void;
onToggle?: (currencyAbbreviation: string) => void;
onViewAllTokensPressed?: (
currency: CurrencySelectionItem,
tokens: CurrencySelectionItem[],
Expand Down Expand Up @@ -142,28 +144,42 @@ export const ChainSelectionRow: React.VFC<ChainSelectionRowProps> = memo(
);

interface TokenSelectionRowProps {
chainImg?: CurrencySelectionItem['img'];
token: CurrencySelectionItem;
hideCheckbox?: boolean;
selectionMode?: CurrencySelectionMode;
onToggle?: (id: string) => any;
onToggle?: (currencyAbbreviation: string) => any;
hideArrow?: boolean;
badgeUri?: string | ((props?: any) => ReactElement);
}

export const TokenSelectionRow: React.VFC<TokenSelectionRowProps> = memo(
props => {
const {chainImg, token, hideCheckbox, selectionMode, onToggle} = props;
const {
token,
hideCheckbox,
selectionMode,
onToggle,
hideArrow,
badgeUri: _badgeUri,
} = props;
const badgeUri =
_badgeUri || getBadgeImg(token.currencyAbbreviation, token.chain);

return (
<FlexRow style={{marginBottom: 24}} onPress={() => onToggle?.(token.id)}>
<CurrencyColumn style={{marginRight: 16}}>
<NestedArrowIcon />
</CurrencyColumn>
<FlexRow
style={{marginBottom: 24}}
onPress={() => onToggle?.(token.currencyAbbreviation)}>
{!hideArrow ? (
<CurrencyColumn style={{marginRight: 16}}>
<NestedArrowIcon />
</CurrencyColumn>
) : null}

<CurrencyColumn>
<CurrencyImage
img={token.img}
imgSrc={token.imgSrc}
badgeUri={chainImg}
badgeUri={badgeUri}
/>
</CurrencyColumn>

Expand All @@ -181,7 +197,7 @@ export const TokenSelectionRow: React.VFC<TokenSelectionRowProps> = memo(
checked={!!token.selected}
radio={selectionMode === 'single'}
disabled={!!token.disabled}
onPress={() => onToggle?.(token.id)}
onPress={() => onToggle?.(token.currencyAbbreviation)}
/>
</CurrencyColumn>
) : null}
Expand Down Expand Up @@ -210,9 +226,9 @@ const CurrencySelectionRow: React.VFC<CurrencySelectionRowProps> = ({
const {t} = useTranslation();
const {currencyName} = currency;
const onPress = useCallback(
(id: string): void => {
(currencyAbbreviation: string): void => {
haptic(IS_ANDROID ? 'keyboardPress' : 'impactLight');
onToggle?.(id);
onToggle?.(currencyAbbreviation);
},
[onToggle],
);
Expand All @@ -221,7 +237,7 @@ const CurrencySelectionRow: React.VFC<CurrencySelectionRowProps> = ({
<CurrencySelectionRowContainer>
<ChainSelectionRow
currency={currency}
onToggle={onPress}
onToggle={() => onPress(currency.currencyAbbreviation)}
hideCheckbox={hideCheckbox}
selectionMode={selectionMode}
/>
Expand All @@ -237,9 +253,8 @@ const CurrencySelectionRow: React.VFC<CurrencySelectionRowProps> = ({
{tokens.map(token => (
<TokenSelectionRow
key={token.id}
chainImg={currency.img}
token={token}
onToggle={onPress}
onToggle={() => onPress(token.currencyAbbreviation)}
hideCheckbox={hideCheckbox}
selectionMode={selectionMode}
/>
Expand Down
5 changes: 3 additions & 2 deletions src/components/list/GlobalSelectRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ export const AvailableWalletsPill = styled.View`

const GlobalSelectRow = ({item, emit}: Props) => {
const {t} = useTranslation();
const {currencyName, total, img} = item;
const {currencyName, total, img, badgeImg} = item;

return (
<RowContainer activeOpacity={ActiveOpacity} onPress={() => emit(item)}>
<CurrencyImageContainer>
<CurrencyImage img={img} />
<CurrencyImage img={img} badgeUri={badgeImg} />
</CurrencyImageContainer>
<CurrencyColumn>
<H5>{currencyName}</H5>
Expand Down
5 changes: 4 additions & 1 deletion src/components/list/WalletRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ const NestedArrowContainer = styled.View`
export interface WalletRowProps {
id: string;
img: string | ((props: any) => ReactElement);
badgeImg?: string | ((props: any) => ReactElement);
currencyName: string;
currencyAbbreviation: string;
chain: string;
walletName?: string;
cryptoBalance: string;
cryptoLockedBalance?: string;
Expand Down Expand Up @@ -85,6 +87,7 @@ const WalletRow = ({wallet, onPress}: Props) => {
currencyAbbreviation,
walletName,
img,
badgeImg,
cryptoBalance,
fiatBalance,
isToken,
Expand All @@ -104,7 +107,7 @@ const WalletRow = ({wallet, onPress}: Props) => {
</NestedArrowContainer>
)}
<CurrencyImageContainer>
<CurrencyImage img={img} size={45} />
<CurrencyImage img={img} badgeUri={badgeImg} size={45} />
</CurrencyImageContainer>
<CurrencyColumn>
<Row>
Expand Down
1 change: 0 additions & 1 deletion src/components/modal/biometric/BiometricModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ const BiometricModal: React.FC = () => {
onClose?.(true);
})
.catch((error: BiometricError) => {
console.log(error);
if (error.code && TO_HANDLE_ERRORS[error.code]) {
const err = TO_HANDLE_ERRORS[error.code];
dispatch(
Expand Down
Loading

0 comments on commit 29f9623

Please sign in to comment.