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): Initial Composer UI Setup #21274

Merged
merged 1 commit into from
Dec 8, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 7 additions & 8 deletions components/brave_wallet/browser/brave_wallet_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,17 +190,12 @@ inline constexpr webui::LocalizedString kLocalizedStrings[] = {
{"braveWalletBuy", IDS_BRAVE_WALLET_BUY},
{"braveWalletSend", IDS_BRAVE_WALLET_SEND},
{"braveWalletSwap", IDS_BRAVE_WALLET_SWAP},
{"braveWalletBridge", IDS_BRAVE_WALLET_BRIDGE},
{"braveWalletReset", IDS_BRAVE_WALLET_RESET},
{"braveWalletSell", IDS_BRAVE_WALLET_SELL},
{"braveWalletNotEnoughBalance", IDS_BRAVE_WALLET_NOT_ENOUGH_BALANCE},
{"braveWalletSendToken", IDS_BRAVE_WALLET_SEND_TOKEN},
{"braveWalletSendNFT", IDS_BRAVE_WALLET_SEND_NFT},
{"braveWalletSelectToken", IDS_BRAVE_WALLET_SELECT_TOKEN},
{"braveWalletSelectNFT", IDS_BRAVE_WALLET_SELECT_NFT},
{"braveWalletSendTabSelectTokenTitle",
IDS_BRAVE_WALLET_SEND_TAB_SELECT_TOKEN_TITLE},
{"braveWalletSendTabSelectNFTTitle",
IDS_BRAVE_WALLET_SEND_TAB_SELECT_NFT_TITLE},
{"braveWalletChooseAssetToSend", IDS_BRAVE_WALLET_CHOOSE_ASSET_TO_SEND},
{"braveWalletChooseAssetToSwap", IDS_BRAVE_WALLET_CHOOSE_ASSET_TO_SWAP},
{"braveWalletEnterRecipientAddress",
IDS_BRAVE_WALLET_ENTER_RECIPIENT_ADDRESS},
{"braveWalletNotEnoughFunds", IDS_BRAVE_WALLET_NOT_ENOUGH_FUNDS},
Expand All @@ -211,6 +206,7 @@ inline constexpr webui::LocalizedString kLocalizedStrings[] = {
{"braveWalletNoAvailableTokens", IDS_BRAVE_WALLET_NO_AVAILIBLE_TOKENS},
{"braveWalletSearchTokens", IDS_BRAVE_WALLET_SEARCH_TOKENS},
{"braveWalletSearchNFTs", IDS_BRAVE_WALLET_SEARCH_NFTS},
{"braveWalletChooseAsset", IDS_BRAVE_WALLET_CHOOSE_ASSET},
{"braveWalletSlippageToleranceWarning",
IDS_BRAVE_WALLET_SLIPPAGE_TOLERANCE_WARNING},
{"braveWalletSlippageToleranceTitle",
Expand Down Expand Up @@ -1200,6 +1196,9 @@ inline constexpr webui::LocalizedString kLocalizedStrings[] = {
{"braveSwapMax", IDS_BRAVE_SWAP_MAX},
{"braveSwapEnterAnAmount", IDS_BRAVE_SWAP_ENTER_AN_AMOUNT},
{"braveSwapFindingPrice", IDS_BRAVE_SWAP_FINDING_PRICE},
{"braveWalletReceiveEstimate", IDS_BRAVE_WALLET_RECEIVE_ESTIMATE},
{"braveWalletFromToken", IDS_BRAVE_WALLET_FROM_TOKEN},
{"braveWalletToToken", IDS_BRAVE_WALLET_TO_TOKEN},
{"braveSwapBalance", IDS_BRAVE_SWAP_BALANCE},
{"braveSwapSelectAToken", IDS_BRAVE_SWAP_SELECT_A_TOKEN},
{"braveSwapShowTokensWithZeroBalances",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@

import * as React from 'react'

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

// Hooks
import { useOnClickOutside } from '../../../common/hooks/useOnClickOutside'

// Utils
import { openWalletRouteTab } from '../../../utils/routes-utils'

// Components
import { DefaultPanelMenu } from '../wallet-menus/default-panel-menu'
import {
Expand All @@ -26,10 +32,11 @@ import { Row } from '../../shared/style'

interface Props {
title: string
expandRoute?: WalletRoutes
}

export const DefaultPanelHeader = (props: Props) => {
const { title } = props
const { title, expandRoute } = props

// State
const [showSettingsMenu, setShowSettingsMenu] = React.useState<boolean>(false)
Expand All @@ -46,12 +53,12 @@ export const DefaultPanelHeader = (props: Props) => {

// Methods
const onClickExpand = React.useCallback(() => {
chrome.tabs.create({ url: 'chrome://wallet/crypto' }, () => {
if (chrome.runtime.lastError) {
console.error('tabs.create failed: ' + chrome.runtime.lastError.message)
}
})
}, [])
if (expandRoute) {
openWalletRouteTab(expandRoute)
return
}
openWalletRouteTab(WalletRoutes.PortfolioAssets)
}, [expandRoute])

return (
<Row
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ interface Props {
searchAction?: (event: any) => void | undefined
searchAutoFocus?: boolean
searchValue?: string
networkSelectorDisabled?: boolean
useSwapNetworks?: boolean
}

export const NetworkFilterWithSearch = (props: Props) => {
Expand All @@ -38,7 +40,9 @@ export const NetworkFilterWithSearch = (props: Props) => {
searchPlaceholder,
searchAction,
searchAutoFocus,
searchValue
searchValue,
networkSelectorDisabled,
useSwapNetworks
} = props

return (
Expand All @@ -49,6 +53,7 @@ export const NetworkFilterWithSearch = (props: Props) => {
autoFocus={searchAutoFocus}
value={searchValue}
useWithFilter={true}
isV2={true}
/>
<HorizontalDivider />
<SelectNetworkDropdown
Expand All @@ -58,6 +63,9 @@ export const NetworkFilterWithSearch = (props: Props) => {
showNetworkDropDown={showNetworkDropDown}
useWithSearch={true}
customNetwork={AllNetworksOption}
useSwapNetworks={useSwapNetworks}
disabled={networkSelectorDisabled}
reduceDisplayName={true}
/>
</StyledWrapper>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@
// you can obtain one at https://mozilla.org/MPL/2.0/.

import styled from 'styled-components'
import * as leo from '@brave/leo/tokens/css'

export const StyledWrapper = styled.div`
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
width: 100%;
border: ${(p) => `1px solid ${p.theme.color.interactive08}`};
border-radius: 4px;
border-radius: 8px;
background-color: ${leo.color.container.highlight};
`

export const HorizontalDivider = styled.div`
display: flex;
width: 1px;
height: 24px;
background-color: ${(p) => p.theme.color.interactive08};
background-color: ${leo.color.divider.subtle};
`
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

import * as React from 'react'

// Utils
import { reduceNetworkDisplayName } from '../../../utils/network-utils'

// Options
import { AllNetworksOption } from '../../../options/network-filter-options'

Expand Down Expand Up @@ -32,7 +35,10 @@ interface Props {
onClick: () => void
onSelectCustomNetwork: (network: BraveWallet.NetworkInfo) => void
useWithSearch?: boolean
useSwapNetworks?: boolean
customNetwork?: BraveWallet.NetworkInfo | undefined
disabled?: boolean
reduceDisplayName?: boolean
}

export const SelectNetworkDropdown = (props: Props) => {
Expand All @@ -42,14 +48,24 @@ export const SelectNetworkDropdown = (props: Props) => {
showNetworkDropDown,
onSelectCustomNetwork,
useWithSearch,
customNetwork
useSwapNetworks,
customNetwork,
disabled,
reduceDisplayName
} = props

const networkDisplayName = selectedNetwork?.chainName
? reduceDisplayName && selectedNetwork.chainId !== AllNetworksOption.chainId
? reduceNetworkDisplayName(selectedNetwork.chainName)
: selectedNetwork.chainName
: getLocale('braveWalletSelectNetwork')

return (
<StyledWrapper useWithSearch={useWithSearch}>
<NetworkButton
onClick={onClick}
useWithSearch={useWithSearch}
disabled={disabled}
>
<LeftSide>
{selectedNetwork &&
Expand All @@ -60,10 +76,7 @@ export const SelectNetworkDropdown = (props: Props) => {
size='big'
/>
)}
<NetworkText>
{selectedNetwork?.chainName ||
getLocale('braveWalletSelectNetwork')}
</NetworkText>
<NetworkText>{networkDisplayName}</NetworkText>
</LeftSide>
<DropDownIcon isOpen={showNetworkDropDown} />
</NetworkButton>
Expand All @@ -73,6 +86,7 @@ export const SelectNetworkDropdown = (props: Props) => {
onSelectCustomNetwork={onSelectCustomNetwork}
selectedNetwork={selectedNetwork}
customNetwork={customNetwork}
useSwapNetworks={useSwapNetworks}
/>
</DropDown>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export const NetworkButton = styled(WalletButton)<{ useWithSearch?: boolean }>`
padding: 10px;
padding-left: 12px;
margin-bottom: ${(p) => (p.useWithSearch ? '0px' : '8px')};
:disabled {
cursor: not-allowed;
opacity: 0.5;
}
`

export const DropDownIcon = styled(CaratStrongDownIcon)<{ isOpen: boolean }>`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,9 @@ export const BuySendSwapDepositNav = () => {
// methods
const onClick = React.useCallback(
(option: NavOption) => {
// Redirect to full page view for buy and swap page
// until we have a panel view for those pages
if (
(option.route === WalletRoutes.FundWalletPageStart ||
option.route === WalletRoutes.Swap) &&
isPanel
) {
// Redirect to full page view for buy page
// until we have a panel view for that page.
if (option.route === WalletRoutes.FundWalletPageStart && isPanel) {
chrome.tabs.create({
url: `brave://wallet${option.route}`
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import CreateNetworkIcon from '../create-network-icon'
import { NftIcon, NftIconProps } from './nft-icon'

// styles
import { NetworkIconWrapper } from '../../../page/screens/send/components/token-list-item/token-list-item.style'
import {
NetworkIconWrapper //
} from '../../../page/screens/composer_ui/token_list_item/token_list_item.style'
import { IconWrapper } from './nft-icon-styles'
import { useGetNetworkQuery } from '../../../common/slices/api.slice'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import * as React from 'react'
import { BraveWallet } from '../../../constants/types'

// hooks
import { useGetVisibleNetworksQuery } from '../../../common/slices/api.slice'
import {
useGetSwapSupportedNetworksQuery,
useGetVisibleNetworksQuery
} from '../../../common/slices/api.slice'

// components
import { SelectNetworkItem } from '../select-network-item/index'
Expand All @@ -18,15 +21,28 @@ interface Props {
onSelectCustomNetwork: (network: BraveWallet.NetworkInfo) => void
selectedNetwork: BraveWallet.NetworkInfo | undefined | null
customNetwork?: BraveWallet.NetworkInfo
useSwapNetworks?: boolean
}

export function SelectNetwork({
onSelectCustomNetwork,
selectedNetwork,
customNetwork
customNetwork,
useSwapNetworks
}: Props) {
// queries
const { data: networks = [] } = useGetVisibleNetworksQuery()
const { data: visibleNetworks = [] } = useGetVisibleNetworksQuery(undefined, {
skip: useSwapNetworks
})
const { data: swapNetworks = [] } = useGetSwapSupportedNetworksQuery(
undefined,
{
skip: !useSwapNetworks
}
)
Douglashdaniel marked this conversation as resolved.
Show resolved Hide resolved

// Computed
const networks = useSwapNetworks ? swapNetworks : visibleNetworks

// memos
const networksList = React.useMemo(() => {
Expand Down
3 changes: 3 additions & 0 deletions components/brave_wallet_ui/constants/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,8 @@ export enum WalletRoutes {
// send
Send = '/send',

Bridge = '/bridge',

// dev bitcoin screen
DevBitcoin = '/dev-bitcoin',

Expand Down Expand Up @@ -964,6 +966,7 @@ export type NavIDTypes =
| 'transactions'
| 'my_assets'
| 'available_assets'
| 'bridge'

export type AccountPageTabs =
(typeof AccountPageTabs)[keyof typeof AccountPageTabs]
Expand Down
22 changes: 22 additions & 0 deletions components/brave_wallet_ui/options/nav-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,25 @@ export const AccountDetailsOptions: NavOption[] = [
route: AccountPageTabs.AccountTransactionsSub
}
]

export const SendSwapBridgeOptions: NavOption[] = [
{
id: 'send',
name: 'braveWalletSend',
icon: 'send',
route: WalletRoutes.Send
},
{
id: 'swap',
name: 'braveWalletSwap',
icon: 'currency-exchange',
route: WalletRoutes.Swap
}
// Bridge is not yet implemented
// {
// id: 'bridge',
// name: 'braveWalletBridge',
// icon: 'bridge',
// route: WalletRoutes.Bridge
// }
]
11 changes: 1 addition & 10 deletions components/brave_wallet_ui/page/container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ import {
ProtectedRoute //
} from '../components/shared/protected-routing/protected-route'
import { UnlockedWalletRoutes } from './router/unlocked_wallet_routes'
import {
PageTitleHeader //
} from '../components/desktop/card-headers/page-title-header'
import { Swap } from './screens/swap/swap'
import { SendScreen } from './screens/send/send_screen/send_screen'

Expand Down Expand Up @@ -167,13 +164,7 @@ export const Container = () => {
redirectRoute={defaultRedirect}
exact={true}
>
<WalletPageWrapper
hideHeader={true}
hideBackground={true}
cardHeader={<PageTitleHeader title={'braveWalletSwap'} />}
>
<Swap />
</WalletPageWrapper>
<Swap />
</ProtectedRoute>

<ProtectedRoute
Expand Down