diff --git a/src/__swaps__/screens/Swap/hooks/useSwapInputsController.ts b/src/__swaps__/screens/Swap/hooks/useSwapInputsController.ts index 456144d6a66..ee11d19db47 100644 --- a/src/__swaps__/screens/Swap/hooks/useSwapInputsController.ts +++ b/src/__swaps__/screens/Swap/hooks/useSwapInputsController.ts @@ -914,7 +914,9 @@ export function useSwapInputsController({ const decimalPlaces = isNativeInputMethod ? internalSelectedInputAsset.value?.decimals : internalSelectedOutputAsset.value?.decimals; - const amount = toFixedWorklet(divWorklet(current.values[inputMethodValue], nativePrice), decimalPlaces || 18); + + const decimals = typeof decimalPlaces === 'number' ? decimalPlaces : 18; + const amount = toFixedWorklet(divWorklet(current.values[inputMethodValue], nativePrice), decimals); const amountKey = isNativeInputMethod ? 'inputAmount' : 'outputAmount'; inputValues.modify(values => { diff --git a/src/components/coin-row/FastTransactionCoinRow.tsx b/src/components/coin-row/FastTransactionCoinRow.tsx index 9d1758037d0..588255a4409 100644 --- a/src/components/coin-row/FastTransactionCoinRow.tsx +++ b/src/components/coin-row/FastTransactionCoinRow.tsx @@ -54,8 +54,11 @@ const swapTypeValues = (changes: RainbowTransaction['changes'], status: RainbowT // NOTE: For pending txns let's use the change values instead of // the transaction balance change since that hasn't happened yet if (status === TransactionStatus.pending) { - const valueOut = `${handleSignificantDecimals(convertRawAmountToDecimalFormat(tokenOut?.value?.toString() || '0', tokenOut?.asset.decimals || 18), tokenOut?.asset.decimals || 18)} ${tokenOut?.asset.symbol}`; - const valueIn = `+${handleSignificantDecimals(convertRawAmountToDecimalFormat(tokenIn?.value?.toString() || '0', tokenIn?.asset.decimals || 18), tokenIn?.asset.decimals || 18)} ${tokenIn?.asset.symbol}`; + const decimalsOut = typeof tokenOut?.asset.decimals === 'number' ? tokenOut.asset.decimals : 18; + const decimalsIn = typeof tokenIn?.asset.decimals === 'number' ? tokenIn.asset.decimals : 18; + + const valueOut = `${handleSignificantDecimals(convertRawAmountToDecimalFormat(tokenOut?.value?.toString() || '0', decimalsOut), decimalsOut)} ${tokenOut?.asset.symbol}`; + const valueIn = `+${handleSignificantDecimals(convertRawAmountToDecimalFormat(tokenIn?.value?.toString() || '0', decimalsIn), decimalsIn)} ${tokenIn?.asset.symbol}`; return [valueOut, valueIn]; } diff --git a/src/components/gas/GasSpeedButton.tsx b/src/components/gas/GasSpeedButton.tsx index 48011d8980f..80176d8ab14 100644 --- a/src/components/gas/GasSpeedButton.tsx +++ b/src/components/gas/GasSpeedButton.tsx @@ -172,7 +172,7 @@ const GasSpeedButton = ({ }: GasSpeedButtonProps) => { const { colors } = useTheme(); const { navigate, goBack } = useNavigation(); - const { nativeCurrencySymbol, nativeCurrency } = useAccountSettings(); + const { nativeCurrency } = useAccountSettings(); const rawColorForAsset = useColorForAsset(asset || {}, fallbackColor, false, true); const { gasFeeParamsBySpeed, updateGasFeeOption, selectedGasFee, selectedGasFeeOption, currentBlockParams } = useGas(); diff --git a/src/helpers/utilities.ts b/src/helpers/utilities.ts index 0227ef6c400..ea543581048 100644 --- a/src/helpers/utilities.ts +++ b/src/helpers/utilities.ts @@ -299,7 +299,7 @@ export const convertAmountToBalanceDisplayWorklet = ( buffer?: number ) => { 'worklet'; - const decimals = asset?.decimals ?? 18; + const decimals = typeof asset?.decimals === 'number' ? asset.decimals : 18; const display = handleSignificantDecimalsWorklet(value, decimals, buffer); return `${display} ${asset?.symbol || ''}`; }; diff --git a/src/parsers/transactions.ts b/src/parsers/transactions.ts index fa022ff65cc..013c3c82865 100644 --- a/src/parsers/transactions.ts +++ b/src/parsers/transactions.ts @@ -87,7 +87,8 @@ export const parseTransaction = async ( const nativeAsset = changes.find(change => change?.asset.isNativeAsset); const nativeAssetPrice = nativeAsset?.price?.toString() || '0'; - const value = toFixedDecimals(nativeAsset?.value || '', nativeAsset?.asset?.decimals || 18); + const decimals = typeof nativeAsset?.asset?.decimals === 'number' ? nativeAsset.asset.decimals : 18; + const value = toFixedDecimals(nativeAsset?.value || '', decimals); // this is probably wrong, need to revisit const native = convertAmountAndPriceToNativeDisplay(value, nativeAssetPrice, nativeCurrency); diff --git a/src/resources/assets/assets.ts b/src/resources/assets/assets.ts index 860322c7fb5..f8c9eb9abfb 100644 --- a/src/resources/assets/assets.ts +++ b/src/resources/assets/assets.ts @@ -1,6 +1,5 @@ import lang from 'i18n-js'; import isEmpty from 'lodash/isEmpty'; -import { MMKV } from 'react-native-mmkv'; import { NativeCurrencyKey, ParsedAddressAsset } from '@/entities'; import { isNativeAsset } from '@/handlers/assets'; import { convertRawAmountToBalance } from '@/helpers/utilities'; diff --git a/src/resources/assets/hardhatAssets.ts b/src/resources/assets/hardhatAssets.ts index 8945031038c..a559414041c 100644 --- a/src/resources/assets/hardhatAssets.ts +++ b/src/resources/assets/hardhatAssets.ts @@ -112,7 +112,7 @@ export const fetchHardhatBalancesByChainId = async ( implementations: chainAsset.asset.implementations || {}, name: chainAsset.asset.name || 'Unknown Token', symbol: chainAsset.asset.symbol || 'UNKNOWN', - decimals: chainAsset.asset.decimals || 18, + decimals: typeof chainAsset.asset.decimals === 'number' ? chainAsset.asset.decimals : 18, icon_url: chainAsset.asset.icon_url || '', price: chainAsset.asset.price || { value: 0, relative_change_24h: 0 }, }; diff --git a/src/resources/defi/utils.ts b/src/resources/defi/utils.ts index 2765a51bf6c..87f570f8a93 100644 --- a/src/resources/defi/utils.ts +++ b/src/resources/defi/utils.ts @@ -24,12 +24,8 @@ export const parsePosition = (position: Position, currency: NativeCurrencyKey): return { ...deposit, underlying: deposit.underlying?.map(underlying => { - const nativeDisplay = convertRawAmountToNativeDisplay( - underlying.quantity, - underlying.asset.decimals, - underlying.asset.price?.value!, - currency - ); + const decimals = typeof underlying.asset.decimals === 'number' ? underlying.asset.decimals : 18; + const nativeDisplay = convertRawAmountToNativeDisplay(underlying.quantity, decimals, underlying.asset.price?.value!, currency); if (deposit.omit_from_total) { totalLocked = add(totalLocked, nativeDisplay.amount); @@ -50,12 +46,8 @@ export const parsePosition = (position: Position, currency: NativeCurrencyKey): return { ...borrow, underlying: borrow.underlying.map(underlying => { - const nativeDisplay = convertRawAmountToNativeDisplay( - underlying.quantity, - underlying.asset.decimals, - underlying.asset.price?.value!, - currency - ); + const decimals = typeof underlying.asset.decimals === 'number' ? underlying.asset.decimals : 18; + const nativeDisplay = convertRawAmountToNativeDisplay(underlying.quantity, decimals, underlying.asset.price?.value!, currency); if (borrow.omit_from_total) { totalLocked = subtract(totalLocked, nativeDisplay.amount); @@ -73,7 +65,8 @@ export const parsePosition = (position: Position, currency: NativeCurrencyKey): let totalClaimables = '0'; const parsedClaimables = position.claimables?.map((claim: Claimable): RainbowClaimable => { - const nativeDisplay = convertRawAmountToNativeDisplay(claim.quantity, claim.asset.decimals, claim.asset.price?.value!, currency); + const decimals = typeof claim.asset.decimals === 'number' ? claim.asset.decimals : 18; + const nativeDisplay = convertRawAmountToNativeDisplay(claim.quantity, decimals, claim.asset.price?.value!, currency); if (claim.omit_from_total) { totalLocked = add(totalLocked, nativeDisplay.amount); diff --git a/src/screens/SendSheet.tsx b/src/screens/SendSheet.tsx index 65a58113525..eca3f922fa2 100644 --- a/src/screens/SendSheet.tsx +++ b/src/screens/SendSheet.tsx @@ -325,7 +325,7 @@ export default function SendSheet() { let _assetAmount = ''; if (_nativeAmount.length) { const priceUnit = !isUniqueAsset ? selected?.price?.value ?? 0 : 0; - const decimals = !isUniqueAsset ? selected?.decimals ?? 18 : 0; + const decimals = !isUniqueAsset ? (typeof selected?.decimals === 'number' ? selected.decimals : 18) : 0; const convertedAssetAmount = convertAmountFromNativeValue(_nativeAmount, priceUnit, decimals); _assetAmount = formatInputDecimals(convertedAssetAmount, _nativeAmount); } diff --git a/src/screens/mints/MintSheet.tsx b/src/screens/mints/MintSheet.tsx index 953b0b1c539..5060821490e 100644 --- a/src/screens/mints/MintSheet.tsx +++ b/src/screens/mints/MintSheet.tsx @@ -159,15 +159,20 @@ const MintSheet = () => { // if there is no max mint info, we fallback to 1 to be safe const maxMintsPerWallet = Number(mintCollection.publicMintInfo?.maxMintsPerWallet); + const decimals = + typeof mintCollection.publicMintInfo?.price?.currency?.decimals === 'number' + ? mintCollection.publicMintInfo?.price?.currency?.decimals + : 18; + const price = convertRawAmountToBalance(mintCollection.publicMintInfo?.price?.amount?.raw || pricePerMint || '0', { - decimals: mintCollection.publicMintInfo?.price?.currency?.decimals || 18, + decimals, symbol: mintCollection.publicMintInfo?.price?.currency?.symbol || 'ETH', }); // case where mint isnt eth? prob not with our current entrypoints const mintPriceAmount = multiply(price.amount, quantity); const mintPriceDisplay = convertAmountToBalanceDisplay(multiply(price.amount, quantity), { - decimals: mintCollection.publicMintInfo?.price?.currency?.decimals || 18, + decimals, symbol: mintCollection.publicMintInfo?.price?.currency?.symbol || 'ETH', }); diff --git a/src/screens/transaction-details/components/TransactionMasthead.tsx b/src/screens/transaction-details/components/TransactionMasthead.tsx index 0c8a450564c..f431fd0e3ea 100644 --- a/src/screens/transaction-details/components/TransactionMasthead.tsx +++ b/src/screens/transaction-details/components/TransactionMasthead.tsx @@ -289,12 +289,13 @@ export default function TransactionMasthead({ transaction }: { transaction: Rain // NOTE: For pending transactions let's use the change value // since the balance hasn't been updated yet. if (isPendingSwap) { - const inAssetValueDisplay = `${handleSignificantDecimals(convertRawAmountToDecimalFormat(change?.value?.toString() || '0', change?.asset.decimals || 18), change?.asset.decimals || 18)} ${change?.asset.symbol}`; + const decimals = typeof change?.asset.decimals === 'number' ? change?.asset.decimals : 18; + const inAssetValueDisplay = `${handleSignificantDecimals(convertRawAmountToDecimalFormat(change?.value?.toString() || '0', decimals), decimals)} ${change?.asset.symbol}`; return { inAssetValueDisplay, inAssetNativeDisplay: change?.asset.price?.value ? convertAmountAndPriceToNativeDisplay( - convertRawAmountToDecimalFormat(change?.value?.toString() || '0', change?.asset.decimals || 18), + convertRawAmountToDecimalFormat(change?.value?.toString() || '0', decimals), change?.asset.price?.value || '0', nativeCurrency )?.display @@ -322,12 +323,13 @@ export default function TransactionMasthead({ transaction }: { transaction: Rain // NOTE: For pending transactions let's use the change value // since the balance hasn't been updated yet. if (isPendingSwap) { - const inAssetValueDisplay = `${handleSignificantDecimals(convertRawAmountToDecimalFormat(change?.value?.toString() || '0', change?.asset.decimals || 18), change?.asset.decimals || 18)} ${change?.asset.symbol}`; + const decimals = typeof change?.asset.decimals === 'number' ? change?.asset.decimals : 18; + const inAssetValueDisplay = `${handleSignificantDecimals(convertRawAmountToDecimalFormat(change?.value?.toString() || '0', decimals), decimals)} ${change?.asset.symbol}`; return { inAssetValueDisplay, inAssetNativeDisplay: change?.asset.price?.value ? convertAmountAndPriceToNativeDisplay( - convertRawAmountToDecimalFormat(change?.value?.toString() || '0', change?.asset.decimals || 18), + convertRawAmountToDecimalFormat(change?.value?.toString() || '0', decimals), change?.asset.price?.value || '0', nativeCurrency )?.display