Skip to content

Commit

Permalink
Merge branch 'dev' into stage
Browse files Browse the repository at this point in the history
  • Loading branch information
JavidHaji-zada committed Nov 27, 2023
1 parent bc45c9f commit 494ef47
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 49 deletions.
15 changes: 6 additions & 9 deletions src/components/modular/SingleAsset/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React from 'react';
import { View } from 'react-native';
import { Row, Spacer, Text } from '@components/base';
import { moderateScale, scale, verticalScale } from '@utils/scaling';
import { scale, verticalScale } from '@utils/scaling';
import { COLORS } from '@constants/colors';
import { useAMBPrice, useUSDPrice } from '@hooks';
import { NumberUtils } from '@utils/number';
import { PercentChange } from '@components/composite';
import { Token } from '@models';
import { TokenLogo, TokenLogoProps } from '../TokenLogo';
import { NumberUtils } from '@utils/number';
import { styles } from './styles';

interface SingleAssetProps {
Expand All @@ -25,11 +25,7 @@ export const SingleAsset = (props: SingleAssetProps): JSX.Element => {
<View style={styles.container}>
<Row>
<View style={{ alignSelf: 'center' }}>
<TokenLogo
token={name}
overrideIconVariants={overrideIconVariants}
style={{ width: moderateScale(32), height: moderateScale(32) }}
/>
<TokenLogo token={name} overrideIconVariants={overrideIconVariants} />
</View>
<Spacer horizontal value={scale(8)} />
<View style={styles.item}>
Expand All @@ -46,7 +42,7 @@ export const SingleAsset = (props: SingleAssetProps): JSX.Element => {
fontSize={16}
color={COLORS.neutral800}
>
${NumberUtils.formatNumber(usdPrice, 2)}
${NumberUtils.limitDecimalCount(usdPrice, 2)}
</Text>
</Row>
<Spacer horizontal value={scale(8)} />
Expand All @@ -56,7 +52,8 @@ export const SingleAsset = (props: SingleAssetProps): JSX.Element => {
fontSize={14}
color={COLORS.neutral400}
>
{NumberUtils.formatNumber(balance.ether, 2)} {symbol || 'tokens'}
{NumberUtils.limitDecimalCount(balance.ether, 2)}{' '}
{symbol || 'tokens'}
</Text>
<Text
fontFamily="Inter_400Regular"
Expand Down
11 changes: 2 additions & 9 deletions src/components/modular/TokenLogo/index.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import React from 'react';
import { Image } from 'react-native';
import {
AirBondIcon,
AirdaoBlueIcon,
AirdaoWhiteIcon,
BusdIcon,
EthTokenIcon,
FirepotIcon,
GanymadeIcon,
HeraPoolIcon,
PlutusIcon,
TetherIcon,
UsdcIcon
} from '@components/svg/icons';
import { AirDAODictTypes } from '@crypto/common/AirDAODictTypes';
import { moderateScale } from '@utils/scaling';

export interface TokenLogoProps {
token: string;
Expand Down Expand Up @@ -50,13 +49,7 @@ export const TokenLogo = (props: TokenLogoProps) => {
case 'Hera pool token':
return <HeraPoolIcon scale={scale} />;
case 'Firepot-LP-Token':
return (
<Image
{...props}
style={{ width: moderateScale(96), height: moderateScale(96) }}
source={require('@assets/images/tokens/firepot-lp-token.png')}
/>
);
return <FirepotIcon scale={scale} />;
case 'AirBond':
return <AirBondIcon scale={scale} />;
default:
Expand Down
6 changes: 3 additions & 3 deletions src/components/modular/TransactionItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { COLORS } from '@constants/colors';
import { DownArrowIcon } from '@components/svg/icons';
import { StringUtils } from '@utils/string';
import { useUSDPrice } from '@hooks';
import { NumberUtils } from '@utils/number';
import { AirDAODictTypes } from '@crypto/common/AirDAODictTypes';
import { NumberUtils } from '@utils/number';
import { styles } from './styles';

interface TransactionItemProps {
Expand Down Expand Up @@ -66,7 +66,7 @@ export const TransactionItem = (props: TransactionItemProps): JSX.Element => {
fontFamily="Mersad_600SemiBold"
color={COLORS.neutral900}
>
{NumberUtils.formatNumber(transaction.amount, 2)}{' '}
{NumberUtils.limitDecimalCount(transaction.amount, 2)}{' '}
{transaction.value.symbol}
</Text>
<Spacer value={verticalScale(4)} />
Expand All @@ -76,7 +76,7 @@ export const TransactionItem = (props: TransactionItemProps): JSX.Element => {
fontFamily="Inter_500Medium"
color={COLORS.alphaBlack50}
>
${NumberUtils.formatNumber(usdAmount, 2)}
${NumberUtils.limitDecimalCount(usdAmount, 2)}
</Text>
</View>
</Row>
Expand Down
3 changes: 1 addition & 2 deletions src/components/modular/WalletCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ export const WalletCard = (props: WalletCardProps) => {
fontWeight="800"
fontFamily="Mersad_600SemiBold"
>
{StringUtils.limitNumberInputDecimals(ambBalance.toString(), 2)}{' '}
AMB
{NumberUtils.limitDecimalCount(ambBalance.toString(), 2)} AMB
</Text>
<Spacer value={scale(16)} horizontal />
<View style={styles.usdPriceBg}>
Expand Down
68 changes: 68 additions & 0 deletions src/components/svg/icons/TokenFirepot.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import React from 'react';
import {
ClipPath,
Defs,
G,
LinearGradient,
Mask,
Path,
Stop,
Svg
} from 'react-native-svg';
import { moderateScale } from '@utils/scaling';
import { IconProps } from './Icon.types';

export function FirepotIcon(props: Omit<IconProps, 'color'>) {
const { scale = 1 } = props;
const width = moderateScale(32);
const height = moderateScale(32);
return (
<Svg
width={width * scale}
height={height * scale}
viewBox={`0 0 ${width} ${height}`}
fill="none"
>
<G clipPath="url(#prefix__clip0_1382_130)">
<Mask
id="prefix__a"
maskUnits="userSpaceOnUse"
x={0}
y={0}
width={32}
height={32}
>
<Path d="M32 0H0v32h32V0z" fill="#fff" />
</Mask>
<G mask="url(#prefix__a)">
<Path
d="M16 32c8.867 0 16-7.133 16-16S24.867 0 16 0 0 7.133 0 16s7.133 16 16 16z"
fill="#E3ECFF"
/>
<Path
fillRule="evenodd"
clipRule="evenodd"
d="M10.099 26.622a.277.277 0 01-.387-.09l-.33-.514a.322.322 0 01.064-.417 13.221 13.221 0 002.677-3.004c2.61-4.05 2.61-9.145 0-13.194a13.217 13.217 0 00-2.677-3.004.323.323 0 01-.063-.417l.33-.515a.277.277 0 01.386-.09l14.622 9.466c.816.528.816 1.786 0 2.314L10.1 26.622z"
fill="url(#prefix__paint0_linear_1382_130)"
/>
</G>
</G>
<Defs>
<LinearGradient
id="prefix__paint0_linear_1382_130"
x1={27.201}
y1={16.189}
x2={3.449}
y2={16.189}
gradientUnits="userSpaceOnUse"
>
<Stop stopColor="#3568DD" />
<Stop offset={1} stopColor="#3568DD" stopOpacity={0.66} />
</LinearGradient>
<ClipPath id="prefix__clip0_1382_130">
<Path fill="#fff" d="M0 0h32v32H0z" />
</ClipPath>
</Defs>
</Svg>
);
}
1 change: 1 addition & 0 deletions src/components/svg/icons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export * from './TokenAirdaoBlue';
export * from './TokenAirdaoWhite';
export * from './TokenBusd';
export * from './TokenEth';
export * from './TokenFirepot';
export * from './TokenGanymade';
export * from './TokenHera';
export * from './TokenPlutus';
Expand Down
6 changes: 1 addition & 5 deletions src/components/templates/TransactionDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,7 @@ export const TransactionDetails = (
fontFamily="Inter_600SemiBold"
fontSize={14}
>
{StringUtils.limitNumberInputDecimals(
transaction.fee.toString(),
6
)}{' '}
AMB
{NumberUtils.limitDecimalCount(transaction.fee.toString(), 6)} AMB
</Text>
</Row>
</JustifiedRow>
Expand Down
7 changes: 4 additions & 3 deletions src/screens/SendFunds/SendFunds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { Token } from '@models';
import { TransactionUtils } from '@utils/transaction';
import { DeviceUtils } from '@utils/device';
import { useAccountByAddress } from '@hooks/database';
import { NumberUtils } from '@utils/number';
import { styles } from './styles';

export const SendFunds = () => {
Expand Down Expand Up @@ -118,10 +119,10 @@ export const SendFunds = () => {
}

setAmountInCrypto(
StringUtils.limitNumberInputDecimals(maxSendableBalance.toString(), 3)
NumberUtils.limitDecimalCount(maxSendableBalance.toString(), 3)
);
setAmountInUSD(
StringUtils.limitNumberInputDecimals(
NumberUtils.limitDecimalCount(
CurrencyUtils.toUSD(maxSendableBalance, ambPrice).toString(),
3
)
Expand All @@ -136,7 +137,7 @@ export const SendFunds = () => {
return;
}
let finalValue = StringUtils.formatNumberInput(newValue);
finalValue = StringUtils.limitNumberInputDecimals(finalValue, 3);
finalValue = NumberUtils.limitDecimalCount(finalValue, 3);
if (amountShownInUSD) {
setAmountInUSD(finalValue);
const newUsdAmount = parseFloat(finalValue) || 0;
Expand Down
2 changes: 1 addition & 1 deletion src/screens/Settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const SettingsScreen = () => {
<View style={styles.innerContainer}>
{SETTINGS_MENU_ITEMS.map(renderMenu)}
</View>
{isStage && <Text style={{ margin: 20 }}>Build: 1.1.5.13</Text>}
{isStage && <Text style={{ margin: 20 }}>Build: 1.1.5.14</Text>}
</View>
);
};
22 changes: 21 additions & 1 deletion src/utils/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@ const formatNumber = (amount: number, decimalPlaces = 2): string => {
return formattedString + strAmount.substring(startingIdx + 1);
};

const limitDecimalCount = (
number: string | number,
decimalPlaces: number
): string => {
let str = number.toString();
const parts = str.split('.');
if (str.includes('.') && parts[1] && parts[1].length > decimalPlaces) {
if (parts[1].length > decimalPlaces) {
parts[1] = parts[1].substring(0, decimalPlaces);
str = parts.join('.');
}
}
return str;
};

const addSignToNumber = (num: number): string => {
const shouldAddMinus = num.toString() && num.toString()[0] !== '-';
return (num > 0 ? '+' : shouldAddMinus ? '-' : '') + num;
Expand Down Expand Up @@ -52,4 +67,9 @@ const abbreviateNumber = (num: number): string => {
return newValue;
};

export const NumberUtils = { formatNumber, addSignToNumber, abbreviateNumber };
export const NumberUtils = {
formatNumber,
addSignToNumber,
abbreviateNumber,
limitDecimalCount
};
17 changes: 1 addition & 16 deletions src/utils/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,25 +66,10 @@ function _removeExtraDots(str: string): string {
.join('');
}

const limitNumberInputDecimals = (
str: string,
decimalPlaces: number
): string => {
const parts = str.split('.');
if (str.includes('.') && parts[1] && parts[1].length > decimalPlaces) {
if (parts[1].length > decimalPlaces) {
parts[1] = parts[1].substring(0, decimalPlaces);
str = parts.join('.');
}
}
return str;
};

export const StringUtils = {
formatAddress,
pluralize,
removeNonNumericCharacters,
removeNonAlphabeticCharacters,
formatNumberInput,
limitNumberInputDecimals
formatNumberInput
};

0 comments on commit 494ef47

Please sign in to comment.