Uniswap_interface 코드 분석
2021. 11. 7. 04:07ㆍBlockchain/Project - Coin Swap
수정 중
id or function | conditional, state, variable | function | action |
interface/src/pages/Swap/index.tsx, swap-button | isExpertMode, true | handleSwap() | |
false | setSwapState() | tradeToConfirm: trade, attemptingTxn: false, swapErrorMessage: undefined, showConfirm: true, txHash: undefined, |
|
const handleSwap() | if (!swapCallback) | return | |
if (priceImpact && !confirmPriceImpactWithoutFee(priceImpact)) | return | ||
setSwapState() | attemptingTxn: true, tradeToConfirm, showConfirm, swapErrorMessage: undefined, txHash: undefined |
||
swapCallback() | useSwapCallback() | ||
interface/src/hooks/useSwapCallback.tsx, useSwapCallback() | { account, chainId, library } swapCalls addTransaction { address: recipientAddress } recipient |
useActiveWeb3React() useSwapCallArguments() useTransactionAdder() useENS() recipientAddressOrName === null ? account : recipientAddress |
return useMemo() |
useMemo() | if (!trade || !library || !account || !chainId) | return { state: SwapCallbackState.INVALID, callback: null, error: <Trans>Missing dependencies</Trans> } | |
if (!recipient) | if (recipientAddressOrName !== null) | return { state: SwapCallbackState.INVALID, callback: null, error: <Trans>Invalid recipient</Trans> } | |
else | return { state: SwapCallbackState.LOADING, callback: null, error: null } | ||
else | ... | ||
interface/src/hooks/web3.ts, useActiveWeb3React() | context contextNetwork |
useWeb3React() useWeb3React(NetworkContextName) |
return context.active ? context : contextNetwork |
interface/src/hooks/useSwapCallback.tsx, useSwapCallArguments() | { account, chainId, library } { address: recipientAddress } recipient deadline routerContract argentWalletContract |
useActiveWeb3React() useENS() = recipientAddressOrName === null ? account : recipientAddress useTransactionDeadline() useV2RouterContract() useArgentWalletContract() |
|
interface/src/hooks/useTransactionDeadline.ts, useTransactionDeadline() | { chainId } ttl blockTimestamp |
useActiveWeb3React() useAppSelector() useCurrentBlockTimestamp() |
return useMemo(() => { if (blockTimestamp && chainId && L2_CHAIN_IDS.includes(chainId)) return blockTimestamp.add(L2_DEADLINE_FROM_NOW) if (blockTimestamp && ttl) return blockTimestamp.add(ttl) return undefined }, [blockTimestamp, chainId, ttl]) |
interface/src/hooks/useContracts.ts, useV2RouterContract() | return useContract(V2_ROUTER_ADDRESS, IUniswapV2Router02ABI, true) | ||
interface/src/hooks/useContracts.ts, useContract() | { library, account, chainId } | useActiveWeb3React() | return useMemo(() => { if (!addressOrAddressMap || !ABI || !library || !chainId) return null let address: string | undefined if (typeof addressOrAddressMap === 'string') address = addressOrAddressMap else address = addressOrAddressMap[chainId] if (!address) return null try { return getContract(address, ABI, library, withSignerIfPossible && account ? account : undefined) } catch (error) { console.error('Failed to get contract', error) return null } }, [addressOrAddressMap, ABI, library, chainId, withSignerIfPossible, account]) as T |
interface/src/hooks/useArgentWalletContract.ts, useArgentWalletContract() | { account } isArgentWallet |
useActiveWeb3React() useIsArgentWallet() |
return useContract( isArgentWallet ? account ?? undefined : undefined, ArgentWalletContractABI, true ) as ArgentWalletContract |
ddddddddd | |||
ddddddddddd | |||
interface/src/data/transactions/hooks.tsx, useTransactionAdder() | { chainId, account } dispatch logMonitoringEvent |
useActiveWeb3React() useAppDispatch() useTransactionMonitoringEventCallback() |
return useCallback( (response: TransactionResponse, info: TransactionInfo) => { if (!account) return if (!chainId) return const { hash } = response if (!hash) {throw Error('No transaction hash found.')} dispatch(addTransaction({ hash, from: account, info, chainId })) logMonitoringEvent(info, response) }, [account, chainId, dispatch, logMonitoringEvent] ) |
interface/src/hooks/useENS.ts, useENS() | validated reverseLookup lookup |
isAddress() useENSName() useENSAddress() |
return { loading: reverseLookup.loading || lookup.loading, address: validated ? validated : lookup.address, name: reverseLookup.ENSName ? reverseLookup.ENSName : !validated && lookup.address ? nameOrAddress || null : null, } |
interface/src/components/swap/confirmPriceImpactWithoutFee.tsx, confirmPriceImpactWithoutFee() | if (!priceImpactWithoutFee.lessThan(PRICE_IMPACT_WITHOUT_FEE_CONFIRM_MIN)) | return (window.prompt) | |
else if (!priceImpactWithoutFee.lessThan(ALLOWED_PRICE_IMPACT_HIGH)) | return (window.confirm) | ||
swapCallback() | .then(hash) | setSwapState() | attemptingTxn: false, tradeToConfirm, showConfirm, swapErrorMessage: undefined, txHash: hash, |
.catch(error) | setSwapState() | attemptingTxn: false, tradeToConfirm, showConfirm, swapErrorMessage: error.message, txHash: undefined, |
|
interface/src/components/swap/SwapModalFooter.tsx, confirm-swap-or-send | onConfirm() | ||
-> ConfirmSwapModal.tsx | |||
-> ConfirmSwapModal.tsx, swap-page | handleSwap() | ||
Check List
ReactGA
useMemo
'Blockchain > Project - Coin Swap' 카테고리의 다른 글
211109 미팅 내용 정리 (0) | 2021.11.09 |
---|---|
자료조사 : 탈중앙 금융에서의 유동성 풀(Pools)과 농사(Farms) (0) | 2021.11.07 |
Truffle, Solidity, Node.js, Web3.js 버전 변경 방법 (0) | 2021.11.03 |
자료 조사 : 도커파일(Dockerfile) 개념과 읽는 방법 (0) | 2021.11.03 |
Uniswap Interface 클론 후 도커(Docker)로 빌드 후 실행 방법 (0) | 2021.11.03 |