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

[SWAPS V2]: Adjust asset types + utils to match BX #5538

Merged
merged 9 commits into from
Mar 21, 2024
2 changes: 1 addition & 1 deletion src/__swaps__/screens/Swap/components/CoinRowButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Box, TextIcon, useColorMode, useForegroundColor } from '@/design-system
import { TextWeight } from '@/design-system/components/Text/Text';
import { TextSize } from '@/design-system/typography/typeHierarchy';
import { LIGHT_SEPARATOR_COLOR, SEPARATOR_COLOR, THICK_BORDER_WIDTH } from '../constants';
import { opacity } from '../utils';
import { opacity } from '../utils/swaps';

export const CoinRowButton = ({
icon,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { Box, Inline, Text, TextIcon, useColorMode, useForegroundColor } from '@/design-system';
import { LIGHT_SEPARATOR_COLOR, SEPARATOR_COLOR, THICK_BORDER_WIDTH } from '../constants';
import { opacity } from '../utils';
import { opacity } from '../utils/swaps';
import { ButtonPressAnimation } from '@/components/animations';
import Animated from 'react-native-reanimated';
import { useSwapContext } from '../providers/swap-provider';
Expand Down
2 changes: 1 addition & 1 deletion src/__swaps__/screens/Swap/components/FlipButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { AnimatedSpinner, spinnerExitConfig } from '@/__swaps__/components/anima
import { Bleed, Box, IconContainer, Text, globalColors, useColorMode } from '@/design-system';
import { colors } from '@/styles';
import { SEPARATOR_COLOR, THICK_BORDER_WIDTH } from '../constants';
import { opacity } from '../utils';
import { opacity } from '../utils/swaps';
import { IS_ANDROID, IS_IOS } from '@/env';
import { AnimatedBlurView } from './AnimatedBlurView';
import { useSwapContext } from '../providers/swap-provider';
Expand Down
2 changes: 1 addition & 1 deletion src/__swaps__/screens/Swap/components/SearchInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ButtonPressAnimation } from '@/components/animations';
import { Input } from '@/components/inputs';
import { Bleed, Box, Column, Columns, Text, useColorMode, useForegroundColor } from '@/design-system';
import { LIGHT_SEPARATOR_COLOR, SEPARATOR_COLOR, THICK_BORDER_WIDTH } from '../constants';
import { opacity } from '../utils';
import { opacity } from '../utils/swaps';

export const SearchInput = ({
color,
Expand Down
2 changes: 1 addition & 1 deletion src/__swaps__/screens/Swap/components/SwapBackground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useColorMode, Box } from '@/design-system';
import LinearGradient from 'react-native-linear-gradient';
import { useDimensions } from '@/hooks';
import { ETH_COLOR, ETH_COLOR_DARK } from '../constants';
import { getTintedBackgroundColor } from '../utils';
import { getTintedBackgroundColor } from '../utils/swaps';
import { IS_ANDROID } from '@/env';
import { ScreenCornerRadius } from 'react-native-screen-corner-radius';
import { navbarHeight } from '@/components/navbar/Navbar';
Expand Down
2 changes: 1 addition & 1 deletion src/__swaps__/screens/Swap/components/SwapNavbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { safeAreaInsetValues } from '@/utils';
import { ETH_COLOR, ETH_COLOR_DARK, THICK_BORDER_WIDTH } from '../constants';
import { OUTPUT_COLOR } from '../dummyValues';

import { getHighContrastColor, opacity } from '../utils';
import { getHighContrastColor, opacity } from '../utils/swaps';
import { IS_ANDROID, IS_IOS } from '@/env';
import { useSwapContext } from '../providers/swap-provider';

Expand Down
2 changes: 1 addition & 1 deletion src/__swaps__/screens/Swap/components/SwapNumberPad.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Animated, {
} from 'react-native-reanimated';

import { Box, Columns, HitSlop, Separator, Text, useColorMode, useForegroundColor } from '@/design-system';
import { stripCommas } from '../utils';
import { stripCommas } from '../utils/swaps';
import {
CUSTOM_KEYBOARD_HEIGHT,
LIGHT_SEPARATOR_COLOR,
Expand Down
2 changes: 1 addition & 1 deletion src/__swaps__/screens/Swap/components/SwapSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
snappySpringConfig,
springConfig,
} from '../constants';
import { clamp, opacity } from '../utils';
import { clamp, opacity } from '../utils/swaps';
import { useSwapContext } from '../providers/swap-provider';
import { SwapCoinIcon } from './SwapCoinIcon';
import { INPUT_ADDRESS, INPUT_NETWORK, INPUT_SYMBOL } from '../dummyValues';
Expand Down
2 changes: 1 addition & 1 deletion src/__swaps__/screens/Swap/components/TokenList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useTheme } from '@/theme';
import { SwapCoinIcon } from './SwapCoinIcon';
import { EXPANDED_INPUT_HEIGHT, FOCUSED_INPUT_HEIGHT } from '../constants';
import { DAI_ADDRESS, ETH_ADDRESS, USDC_ADDRESS } from '../dummyValues';
import { opacity } from '../utils';
import { opacity } from '../utils/swaps';
import { CoinRow } from './CoinRow';
import { SearchInput } from './SearchInput';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { safeAreaInsetValues } from '@/utils';
import { SwapActionButton } from '../../components/SwapActionButton';
import { GasButton } from '../../components/GasButton';
import { LIGHT_SEPARATOR_COLOR, SEPARATOR_COLOR, THICK_BORDER_WIDTH } from '../../constants';
import { opacity } from '../../utils';
import { opacity } from '../../utils/swaps';
import { IS_ANDROID } from '@/env';
import { useSwapContext } from '../../providers/swap-provider';

Expand Down
2 changes: 1 addition & 1 deletion src/__swaps__/screens/Swap/hooks/useSwapInputStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
fadeConfig,
springConfig,
} from '../constants';
import { opacity } from '../utils';
import { opacity } from '../utils/swaps';

export const useSwapInputStyles = ({
bottomInput,
Expand Down
4 changes: 2 additions & 2 deletions src/__swaps__/screens/Swap/hooks/useSwapInputsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { useDebouncedCallback } from 'use-debounce';

import { SCRUBBER_WIDTH, SLIDER_WIDTH, snappySpringConfig } from '../constants';
import { IS_INPUT_STABLECOIN, IS_OUTPUT_STABLECOIN, SWAP_FEE } from '../dummyValues';
import { inputKeys, inputMethods } from '../types';
import { inputKeys, inputMethods } from '../types/swap';
import {
addCommasToNumber,
clamp,
Expand All @@ -22,7 +22,7 @@ import {
niceIncrementFormatter,
trimTrailingZeros,
valueBasedDecimalFormatter,
} from '../utils';
} from '../utils/swaps';

export function useSwapInputsController({
focusedInput,
Expand Down
4 changes: 2 additions & 2 deletions src/__swaps__/screens/Swap/hooks/useSwapTextStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import {
sliderConfig,
slowFadeConfig,
} from '../constants';
import { inputKeys, inputMethods } from '../types';
import { opacity } from '../utils';
import { inputKeys, inputMethods } from '../types/swap';
import { opacity } from '../utils/swaps';

export function useSwapTextStyles({
bottomColor,
Expand Down
2 changes: 1 addition & 1 deletion src/__swaps__/screens/Swap/providers/swap-provider.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { createContext, useContext, ReactNode, SetStateAction, Dispatch, useState } from 'react';
import { SharedValue, useAnimatedStyle, useDerivedValue, useSharedValue } from 'react-native-reanimated';
import { inputKeys } from '../types';
import { inputKeys } from '../types/swap';
import { INITIAL_SLIDER_POSITION, SLIDER_COLLAPSED_HEIGHT, SLIDER_HEIGHT, SLIDER_WIDTH, ETH_COLOR_DARK, ETH_COLOR } from '../constants';
import { INPUT_ASSET_BALANCE, INPUT_ASSET_USD_PRICE, OUTPUT_ASSET_USD_PRICE, OUTPUT_COLOR } from '../dummyValues';
import { useColorMode } from '@/design-system';
Expand Down
177 changes: 177 additions & 0 deletions src/__swaps__/screens/Swap/types/assets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
import { Address } from 'viem';

import { ChainId, ChainName } from '@/__swaps__/screens/Swap/types/chains';

import { ETH_ADDRESS } from '@/references';

import { SearchAsset } from './search';

export type AddressOrEth = Address | typeof ETH_ADDRESS;

export interface ParsedAsset {
address: AddressOrEth;
chainId: ChainId;
chainName: ChainName;
colors?: {
primary?: string;
fallback?: string;
shadow?: string;
};
isNativeAsset: boolean;
name: string;
native: {
price?: {
change: string;
amount: number;
display: string;
};
};
mainnetAddress?: AddressOrEth;
price?: ZerionAssetPrice;
symbol: string;
uniqueId: UniqueId;
decimals: number;
icon_url?: string;
type?: AssetType;
smallBalance?: boolean;
standard?: 'erc-721' | 'erc-1155';
networks?: AssetApiResponse['networks'];
bridging?: {
isBridgeable: boolean;
networks: { [id in ChainId]?: { bridgeable: boolean } };
};
}

export interface ParsedUserAsset extends ParsedAsset {
balance: {
amount: string;
display: string;
};
native: {
balance: {
amount: string;
display: string;
};
price?: {
change: string;
amount: number;
display: string;
};
};
}

export type SearchAssetWithPrice = SearchAsset & ParsedAsset;
export type ParsedSearchAsset = SearchAsset & ParsedUserAsset;

export type ParsedAssetsDict = Record<UniqueId, ParsedUserAsset>;

export type ParsedAssetsDictByChain = Record<ChainId | number, ParsedAssetsDict>;

export interface ZerionAssetPrice {
value: number;
relative_change_24h?: number;
}

export type AssetApiResponse = {
asset_code: AddressOrEth;
decimals: number;
icon_url: string;
name: string;
chain_id?: number;
price?: {
value: number;
changed_at: number;
relative_change_24h: number;
};
symbol: string;
colors?: { primary?: string; fallback?: string; shadow?: string };
network?: ChainName;
networks?: {
[chainId in ChainId]?: {
address: chainId extends ChainId.mainnet ? AddressOrEth : Address;
decimals: number;
};
};
type?: AssetType;
interface?: 'erc-721' | 'erc-1155';
};

type AssetType = ProtocolType | 'nft';

export interface ZerionAsset {
asset_code: AddressOrEth;
colors?: {
primary: string;
fallback: string;
};
implementations?: Record<string, { address: Address | null; decimals: number }>;
mainnet_address?: AddressOrEth;
name: string;
symbol: string;
decimals: number;
type?: AssetType;
icon_url?: string;
is_displayable?: boolean;
is_verified?: boolean;
price?: ZerionAssetPrice;
network?: ChainName;
bridging: {
bridgeable: boolean;
networks: { [id in ChainId]?: { bridgeable: boolean } };
};
}

// protocols https://github.com/rainbow-me/go-utils-lib/blob/master/pkg/enums/token_type.go#L44
export type ProtocolType =
| 'aave-v2'
| 'balancer'
| 'curve'
| 'compound'
| 'compound-v3'
| 'maker'
| 'one-inch'
| 'piedao-pool'
| 'yearn'
| 'yearn-v2'
| 'uniswap-v2'
| 'aave-v3'
| 'harvest'
| 'lido'
| 'uniswap-v3'
| 'convex'
| 'convex-frax'
| 'pancake-swap'
| 'balancer-v2'
| 'frax'
| 'gmx'
| 'aura'
| 'pickle'
| 'yearn-v3'
| 'venus'
| 'sushiswap';

export type AssetMetadata = {
circulatingSupply: number;
colors?: { primary: string; fallback?: string; shadow?: string };
decimals: number;
description: string;
fullyDilutedValuation: number;
iconUrl: string;
marketCap: number;
name: string;
networks?: {
[chainId in ChainId]?: {
address: chainId extends ChainId.mainnet ? AddressOrEth : Address;
decimals: number;
};
};
price: {
value: number;
relativeChange24h: number;
};
symbol: string;
totalSupply: number;
volume1d: number;
};

export type UniqueId = `${Address}_${ChainId}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getting war flashbacks here, kind of a nbd if contained to swaps but testy about having too patterns here

Loading
Loading