Skip to content

Commit

Permalink
Hide chooser for filenet
Browse files Browse the repository at this point in the history
  • Loading branch information
cypt4 committed Jun 13, 2022
1 parent f391b7a commit 91e1231
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ TEST_F(BraveWalletUtilsUnitTest, GetChain) {
EXPECT_EQ(GetChain(&prefs, "f", mojom::CoinType::FIL), fil_mainnet.Clone());
}

TEST(BraveWalletUtilsUnitTest, GetAllKnownEthNetworkIds) {
TEST_F(BraveWalletUtilsUnitTest, GetAllKnownEthNetworkIds) {
const std::vector<std::string> expected_network_ids(
{"mainnet", mojom::kPolygonMainnetChainId,
mojom::kBinanceSmartChainMainnetChainId, mojom::kCeloMainnetChainId,
Expand Down
8 changes: 0 additions & 8 deletions components/brave_wallet_ui/common/hardware/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,5 @@ export type GetAccountsHardwareOperationResult = HardwareOperationResult & {
payload?: BraveWallet.HardwareWalletAccount[]
}

// Did not create a string for these yet since it is
// likely these names will be returned from another service
// that will be localized.
export const FilecoinNetworkLocaleMapping = {
[BraveWallet.FILECOIN_MAINNET]: 'Filecoin Mainnet',
[BraveWallet.FILECOIN_TESTNET]: 'Filecoin Testnet'
}

// Batch size of accounts imported from the device in one step.
export const DerivationBatchSize = 4
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ function NetworkFilterSelector () {
selectedNetwork={selectedNetworkFilter}
isSubItem={isTestNetworksEnabled ? !SupportedTopLevelChainIds.includes(network.chainId) : true}
>
{isTestNetworksEnabled &&
{/* Disabled Filecoin Submenu until testnetworks are enabled */}
{isTestNetworksEnabled && network.coin !== BraveWallet.CoinType.FIL &&
<SubDropDown>
{sortedNetworks.filter((n) =>
n.coin === network.coin &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { CreateAccountOptions } from '../../../../options/create-account-options

// types
import { BraveWallet, CreateAccountOptionsType, PageState, WalletRoutes, WalletState } from '../../../../constants/types'
import { FilecoinNetworkTypes, FilecoinNetworkLocaleMapping, FilecoinNetwork } from '../../../../common/hardware/types'

// actions
import { WalletPageActions } from '../../../../page/actions'
Expand Down Expand Up @@ -74,8 +73,11 @@ export const ImportAccountModal = () => {
}, [accountTypeName, isFilecoinEnabled, isSolanaEnabled])

// state
const selectedFilecoinNetwork = useSelector(({ wallet }: { wallet: WalletState }) => {
return wallet.defaultNetworks.find((network) => { return network.coin === BraveWallet.CoinType.FIL })
})
const [accountName, setAccountName] = React.useState<string>('')
const [filecoinNetwork, setFilecoinNetwork] = React.useState<FilecoinNetwork>('f')
const networkSymbol = selectedFilecoinNetwork?.chainId.toLowerCase() === BraveWallet.FILECOIN_MAINNET.toLowerCase() ? BraveWallet.FILECOIN_MAINNET : BraveWallet.FILECOIN_TESTNET
const [importOption, setImportOption] = React.useState<string>('key')
const [privateKey, setPrivateKey] = React.useState<string>('')
const [file, setFile] = React.useState<HTMLInputElement['files']>()
Expand Down Expand Up @@ -112,10 +114,6 @@ export const ImportAccountModal = () => {
setImportError(false)
}, [setImportError])

const onChangeFilecoinNetwork = React.useCallback((network: FilecoinNetwork) => {
setFilecoinNetwork(network)
}, [])

const handlePrivateKeyChanged = React.useCallback((event: React.ChangeEvent<HTMLInputElement>) => {
setPrivateKey(event.target.value)
setImportError(false)
Expand All @@ -141,7 +139,7 @@ export const ImportAccountModal = () => {
const onClickCreateAccount = React.useCallback(() => {
if (importOption === 'key') {
if (selectedAccountType?.coin === BraveWallet.CoinType.FIL) {
importFilecoinAccount(accountName, privateKey, filecoinNetwork)
importFilecoinAccount(accountName, privateKey, networkSymbol)
} else {
importAccount(accountName, privateKey, selectedAccountType?.coin || BraveWallet.CoinType.ETH)
}
Expand Down Expand Up @@ -208,23 +206,6 @@ export const ImportAccountModal = () => {
<DisclaimerText>{getLocale('braveWalletImportAccountDisclaimer')}</DisclaimerText>
</ImportDisclaimer>

{selectedAccountType?.coin === BraveWallet.CoinType.FIL &&
<>
<SelectWrapper>
<Select value={filecoinNetwork} onChange={onChangeFilecoinNetwork}>
{FilecoinNetworkTypes.map((network, index) => {
const networkLocale = FilecoinNetworkLocaleMapping[network]
return (
<div data-value={network} key={index}>
{networkLocale}
</div>
)
})}
</Select>
</SelectWrapper>
</>
}

{selectedAccountType?.coin === BraveWallet.CoinType.ETH &&
<SelectWrapper>
<Select
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ import {
HardwareWalletDerivationPathsMapping
} from './types'
import {
FilecoinNetwork,
FilecoinNetworkTypes,
FilecoinNetworkLocaleMapping
FilecoinNetwork
} from '../../../../../common/hardware/types'
import { BraveWallet, WalletAccountType, CreateAccountOptionsType } from '../../../../../constants/types'
import { getLocale } from '../../../../../../common/locale'
Expand All @@ -47,7 +45,6 @@ interface Props {
onAddAccounts: () => void
getBalance: (address: string, coin: BraveWallet.CoinType) => Promise<string>
filecoinNetwork: FilecoinNetwork
onChangeFilecoinNetwork: (network: FilecoinNetwork) => void
selectedAccountType: CreateAccountOptionsType
}

Expand All @@ -64,8 +61,6 @@ export default function (props: Props) {
onLoadMore,
onAddAccounts,
getBalance,
filecoinNetwork,
onChangeFilecoinNetwork,
selectedAccountType
} = props
const [filteredAccountList, setFilteredAccountList] = React.useState<BraveWallet.HardwareWalletAccount[]>([])
Expand Down Expand Up @@ -115,7 +110,7 @@ export default function (props: Props) {
<>
<SelectRow>
<SelectWrapper>
{selectedAccountType.coin !== BraveWallet.CoinType.FIL ? (
{selectedAccountType.coin !== BraveWallet.CoinType.FIL && (
<Select value={selectedDerivationScheme} onChange={setSelectedDerivationScheme}>
{Object.keys(derivationPathsEnum).map((path, index) => {
const pathValue = derivationPathsEnum[path]
Expand All @@ -127,17 +122,6 @@ export default function (props: Props) {
)
})}
</Select>
) : (
<Select value={filecoinNetwork} onChange={onChangeFilecoinNetwork}>
{FilecoinNetworkTypes.map((network, index) => {
const networkLocale = FilecoinNetworkLocaleMapping[network]
return (
<div data-value={network} key={index}>
{networkLocale}
</div>
)
})}
</Select>
)}
</SelectWrapper>
</SelectRow>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {

// Custom types
import { ErrorMessage, HardwareWalletDerivationPathsMapping } from './types'
import { HardwareDerivationScheme, LedgerDerivationPaths, FilecoinNetwork, DerivationBatchSize } from '../../../../../common/hardware/types'
import { HardwareDerivationScheme, LedgerDerivationPaths, DerivationBatchSize } from '../../../../../common/hardware/types'
import { HardwareVendor } from '../../../../../common/api/hardware_keyrings'
import { WalletPageActions } from '../../../../../page/actions'
import { BraveWallet, CreateAccountOptionsType, WalletState } from '../../../../../constants/types'
Expand Down Expand Up @@ -68,6 +68,9 @@ export const HardwareWalletConnect = ({ onSuccess, selectedAccountType }: Props)
// redux
const dispatch = useDispatch()
const selectedNetwork = useSelector(({ wallet }: { wallet: WalletState }) => wallet.selectedNetwork)
const selectedFilecoinNetwork = useSelector(({ wallet }: { wallet: WalletState }) => {
return wallet.defaultNetworks.find((network) => { return network.coin === BraveWallet.CoinType.FIL })
})
const savedAccounts = useSelector(({ wallet }: { wallet: WalletState }) => wallet.accounts)

// state
Expand All @@ -79,28 +82,11 @@ export const HardwareWalletConnect = ({ onSuccess, selectedAccountType }: Props)
const [selectedDerivationScheme, setSelectedDerivationScheme] = React.useState<HardwareDerivationScheme>(
LedgerDerivationPaths.LedgerLive
)

const [showAccountsList, setShowAccountsList] = React.useState<boolean>(false)
const [filecoinNetwork, setFilecoinNetwork] = React.useState<FilecoinNetwork>('f')
const filecoinNetwork = selectedFilecoinNetwork?.chainId.toLowerCase() === BraveWallet.FILECOIN_MAINNET.toLowerCase() ? BraveWallet.FILECOIN_MAINNET : BraveWallet.FILECOIN_TESTNET

// methods
const onFilecoinNetworkChanged = React.useCallback((network: FilecoinNetwork) => {
setFilecoinNetwork(network)
onConnectHardwareWallet({
hardware: BraveWallet.LEDGER_HARDWARE_VENDOR,
startIndex: 0,
stopIndex: DerivationBatchSize,
network: network,
coin: BraveWallet.CoinType.FIL
}).then((result) => {
setAccounts(result)
}).catch((error) => {
setConnectionError(getErrorMessage(error, selectedAccountType.name))
setShowAccountsList(false)
}).finally(
() => setIsConnecting(false)
)
}, [onConnectHardwareWallet, selectedAccountType])

const onAddHardwareAccounts = React.useCallback((selected: BraveWallet.HardwareWalletAccount[]) => {
dispatch(WalletPageActions.addHardwareAccounts(selected))
onSuccess()
Expand Down Expand Up @@ -215,7 +201,6 @@ export const HardwareWalletConnect = ({ onSuccess, selectedAccountType }: Props)
getBalance={getBalance}
selectedNetwork={selectedNetwork}
filecoinNetwork={filecoinNetwork}
onChangeFilecoinNetwork={onFilecoinNetworkChanged}
selectedAccountType={selectedAccountType}
/>
)
Expand Down

0 comments on commit 91e1231

Please sign in to comment.