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

feat: swapper chain flags #8226

Merged
merged 5 commits into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .env.base
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ REACT_APP_FEATURE_DYNAMIC_LP_ASSETS=false
# Fetch read-only assets from various providers (Zapper only for now)
REACT_APP_FEATURE_READ_ONLY_ASSETS=true

# swapper feature flags - other .env files will override these
# Swapper chain-specific flags. Use me if you're working on a swapper which brings first time swapper support for a chain,
# meaning we don't want to enable the selection for said chain in prod just yet
# Or alternatively, if we know that a given chain is very unstable and we may want to disable it in swapper altogether.
woodenfurniture marked this conversation as resolved.
Show resolved Hide resolved
REACT_APP_FEATURE_SWAPPER_SOLANA=false

# Swapper feature flags - other .env files will override these
REACT_APP_FEATURE_CHAINFLIP=false
REACT_APP_FEATURE_CHAINFLIP_DCA=false
REACT_APP_FEATURE_COWSWAP=true
Expand Down
7 changes: 6 additions & 1 deletion .env.dev
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# feature flags
# Swapper chain-specific flags. Use me if you're working on a swapper which brings first time swapper support for a chain,
# meaning we don't want to enable the selection for said chain in prod just yet
# Or alternatively, if we know that a given chain is very unstable and we may want to disable it in swapper altogether.
REACT_APP_FEATURE_SWAPPER_SOLANA=true

# Swapper feature flags
REACT_APP_FEATURE_CHAINFLIP=true
REACT_APP_FEATURE_CHAINFLIP_DCA=false
REACT_APP_FEATURE_PUBLIC_TRADE_ROUTE=true
Expand Down
8 changes: 7 additions & 1 deletion .env.develop
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# feature flags
# Swapper chain-specific flags. Use me if you're working on a swapper which brings first time swapper support for a chain,
# meaning we don't want to enable the selection for said chain in prod just yet
# Or alternatively, if we know that a given chain is very unstable and we may want to disable it in swapper altogether.

REACT_APP_FEATURE_SWAPPER_SOLANA=true

# Swapper feature flags
REACT_APP_FEATURE_LIMIT_ORDERS=true
REACT_APP_FEATURE_CHAINFLIP=true
REACT_APP_FEATURE_CHAINFLIP_DCA=false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ import { useModal } from 'hooks/useModal/useModal'
export type TradeAssetSearchModalProps = TradeAssetSearchProps & {
title?: string
onAssetClick: Required<TradeAssetSearchProps>['onAssetClick']
assetFilterPredicate?: (asset: Asset) => boolean
chainIdFilterPredicate?: (chainId: ChainId) => boolean
assetFilterPredicate: (asset: Asset) => boolean
chainIdFilterPredicate: (chainId: ChainId) => boolean
}

type AssetSearchModalBaseProps = TradeAssetSearchModalProps & {
isOpen: boolean
close: () => void
assetFilterPredicate: (asset: Asset) => boolean
chainIdFilterPredicate: (chainId: ChainId) => boolean
}

export const TradeAssetSearchModalBase: FC<AssetSearchModalBaseProps> = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ type SharedTradeInputBodyProps = {
sellAmountUserCurrency: string | undefined
sellAsset: Asset
sellAccountId: AccountId | undefined
assetFilterPredicate?: (asset: Asset) => boolean
chainIdFilterPredicate?: (chainId: ChainId) => boolean
assetFilterPredicate: (asset: Asset) => boolean
chainIdFilterPredicate: (chainId: ChainId) => boolean
onSwitchAssets: () => void
onChangeIsInputtingFiatSellAmount: (isInputtingFiatSellAmount: boolean) => void
onChangeSellAmountCryptoPrecision: (sellAmountCryptoPrecision: string) => void
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type { ChainId } from '@shapeshiftoss/caip'
import { isLedger } from '@shapeshiftoss/hdwallet-ledger'
import { isArbitrumBridgeTradeQuote } from '@shapeshiftoss/swapper/dist/swappers/ArbitrumBridgeSwapper/getTradeQuote/getTradeQuote'
import type { ThorTradeQuote } from '@shapeshiftoss/swapper/dist/swappers/ThorchainSwapper/types'
import type { Asset } from '@shapeshiftoss/types'
import { KnownChainIds } from '@shapeshiftoss/types'
import { positiveOrZero } from '@shapeshiftoss/utils'
import type { FormEvent } from 'react'
import { useCallback, useEffect, useMemo, useState } from 'react'
Expand All @@ -19,6 +21,7 @@ import { useInputOutputDifferenceDecimalPercentage } from 'components/MultiHopTr
import { TradeInputTab, TradeRoutePaths } from 'components/MultiHopTrade/types'
import { WalletActions } from 'context/WalletProvider/actions'
import { useErrorHandler } from 'hooks/useErrorToast/useErrorToast'
import { useFeatureFlag } from 'hooks/useFeatureFlag/useFeatureFlag'
import { useModal } from 'hooks/useModal/useModal'
import { useWallet } from 'hooks/useWallet/useWallet'
import { fromBaseUnit } from 'lib/math'
Expand Down Expand Up @@ -301,12 +304,33 @@ export const TradeInput = ({ isCompact, tradeInputRef, onChangeTab }: TradeInput
[dispatch],
)

const isSolanaSwapperEnabled = useFeatureFlag('SolanaSwapper')
const assetFilterPredicate = useCallback(
(asset: Asset) => {
if (asset.chainId === KnownChainIds.SolanaMainnet) return isSolanaSwapperEnabled

return true
},
[isSolanaSwapperEnabled],
)

const chainIdFilterPredicate = useCallback(
(chainId: ChainId) => {
if (chainId === KnownChainIds.SolanaMainnet) return isSolanaSwapperEnabled

return true
},
[isSolanaSwapperEnabled],
)

const handleBuyAssetClick = useCallback(() => {
buyAssetSearch.open({
onAssetClick: setBuyAsset,
title: 'trade.tradeTo',
assetFilterPredicate,
chainIdFilterPredicate,
})
}, [buyAssetSearch, setBuyAsset])
}, [assetFilterPredicate, buyAssetSearch, chainIdFilterPredicate, setBuyAsset])

const buyTradeAssetSelect = useMemo(
() => (
Expand All @@ -315,9 +339,10 @@ export const TradeInput = ({ isCompact, tradeInputRef, onChangeTab }: TradeInput
onAssetClick={handleBuyAssetClick}
onAssetChange={setBuyAsset}
onlyConnectedChains={false}
chainIdFilterPredicate={chainIdFilterPredicate}
/>
),
[buyAsset.assetId, handleBuyAssetClick, setBuyAsset],
[buyAsset.assetId, handleBuyAssetClick, setBuyAsset, chainIdFilterPredicate],
)

const bodyContent = useMemo(() => {
Expand All @@ -335,6 +360,8 @@ export const TradeInput = ({ isCompact, tradeInputRef, onChangeTab }: TradeInput
setSellAccountId={setSellAssetAccountId}
onChangeIsInputtingFiatSellAmount={handleIsInputtingFiatSellAmountChange}
onChangeSellAmountCryptoPrecision={handleChangeSellAmountCryptoPrecision}
assetFilterPredicate={assetFilterPredicate}
chainIdFilterPredicate={chainIdFilterPredicate}
>
<TradeAssetInput
// Disable account selection when user set a manual receive address
Expand Down Expand Up @@ -377,6 +404,8 @@ export const TradeInput = ({ isCompact, tradeInputRef, onChangeTab }: TradeInput
sellAsset,
sellAssetAccountId,
translate,
assetFilterPredicate,
chainIdFilterPredicate,
handleChangeSellAmountCryptoPrecision,
handleIsInputtingFiatSellAmountChange,
handleSwitchAssets,
Expand Down
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ const validators = {
REACT_APP_FEATURE_LIMIT_ORDERS: bool({ default: false }),
REACT_APP_ZRX_BASE_URL: url(),
REACT_APP_FEATURE_CHAINFLIP: bool({ default: false }),
REACT_APP_FEATURE_SWAPPER_SOLANA: bool({ default: false }),
REACT_APP_FEATURE_CHAINFLIP_DCA: bool({ default: false }),
REACT_APP_CHAINFLIP_API_KEY: str(),
REACT_APP_CHAINFLIP_API_URL: url(),
Expand Down
2 changes: 2 additions & 0 deletions src/state/slices/preferencesSlice/preferencesSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export type FeatureFlags = {
FoxPageGovernance: boolean
LimitOrders: boolean
Chainflip: boolean
SolanaSwapper: boolean
ChainflipDca: boolean
ThorFreeFees: boolean
}
Expand Down Expand Up @@ -163,6 +164,7 @@ const initialState: Preferences = {
FoxPageGovernance: getConfig().REACT_APP_FEATURE_FOX_PAGE_GOVERNANCE,
LimitOrders: getConfig().REACT_APP_FEATURE_LIMIT_ORDERS,
Chainflip: getConfig().REACT_APP_FEATURE_CHAINFLIP,
SolanaSwapper: getConfig().REACT_APP_FEATURE_SWAPPER_SOLANA,
ChainflipDca: getConfig().REACT_APP_FEATURE_CHAINFLIP_DCA,
ThorFreeFees: getConfig().REACT_APP_FEATURE_THOR_FREE_FEES,
},
Expand Down
1 change: 1 addition & 0 deletions src/test/mocks/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export const mockStore: ReduxState = {
FoxPageGovernance: false,
LimitOrders: false,
Chainflip: false,
SolanaSwapper: false,
ChainflipDca: false,
ThorFreeFees: false,
},
Expand Down