-
-
Notifications
You must be signed in to change notification settings - Fork 316
feat(suite-native): wire approval and revoke screen to trade data #22138
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,34 +1,45 @@ | ||||||
import { memo, useEffect } from 'react'; | ||||||
import { useSelector } from 'react-redux'; | ||||||
|
||||||
import { DexApprovalType, ExchangeTrade } from 'invity-api'; | ||||||
|
||||||
import { | ||||||
TradingRootState, | ||||||
cryptoIdToNetworkSymbolAndContractAddress, | ||||||
selectTradingCoinSymbolByCryptoId, | ||||||
selectTradingExchangeSelectedQuote, | ||||||
selectTradingProviderByNameAndTradeType, | ||||||
} from '@suite-common/trading'; | ||||||
import { isNetworkSymbol } from '@suite-common/wallet-config'; | ||||||
import { TokenSymbol } from '@suite-common/wallet-types'; | ||||||
import { BottomSheetModal, VStack, useBottomSheetModal } from '@suite-native/atoms'; | ||||||
import { CryptoAmountFormatter, TokenAmountFormatter } from '@suite-native/formatters'; | ||||||
import { Translation } from '@suite-native/intl'; | ||||||
|
||||||
import { ExchangeApprovalLimitCard } from './ExchangeApprovalLimitCard'; | ||||||
|
||||||
type ExchangeApprovalLimitSheetProps = { | ||||||
export type ExchangeApprovalLimitSheetProps = { | ||||||
isVisible: boolean; | ||||||
onDismiss: () => void; | ||||||
onApprovalTypeSelect: (type: DexApprovalType) => void; | ||||||
selectedApprovalType: DexApprovalType; | ||||||
quote: ExchangeTrade; | ||||||
}; | ||||||
|
||||||
export const ExchangeApprovalLimitSheet = memo( | ||||||
({ isVisible, onDismiss }: ExchangeApprovalLimitSheetProps) => { | ||||||
const { bottomSheetRef, openModal } = useBottomSheetModal(); | ||||||
({ | ||||||
isVisible, | ||||||
onDismiss, | ||||||
onApprovalTypeSelect, | ||||||
selectedApprovalType, | ||||||
quote, | ||||||
}: ExchangeApprovalLimitSheetProps) => { | ||||||
const { bottomSheetRef, openModal, closeModal } = useBottomSheetModal(); | ||||||
|
||||||
useEffect(() => { | ||||||
if (isVisible) { | ||||||
openModal(); | ||||||
} | ||||||
}, [isVisible, openModal]); | ||||||
useEffect( | ||||||
() => (isVisible ? openModal() : closeModal()), | ||||||
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. This calls openModal when removing from parent, right? Do we want it? Why did the previous version not work? |
||||||
[isVisible, openModal, closeModal], | ||||||
); | ||||||
|
||||||
const quote = useSelector(selectTradingExchangeSelectedQuote); | ||||||
const providerInfo = useSelector((state: TradingRootState) => | ||||||
selectTradingProviderByNameAndTradeType(state, quote?.exchange, 'exchange'), | ||||||
); | ||||||
|
@@ -37,10 +48,6 @@ export const ExchangeApprovalLimitSheet = memo( | |||||
selectTradingCoinSymbolByCryptoId(state, quote?.send), | ||||||
); | ||||||
|
||||||
if (!quote) { | ||||||
return null; | ||||||
} | ||||||
|
||||||
const { symbol, contractAddress } = quote.send | ||||||
? cryptoIdToNetworkSymbolAndContractAddress(quote.send) | ||||||
: {}; | ||||||
|
@@ -49,7 +56,22 @@ export const ExchangeApprovalLimitSheet = memo( | |||||
return null; | ||||||
} | ||||||
|
||||||
const limitAmount = `200.32 ${coinSymbol}`; //TODO | ||||||
const limitAmount = | ||||||
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:
Suggested change
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. I would avoid unnecessary re-renders for this one. Could we use a |
||||||
!!coinSymbol && | ||||||
(isNetworkSymbol(coinSymbol) ? ( | ||||||
<CryptoAmountFormatter | ||||||
value={quote.sendStringAmount ?? '0'} | ||||||
symbol={coinSymbol} | ||||||
isBalance={false} | ||||||
variant="callout" | ||||||
/> | ||||||
) : ( | ||||||
<TokenAmountFormatter | ||||||
value={quote.sendStringAmount ?? '0'} | ||||||
tokenSymbol={coinSymbol as TokenSymbol} | ||||||
variant="callout" | ||||||
/> | ||||||
)); | ||||||
|
||||||
return ( | ||||||
<BottomSheetModal | ||||||
|
@@ -74,9 +96,9 @@ export const ExchangeApprovalLimitSheet = memo( | |||||
} | ||||||
symbol={symbol} | ||||||
contractAddress={contractAddress} | ||||||
isChecked={true} | ||||||
isChecked={selectedApprovalType === 'INFINITE'} | ||||||
onChange={() => { | ||||||
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
Suggested change
|
||||||
// TODO | ||||||
onApprovalTypeSelect('INFINITE'); | ||||||
}} | ||||||
/> | ||||||
|
||||||
|
@@ -90,9 +112,9 @@ export const ExchangeApprovalLimitSheet = memo( | |||||
} | ||||||
symbol={symbol} | ||||||
contractAddress={contractAddress} | ||||||
isChecked={false} | ||||||
isChecked={selectedApprovalType === 'MINIMAL'} | ||||||
onChange={() => { | ||||||
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
Suggested change
|
||||||
// TODO | ||||||
onApprovalTypeSelect('MINIMAL'); | ||||||
}} | ||||||
/> | ||||||
</VStack> | ||||||
|
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.
What about moving
useBottomSheetModal
one level up instead of usingisVisible
? It feels redundant.. maybe we could change the logic directly in useBottomSheetControls What do you think?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.
Then you could remove the the
useEffect
logic below as well