Skip to content

Commit

Permalink
fix: only allow restore route access when unlocked
Browse files Browse the repository at this point in the history
  • Loading branch information
josheleonard committed May 19, 2022
1 parent 427950c commit e387ce2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 41 deletions.
35 changes: 0 additions & 35 deletions components/brave_wallet_ui/common/async/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,41 +232,6 @@ handler.on(WalletActions.removeFavoriteApp.getType(), async (store: Store, appIt
await refreshWalletInfo(store)
})

handler.on(WalletActions.chainChangedEvent.getType(), async (store: Store, payload: ChainChangedEventPayloadType) => {
const keyringService = getAPIProxy().keyringService
const state = getWalletState(store)
const { accounts } = state
const selectedAccountAddress = await keyringService.getSelectedAccount(payload.coin)
const selectedAccount = accounts.find((account) => account.address === selectedAccountAddress.address) ?? accounts[0]
store.dispatch(WalletActions.setSelectedAccount(selectedAccount))
store.dispatch(WalletActions.setSelectedCoin(payload.coin))
})

handler.on(WalletActions.selectNetwork.getType(), async (store: Store, payload: BraveWallet.NetworkInfo) => {
if (payload) {
const jsonRpcService = getAPIProxy().jsonRpcService
await jsonRpcService.setNetwork(payload.chainId, payload.coin)
store.dispatch(WalletActions.setNetwork(payload))
}
})

handler.on(WalletActions.selectAccount.getType(), async (store: Store, payload: WalletAccountType) => {
const { keyringService } = getAPIProxy()
const state = getWalletState(store)
const { defaultNetworks } = state

if (!(defaultNetworks.length > 0)) {
return
}

const defaultCoinTypesNetwork = defaultNetworks.find((network) => network.coin === payload.coin) ?? defaultNetworks[0]
await keyringService.setSelectedAccount(payload.address, payload.coin)
store.dispatch(WalletActions.setNetwork(defaultCoinTypesNetwork))
store.dispatch(WalletActions.setSelectedAccount(payload))
store.dispatch(WalletActions.setSelectedCoin(payload.coin))
await store.dispatch(refreshTransactionHistory(payload.address))
})

handler.on(WalletActions.initialized.getType(), async (store: Store, payload: WalletInfo) => {
const keyringService = getAPIProxy().keyringService
const state = getWalletState(store)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,6 @@ export const PortfolioAsset = () => {
}, [selectedAsset])

const goBack = React.useCallback(() => {
// if (nftMetadata) {
// dispatch(WalletPageActions.updateNFTMetadata(undefined))
// }
dispatch(WalletPageActions.selectAsset({ asset: undefined, timeFrame: selectedTimeline }))
history.push(WalletRoutes.Portfolio)
setfilteredAssetList(userAssetList)
Expand Down Expand Up @@ -337,21 +334,23 @@ export const PortfolioAsset = () => {

{!isNftAsset &&
<InfoColumn>

<AssetRow>
<AssetIconWithPlaceholder asset={selectedAsset} network={selectedAssetsNetwork} />
<AssetColumn>
<AssetNameText>{selectedAssetFromParams.name}</AssetNameText>
<NetworkDescription>{selectedAssetFromParams.symbol} on {selectedAssetsNetwork?.chainName ?? ''}</NetworkDescription>
</AssetColumn>
</AssetRow>
{/* <DetailText>{selectedAsset.name} {getLocale('braveWalletPrice')} ({selectedAsset.symbol})</DetailText> */}

<PriceRow>
<PriceText>{CurrencySymbols[defaultCurrencies.fiat]}{hoverPrice || (selectedAssetFiatPrice ? new Amount(selectedAssetFiatPrice.price).formatAsFiat() : 0.00)}</PriceText>
<PercentBubble isDown={selectedAssetFiatPrice ? Number(selectedAssetFiatPrice.assetTimeframeChange) < 0 : false}>
<ArrowIcon isDown={selectedAssetFiatPrice ? Number(selectedAssetFiatPrice.assetTimeframeChange) < 0 : false} />
<PercentText>{selectedAssetFiatPrice ? Number(selectedAssetFiatPrice.assetTimeframeChange).toFixed(2) : 0.00}%</PercentText>
</PercentBubble>
</PriceRow>

<DetailText>
{
selectedAssetCryptoPrice
Expand All @@ -360,6 +359,7 @@ export const PortfolioAsset = () => {
: ''
}
</DetailText>

</InfoColumn>
}

Expand Down
9 changes: 7 additions & 2 deletions components/brave_wallet_ui/page/container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,16 @@ export const Container = () => {
<Onboarding />
</ProtectedRoute>

<Route path={WalletRoutes.Restore} exact={true}>
<ProtectedRoute
path={WalletRoutes.Restore}
requirement={isWalletLocked}
redirectRoute={sessionRoute as WalletRoutes || WalletRoutes.Unlock}
exact={true}
>
<OnboardingWrapper>
<OnboardingRestore />
</OnboardingWrapper>
</Route>
</ProtectedRoute>

<ProtectedRoute
path={WalletRoutes.Unlock}
Expand Down

0 comments on commit e387ce2

Please sign in to comment.