Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 134
Update swap flows for artist coins#12643
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
4149fc0de07bf137824b53784e9e5e4fa095fb4f193afca40b41e510855a5c294a569bf671c1014eb72cb0d8e919921d2d43fed7cFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import { useMemo } from 'react' | ||
| import { UserCoin } from '~/api' | ||
| import { useFeatureFlag } from '~/hooks' | ||
| import { FeatureFlags } from '~/services' | ||
| export type CoinPairItem = UserCoin | 'find-more' | ||
| /** | ||
| * Groups coins into pairs for 2-column layout rendering. | ||
| * Filters out USDC coins and optionally pairs remaining coins with FindMoreCoins component | ||
| * based on the ARTIST_COINS feature flag. | ||
| * | ||
| * @param coins Array of user coins | ||
| * @returns Array of coin pairs, where each pair contains 1-2 items | ||
| */ | ||
| export const useGroupCoinPairs = (coins?: UserCoin[]) => { | ||
| const { isEnabled: isArtistCoinsEnabled } = useFeatureFlag( | ||
| FeatureFlags.ARTIST_COINS | ||
| ) | ||
| return useMemo(() => { | ||
| if (!coins) return [] | ||
| // Filter out USDC coins | ||
| const filteredCoins = coins.filter((coin) => coin.ticker !== 'USDC') | ||
| // Group coins into pairs for row rendering | ||
| const coinPairs: CoinPairItem[][] = [] | ||
| for (let i = 0; i < filteredCoins.length; i += 2) { | ||
| const pair: CoinPairItem[] = [filteredCoins[i]] | ||
| if (i + 1 < filteredCoins.length) { | ||
| pair.push(filteredCoins[i + 1]) | ||
| } else if (isArtistCoinsEnabled) { | ||
| // If odd number of coins and artist coins enabled, pair the last one with FindMoreCoins | ||
| pair.push('find-more') | ||
| } | ||
| coinPairs.push(pair) | ||
| } | ||
| // If even number of coins and artist coins enabled, FindMoreCoins gets its own row | ||
| if (filteredCoins.length % 2 === 0 && isArtistCoinsEnabled) { | ||
| coinPairs.push(['find-more']) | ||
| } | ||
| return coinPairs | ||
| }, [coins, isArtistCoinsEnabled]) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -70,7 +70,7 @@ export const SwapTab = ({ | ||
| availableOutputTokens, | ||
| onInputTokenChange, | ||
| onOutputTokenChange, | ||
| showExchangeRate = false | ||
| showExchangeRate = true | ||
| }: SwapTabProps) => { | ||
| const { | ||
| formik, | ||
| @@ -80,6 +80,7 @@ export const SwapTab = ({ | ||
| isBalanceLoading, | ||
| availableBalance, | ||
| currentExchangeRate, | ||
| displayExchangeRate, | ||
| handleInputAmountChange, | ||
| handleMaxClick | ||
| } = useTokenSwapForm({ | ||
| @@ -95,10 +96,16 @@ export const SwapTab = ({ | ||
| // Track if an exchange rate has ever been successfully fetched | ||
| const hasRateEverBeenFetched = useRef(false) | ||
| const hasDisplayRateEverBeenFetched = useRef(false) | ||
| if (currentExchangeRate !== null) { | ||
| hasRateEverBeenFetched.current = true | ||
| } | ||
| if (displayExchangeRate !== null) { | ||
| hasDisplayRateEverBeenFetched.current = true | ||
| } | ||
| // Show initial loading state if balance is loading, | ||
| // OR if exchange rate is loading AND we've never fetched a rate before. | ||
| const isInitialLoading = | ||
| @@ -161,20 +168,22 @@ export const SwapTab = ({ | ||
| /> | ||
| {/* Show exchange rate for convert flow */} | ||
| {showExchangeRate && currentExchangeRate && ( | ||
| <Flex p='l' justifyContent='flex-start'> | ||
| <Text variant='body' size='s' color='subdued'> | ||
| {messages.exchangeRateLabel} | ||
| </Text> | ||
| <Text variant='body' size='s' color='default'> | ||
| {messages.exchangeRateValue( | ||
| inputToken.symbol, | ||
| outputToken.symbol, | ||
| currentExchangeRate | ||
| )} | ||
| </Text> | ||
| </Flex> | ||
| )} | ||
| {showExchangeRate && | ||
| currentExchangeRate && | ||
| displayExchangeRate && ( | ||
| <Flex p='l' justifyContent='flex-start'> | ||
| <Text variant='body' size='s' color='subdued'> | ||
| {messages.exchangeRateLabel} | ||
| </Text> | ||
| <Text variant='body' size='s' color='default'> | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: think | ||
| {messages.exchangeRateValue( | ||
| inputToken.symbol, | ||
| outputToken.symbol, | ||
| displayExchangeRate | ||
| )} | ||
| </Text> | ||
| </Flex> | ||
| )} | ||
| </> | ||
| )} | ||
| </Flex> | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
funky but makes sense