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

fix: allow fiat selection in fund wallet screen #15265

Merged
merged 2 commits into from
Sep 28, 2022
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
2 changes: 2 additions & 0 deletions components/brave_wallet_ui/common/async/__mocks__/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@ export const getAllBuyAssets = () => new Promise<{
wyreAssetOptions: BraveWallet.BlockchainToken[]
rampAssetOptions: BraveWallet.BlockchainToken[]
allAssetOptions: BraveWallet.BlockchainToken[]
sardineAssetOptions: BraveWallet.BlockchainToken[]
}>((resolve) => {
resolve({
wyreAssetOptions: mockBuyAssetList,
rampAssetOptions: mockBuyAssetList,
sardineAssetOptions: mockBuyAssetList,
allAssetOptions: mockBuyAssetList
})
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
// Copyright (c) 2022 The Brave Authors. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// you can obtain one at http://mozilla.org/MPL/2.0/.

import * as React from 'react'
import { useDispatch, useSelector } from 'react-redux'
import Fuse from 'fuse.js'
import { useHistory } from 'react-router-dom'

import SelectAssetItem from '../select-asset-item'
// types
import { BraveWallet, WalletRoutes, WalletState } from '../../../constants/types'

// actions
import { WalletActions } from '../../../common/actions'
import { PanelActions } from '../../../panel/actions'

// utils
import { getLocale } from '../../../../common/locale'
import { getAssetIdKey } from '../../../utils/asset-utils'

// components
import SelectAssetItem from '../select-asset-item'
import { SearchBar } from '../../shared'
import Header from '../select-header'
import { getLocale } from '../../../../common/locale'

// Styled Components
import {
SelectWrapper,
SelectScrollSearchContainer,
DivderTextWrapper,
DividerText
} from '../shared-styles'
import { useHistory } from 'react-router-dom'
import { PanelActions } from '../../../panel/actions'

export interface Props {
assets: BraveWallet.BlockchainToken[]
Expand Down Expand Up @@ -95,7 +109,7 @@ function SelectAsset (props: Props) {
// Temp filtering out erc721 tokens, sending will be handled in a different PR
filteredAssetList.filter((token) => !token.isErc721).map((asset: BraveWallet.BlockchainToken) =>
<SelectAssetItem
key={asset.contractAddress}
key={getAssetIdKey(asset)}
asset={asset}
selectedNetwork={selectedNetwork}
onSelectAsset={onSelectAsset(asset)}
Expand All @@ -109,7 +123,7 @@ function SelectAsset (props: Props) {
</DivderTextWrapper>
{erc271Tokens.map((asset: BraveWallet.BlockchainToken) =>
<SelectAssetItem
key={asset.contractAddress}
key={getAssetIdKey(asset)}
asset={asset}
selectedNetwork={selectedNetwork}
onSelectAsset={onSelectAsset(asset)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const SelectWrapper = styled.div`
flex-direction: column;
align-items: center;
justify-content: flex-start;
max-height: 100%;
`

export const SelectScrollSearchContainer = styled.div`
Expand All @@ -30,11 +31,8 @@ export const SelectScrollSearchContainer = styled.div`
justify-content: flex-start;
overflow-y: scroll;
overflow-x: hidden;
position: absolute;
top: 96px;
bottom: 18px;
left: 18px;
right: 18px;
width: 100%;
max-height: 100%;
`

export const SelectScrollContainer = styled.div`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const StyledWrapper = styled.div`
align-items: center;
justify-content: space-between;
flex-direction: row;
height: 36px;
min-height: 36px;
width: 100%;
border: ${(p) => `1px solid ${p.theme.color.interactive08}`};
border-radius: 4px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import { NavButton } from '../../../components/extension/buttons/nav-button/inde
import CreateAccountTab from '../../../components/buy-send-swap/create-account'
import SwapInputComponent from '../../../components/buy-send-swap/swap-input-component'
import SelectHeader from '../../../components/buy-send-swap/select-header'
import { SelectCurrency } from '../../../components/buy-send-swap/select-currency/select-currency'

export const FundWalletScreen = () => {
// routing
Expand Down Expand Up @@ -84,6 +85,7 @@ export const FundWalletScreen = () => {

// state
const [showBuyOptions, setShowBuyOptions] = React.useState<boolean>(false)
const [showFiatSelection, setShowFiatSelection] = React.useState<boolean>(false)
const [showAccountSearch, setShowAccountSearch] = React.useState<boolean>(false)
const [accountSearchText, setAccountSearchText] = React.useState<string>('')

Expand Down Expand Up @@ -209,7 +211,7 @@ export const FundWalletScreen = () => {
<StyledWrapper>

{/* Hide nav when creating or searching accounts */}
{!showAccountSearch && !(
{!showAccountSearch && !showFiatSelection && !(
needsAccount && showBuyOptions
) &&
<StepsNavigation
Expand All @@ -221,8 +223,19 @@ export const FundWalletScreen = () => {
/>
}

{/* Fiat Selection */}
{showFiatSelection &&
<SelectCurrency
onSelectCurrency={
// this internally sets the currency via redux, so just hide the UI when selected
() => setShowFiatSelection(false)
}
onBack={() => setShowFiatSelection(false)}
/>
}

{/* Asset Selection */}
{!showBuyOptions &&
{!showBuyOptions && !showFiatSelection &&
<>
<SelectAssetWrapper>
<SwapInputComponent
Expand All @@ -234,6 +247,7 @@ export const FundWalletScreen = () => {
selectedAsset={selectedAsset}
selectedNetwork={selectedAssetNetwork || selectedNetworkFilter}
autoFocus={true}
onShowCurrencySelection={() => setShowFiatSelection(true)}
/>

{assetsForFilteredNetwork.length
Expand Down