Skip to content

Commit

Permalink
Revert "Hide chooser for filenet"
Browse files Browse the repository at this point in the history
This reverts commit 91e1231.
  • Loading branch information
cypt4 committed Jun 30, 2022
1 parent 81a646b commit 22bf895
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 16 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_F(BraveWalletUtilsUnitTest, GetAllKnownEthNetworkIds) {
TEST(BraveWalletUtilsUnitTest, GetAllKnownEthNetworkIds) {
const std::vector<std::string> expected_network_ids(
{"mainnet", mojom::kPolygonMainnetChainId,
mojom::kBinanceSmartChainMainnetChainId, mojom::kCeloMainnetChainId,
Expand Down
8 changes: 8 additions & 0 deletions components/brave_wallet_ui/common/hardware/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,13 @@ 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,8 +91,7 @@ function NetworkFilterSelector () {
selectedNetwork={selectedNetworkFilter}
isSubItem={isTestNetworksEnabled ? !SupportedTopLevelChainIds.includes(network.chainId) : true}
>
{/* Disabled Filecoin Submenu until testnetworks are enabled */}
{isTestNetworksEnabled && network.coin !== BraveWallet.CoinType.FIL &&
{isTestNetworksEnabled &&
<SubDropDown>
{sortedNetworks.filter((n) =>
n.coin === network.coin &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ 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 @@ -79,11 +80,8 @@ 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 networkSymbol = selectedFilecoinNetwork?.chainId.toLowerCase() === BraveWallet.FILECOIN_MAINNET.toLowerCase() ? BraveWallet.FILECOIN_MAINNET : BraveWallet.FILECOIN_TESTNET
const [filecoinNetwork, setFilecoinNetwork] = React.useState<FilecoinNetwork>('f')
const [importOption, setImportOption] = React.useState<string>('key')
const [privateKey, setPrivateKey] = React.useState<string>('')
const [file, setFile] = React.useState<HTMLInputElement['files']>()
Expand Down Expand Up @@ -120,6 +118,10 @@ 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 @@ -145,7 +147,7 @@ export const ImportAccountModal = () => {
const onClickCreateAccount = React.useCallback(() => {
if (importOption === 'key') {
if (selectedAccountType?.coin === BraveWallet.CoinType.FIL) {
importFilecoinAccount(accountName, privateKey, networkSymbol)
importFilecoinAccount(accountName, privateKey, filecoinNetwork)
} else {
importAccount(accountName, privateKey, selectedAccountType?.coin || BraveWallet.CoinType.ETH)
}
Expand Down Expand Up @@ -216,6 +218,7 @@ export const ImportAccountModal = () => {
</ImportDisclaimer>

{selectedAccountType?.coin === BraveWallet.CoinType.FIL &&

<WarningWrapper>
<WarningText>
{filPrivateKeyFormatDescriptionTextParts.beforeTag}
Expand All @@ -224,6 +227,21 @@ export const ImportAccountModal = () => {
</a>
{filPrivateKeyFormatDescriptionTextParts.afterTag}</WarningText>
</WarningWrapper>

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

Expand All @@ -61,6 +64,8 @@ export default function (props: Props) {
onLoadMore,
onAddAccounts,
getBalance,
filecoinNetwork,
onChangeFilecoinNetwork,
selectedAccountType
} = props
const [filteredAccountList, setFilteredAccountList] = React.useState<BraveWallet.HardwareWalletAccount[]>([])
Expand Down Expand Up @@ -110,7 +115,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 @@ -122,6 +127,17 @@ 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, DerivationBatchSize } from '../../../../../common/hardware/types'
import { HardwareDerivationScheme, LedgerDerivationPaths, FilecoinNetwork, 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,9 +68,6 @@ 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 @@ -82,11 +79,28 @@ export const HardwareWalletConnect = ({ onSuccess, selectedAccountType }: Props)
const [selectedDerivationScheme, setSelectedDerivationScheme] = React.useState<HardwareDerivationScheme>(
LedgerDerivationPaths.LedgerLive
)

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

// 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 @@ -201,6 +215,7 @@ export const HardwareWalletConnect = ({ onSuccess, selectedAccountType }: Props)
getBalance={getBalance}
selectedNetwork={selectedNetwork}
filecoinNetwork={filecoinNetwork}
onChangeFilecoinNetwork={onFilecoinNetworkChanged}
selectedAccountType={selectedAccountType}
/>
)
Expand Down

0 comments on commit 22bf895

Please sign in to comment.