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(wallet): Enable Meld Buy on Android #27252

Merged
merged 2 commits into from
Jan 23, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -430,11 +430,12 @@ IN_PROC_BROWSER_TEST_F(AndroidPageAppearingBrowserTest,
}
}

IN_PROC_BROWSER_TEST_F(AndroidPageAppearingBrowserTest, TestBuyPageAppearing) {
IN_PROC_BROWSER_TEST_F(AndroidPageAppearingBrowserTest, TestMeldPageAppearing) {
const GURL expected_url = GURL("brave://wallet/crypto/fund-wallet");
for (auto scheme : GetWebUISchemes()) {
GURL url = GURL(base::StrCat({scheme, "wallet/crypto/fund-wallet"}));
const std::vector<std::string> ignore_patterns = {
"An internal error has occurred",
"TypeError: Cannot read properties of undefined (reading 'forEach')",
"ReactDOM.render is no longer supported in React 18"};
VerifyPage(url, expected_url, ignore_patterns);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,23 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// you can obtain one at https://mozilla.org/MPL/2.0/.

import { skipToken } from '@reduxjs/toolkit/query/react'

// types
import { BraveWallet } from '../../constants/types'

// utils
import { getAssetSymbol } from '../../utils/meld_utils'
import { loadTimeData } from '../../../common/loadTimeData'

// hooks
import {
useGetMeldCryptoCurrenciesQuery,
useGetOnRampAssetsQuery
} from '../slices/api.slice'
import { useGetMeldCryptoCurrenciesQuery } from '../slices/api.slice'

export const useFindBuySupportedToken = (
token?: Pick<
BraveWallet.BlockchainToken,
'symbol' | 'contractAddress' | 'chainId'
>
) => {
// Computed
const isAndroid = loadTimeData.getBoolean('isAndroid') || false

// queries
const { data: options } = useGetMeldCryptoCurrenciesQuery(
token && !isAndroid ? undefined : skipToken
)

const { data: androidOptions = undefined } = useGetOnRampAssetsQuery(
token && isAndroid ? undefined : skipToken
)

const canBuyOnAndroid =
token &&
isAndroid &&
androidOptions?.allAssetOptions.some(
(asset) => asset.symbol.toLowerCase() === token.symbol.toLowerCase()
)
const { data: options } = useGetMeldCryptoCurrenciesQuery()

// computed
const foundNativeToken =
Expand Down Expand Up @@ -72,7 +50,6 @@ export const useFindBuySupportedToken = (
// render
return {
foundMeldBuyToken:
foundNativeToken || foundTokenByContractAddress || foundTokenBySymbol,
foundAndroidBuyToken: canBuyOnAndroid ? token : undefined
foundNativeToken || foundTokenByContractAddress || foundTokenBySymbol
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@

import * as React from 'react'
import { useHistory } from 'react-router'
import { skipToken } from '@reduxjs/toolkit/query/react'

// Hooks
import {
useGetCoinMarketQuery,
useGetDefaultFiatCurrencyQuery,
useGetMeldCryptoCurrenciesQuery,
useGetOnRampAssetsQuery
useGetMeldCryptoCurrenciesQuery
} from '../../../../common/slices/api.slice'
import {
useGetCombinedTokensListQuery //
Expand Down Expand Up @@ -40,13 +38,11 @@ import {
UpdateIframeHeightMessage
} from '../../../../market/market-ui-messages'
import {
makeAndroidFundWalletRoute,
makeDepositFundsRoute,
makeFundWalletRoute
} from '../../../../utils/routes-utils'
import { getAssetIdKey } from '../../../../utils/asset-utils'
import { getAssetSymbol } from '../../../../utils/meld_utils'
import { loadTimeData } from '../../../../../common/loadTimeData'

const assetsRequestLimit = 250

Expand All @@ -62,25 +58,11 @@ export const MarketView = () => {
// Hooks
const history = useHistory()

// Computed
const isAndroid = loadTimeData.getBoolean('isAndroid') || false

// Queries
const { data: defaultFiatCurrency = 'usd' } = useGetDefaultFiatCurrencyQuery()
const { data: combinedTokensList } = useGetCombinedTokensListQuery()

const { data: buyAssets } = useGetMeldCryptoCurrenciesQuery(
!isAndroid ? undefined : skipToken
)
const { androidBuyAssets } = useGetOnRampAssetsQuery(
isAndroid ? undefined : skipToken,
{
selectFromResult: (res) => ({
isLoading: res.isLoading,
androidBuyAssets: res.data?.allAssetOptions || []
})
}
)
const { data: buyAssets } = useGetMeldCryptoCurrenciesQuery()

const { data: allCoins = [], isLoading: isLoadingCoinMarketData } =
useGetCoinMarketQuery({
Expand Down Expand Up @@ -108,28 +90,6 @@ export const MarketView = () => {
const foundMeldTokens = buyAssets?.filter(
(t) => getAssetSymbol(t) === symbolLower
)
const foundAndroidTokens = androidBuyAssets.filter(
(t) => t.symbol.toLowerCase() === symbolLower
)

if (isAndroid && foundAndroidTokens.length === 1) {
history.push(
makeAndroidFundWalletRoute(getAssetIdKey(foundAndroidTokens[0]), {
searchText: symbolLower
})
)
return
}

if (isAndroid && foundAndroidTokens.length > 1) {
history.push(
makeAndroidFundWalletRoute('', {
searchText: symbolLower
})
)
return
}

if (foundMeldTokens) {
history.push(makeFundWalletRoute(foundMeldTokens[0]))
}
Expand Down Expand Up @@ -169,7 +129,7 @@ export const MarketView = () => {
}
}
},
[buyAssets, combinedTokensList, history, androidBuyAssets, isAndroid]
[buyAssets, combinedTokensList, history]
)

const onMarketDataFrameLoad = React.useCallback(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
import { getAssetIdKey } from '../../../../utils/asset-utils'
import { getLocale } from '../../../../../common/locale'
import {
makeAndroidFundWalletRoute,
makeDepositFundsRoute,
makeFundWalletRoute
} from '../../../../utils/routes-utils'
Expand Down Expand Up @@ -202,7 +201,7 @@ export const MarketAsset = () => {
)

// custom hooks
const { foundAndroidBuyToken, foundMeldBuyToken } = useFindBuySupportedToken(
const { foundMeldBuyToken } = useFindBuySupportedToken(
selectedAssetFromParams
)

Expand Down Expand Up @@ -303,21 +302,10 @@ export const MarketAsset = () => {
}, [history, selectedAssetFromParams, updateUserAssetVisible])

const onSelectBuy = React.useCallback(() => {
if (selectedAssetFromParams && foundAndroidBuyToken) {
history.push(
makeAndroidFundWalletRoute(getAssetIdKey(selectedAssetFromParams))
)
return
}
if (foundMeldBuyToken) {
history.push(makeFundWalletRoute(foundMeldBuyToken))
}
}, [
history,
foundMeldBuyToken,
selectedAssetFromParams,
foundAndroidBuyToken
])
}, [history, foundMeldBuyToken])

const onSelectDeposit = React.useCallback(() => {
if (foundTokens.length === 1) {
Expand Down Expand Up @@ -398,7 +386,7 @@ export const MarketAsset = () => {
/>
<Row padding='0px 20px'>
<ButtonRow>
{(foundMeldBuyToken || foundAndroidBuyToken) && (
{foundMeldBuyToken && (
<div>
<LeoSquaredButton onClick={onSelectBuy}>
{getLocale('braveWalletBuy')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import { getLocale } from '../../../../../common/locale'
import { makeNetworkAsset } from '../../../../options/asset-options'
import { isRewardsAssetId } from '../../../../utils/rewards_utils'
import {
makeAndroidFundWalletRoute,
makeDepositFundsRoute,
makeFundWalletRoute
} from '../../../../utils/routes-utils'
Expand Down Expand Up @@ -210,7 +209,7 @@ export const PortfolioFungibleAsset = () => {
)

// custom hooks
const { foundAndroidBuyToken, foundMeldBuyToken } = useFindBuySupportedToken(
const { foundMeldBuyToken } = useFindBuySupportedToken(
selectedAssetFromParams
)

Expand Down Expand Up @@ -355,21 +354,10 @@ export const PortfolioFungibleAsset = () => {
])

const onSelectBuy = React.useCallback(() => {
if (foundAndroidBuyToken && selectedAssetFromParams) {
history.push(
makeAndroidFundWalletRoute(getAssetIdKey(selectedAssetFromParams))
)
return
}
if (foundMeldBuyToken) {
history.push(makeFundWalletRoute(foundMeldBuyToken))
}
}, [
history,
foundAndroidBuyToken,
foundMeldBuyToken,
selectedAssetFromParams
])
}, [history, foundMeldBuyToken])

const onSelectDeposit = React.useCallback(() => {
if (selectedAssetFromParams) {
Expand Down Expand Up @@ -438,7 +426,7 @@ export const PortfolioFungibleAsset = () => {
/>
<Row padding='0px 20px'>
<ButtonRow>
{(foundMeldBuyToken || foundAndroidBuyToken) && !isRewardsToken && (
{foundMeldBuyToken && !isRewardsToken && (
<div>
<LeoSquaredButton onClick={onSelectBuy}>
{getLocale('braveWalletBuy')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
import { getLocale } from '../../../../common/locale'
import Amount from '../../../utils/amount'
import {
makeAndroidFundWalletRoute,
makeDepositFundsRoute,
makeFundWalletRoute,
makeSendRoute,
Expand Down Expand Up @@ -80,8 +79,7 @@ export const AssetItemMenu = (props: Props) => {
checkIsAssetSellSupported
} = useMultiChainSellAssets()

const { foundAndroidBuyToken, foundMeldBuyToken } =
useFindBuySupportedToken(asset)
const { foundMeldBuyToken } = useFindBuySupportedToken(asset)

// Memos
const isAssetsBalanceZero = React.useMemo(() => {
Expand All @@ -96,14 +94,10 @@ export const AssetItemMenu = (props: Props) => {

// Methods
const onClickBuy = React.useCallback(() => {
if (foundAndroidBuyToken) {
history.push(makeAndroidFundWalletRoute(getAssetIdKey(asset)))
return
}
if (foundMeldBuyToken) {
history.push(makeFundWalletRoute(foundMeldBuyToken, account))
}
}, [foundMeldBuyToken, history, account, foundAndroidBuyToken, asset])
}, [foundMeldBuyToken, history, account])

const onClickSend = React.useCallback(() => {
history.push(makeSendRoute(asset, account))
Expand Down Expand Up @@ -145,7 +139,7 @@ export const AssetItemMenu = (props: Props) => {

return (
<StyledWrapper yPosition={42}>
{(foundMeldBuyToken || foundAndroidBuyToken) && (
{foundMeldBuyToken && (
<PopupButton onClick={onClickBuy}>
<ButtonIcon name='coins-alt1' />
<PopupButtonText>{getLocale('braveWalletBuy')}</PopupButtonText>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
import * as React from 'react'
import { Route, Switch } from 'react-router'

// Utils
import { loadTimeData } from '../../../common/loadTimeData'

// Types
import { WalletRoutes } from '../../constants/types'

Expand All @@ -23,7 +20,6 @@ import {
} from '../screens/backup-wallet/backup-wallet.routes'
import { DepositFundsScreen } from '../screens/fund-wallet/deposit-funds'
import { FundWalletScreen } from '../screens/fund-wallet/fund_wallet_v2'
import FundWalletScreenAndroid from '../screens/fund-wallet/fund-wallet'
import { SimplePageWrapper } from '../screens/page-screen.styles'
import {
OnboardingSuccess //
Expand All @@ -34,9 +30,6 @@ export const UnlockedWalletRoutes = ({
}: {
sessionRoute: WalletRoutes | undefined
}) => {
// Computed
const isAndroid = loadTimeData.getBoolean('isAndroid') || false

// render
return (
<>
Expand All @@ -63,7 +56,7 @@ export const UnlockedWalletRoutes = ({
</Route>

<Route path={WalletRoutes.FundWalletPageStart}>
{isAndroid ? <FundWalletScreenAndroid /> : <FundWalletScreen />}
<FundWalletScreen />
</Route>

<Route path={WalletRoutes.DepositFundsPageStart}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
// eslint-disable-next-line import/no-named-default
default as BraveCoreThemeProvider
} from '../../../../../common/BraveCoreThemeProvider'
import { FundWalletScreen } from '../../fund-wallet/fund-wallet'
import { FundWalletScreen } from '../../fund-wallet/fund_wallet_v2'

// Resources
import { setIconBasePath } from '@brave/leo/react/icon'
Expand Down
Loading