-
Notifications
You must be signed in to change notification settings - Fork 131
Update buy/sell flow on mobile #12981
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
42e537f
Update buy/sell flow on mobile
faridsalau 6ed5ce4
Remove md
faridsalau 43d7f83
Comment
faridsalau 88e8a26
Update skeleton
faridsalau 7c2cff0
Make more like web
faridsalau ae56ea1
Use harmony value
faridsalau 3e30b1c
Refactor shared logic
faridsalau 0fbdafe
Comments
faridsalau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
packages/common/src/store/ui/buy-sell/useBuySellFlowLogic.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import { useMemo } from 'react' | ||
|
|
||
| import { useFeatureFlag } from '~/hooks' | ||
| import { buySellMessages as messages } from '~/messages' | ||
| import { FeatureFlags } from '~/services' | ||
|
|
||
| import type { BuySellTab, TokenInfo, TokenPair } from './types' | ||
| import { createFallbackPair } from './utils' | ||
|
|
||
| /** | ||
| * Creates filtered token lists for buy/sell/convert tabs | ||
| */ | ||
| export const useBuySellTokenFilters = ({ | ||
| availableTokens, | ||
| baseTokenSymbol, | ||
| quoteTokenSymbol, | ||
| hasPositiveBalance | ||
| }: { | ||
| availableTokens: TokenInfo[] | ||
| baseTokenSymbol: string | ||
| quoteTokenSymbol: string | ||
| hasPositiveBalance: (tokenAddress: string) => boolean | ||
| }) => { | ||
| const availableInputTokensForSell = useMemo(() => { | ||
| return availableTokens.filter( | ||
| (t) => | ||
| t.symbol !== baseTokenSymbol && | ||
| t.symbol !== 'USDC' && | ||
|
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. is there a way to avoid hardcode
Contributor
Author
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. no, USDC isn't coming from BE so we have to |
||
| hasPositiveBalance(t.address) | ||
| ) | ||
| }, [availableTokens, baseTokenSymbol, hasPositiveBalance]) | ||
|
|
||
| const availableInputTokensForConvert = useMemo(() => { | ||
| return availableTokens.filter( | ||
| (t) => | ||
| t.symbol !== baseTokenSymbol && | ||
| t.symbol !== quoteTokenSymbol && | ||
| hasPositiveBalance(t.address) | ||
| ) | ||
| }, [availableTokens, baseTokenSymbol, quoteTokenSymbol, hasPositiveBalance]) | ||
|
|
||
| const availableOutputTokensForConvert = useMemo(() => { | ||
| return availableTokens.filter((t) => t.symbol !== baseTokenSymbol) | ||
| }, [availableTokens, baseTokenSymbol]) | ||
|
|
||
| return { | ||
| availableInputTokensForSell, | ||
| availableInputTokensForConvert, | ||
| availableOutputTokensForConvert | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Creates a safe token pair, falling back to AUDIO/USDC if needed | ||
| */ | ||
| export const useSafeTokenPair = (currentTokenPair: TokenPair | null) => { | ||
| return useMemo(() => { | ||
| if (currentTokenPair?.baseToken && currentTokenPair?.quoteToken) { | ||
| return currentTokenPair | ||
| } | ||
| return createFallbackPair() | ||
| }, [currentTokenPair]) | ||
| } | ||
|
|
||
| /** | ||
| * Creates the tabs array based on feature flags | ||
| */ | ||
| export const useBuySellTabsArray = () => { | ||
| const { isEnabled: isArtistCoinsEnabled } = useFeatureFlag( | ||
| FeatureFlags.ARTIST_COINS | ||
| ) | ||
|
|
||
| return useMemo(() => { | ||
| const baseTabs = [ | ||
| { key: 'buy' as BuySellTab, text: messages.buy }, | ||
| { key: 'sell' as BuySellTab, text: messages.sell } | ||
| ] | ||
|
|
||
| if (isArtistCoinsEnabled) { | ||
| baseTabs.push({ key: 'convert' as BuySellTab, text: messages.convert }) | ||
| } | ||
|
|
||
| return baseTabs | ||
| }, [isArtistCoinsEnabled]) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 0 additions & 54 deletions
54
packages/mobile/src/components/buy-sell/TokenDropdownSelect.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
where is this hook used?
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.
BuySellFlow