Skip to content

Commit

Permalink
CR: update
Browse files Browse the repository at this point in the history
  • Loading branch information
banklesss committed Apr 25, 2024
1 parent 6f0aec7 commit 4623b66
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 92 deletions.
1 change: 1 addition & 0 deletions apps/wallet-mobile/.storybook/storybook.requires.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from 'react'
import {defineMessages, useIntl} from 'react-intl'
import {ScrollView, StyleSheet, View, ViewProps} from 'react-native'
import {SafeAreaView} from 'react-native-safe-area-context'
import {useQueryClient} from 'react-query'

import {
Button,
Expand All @@ -14,7 +15,9 @@ import {
TextInput,
TextInputProps,
} from '../../../components'
import {useNavigateToWalletSelectionSync} from '../../../navigation'
import {useWalletNavigation} from '../../../navigation'
import {WalletManager} from '../../../wallet-manager/walletManager'
import {useWalletManager} from '../../../wallet-manager/WalletManagerContext'
import {useRemoveWallet, useWalletName} from '../../../yoroi-wallets/hooks'
import {useSelectedWallet} from '../../WalletManager/Context/SelectedWalletContext'

Expand All @@ -23,11 +26,23 @@ export const RemoveWalletScreen = () => {
const styles = useStyles()
const wallet = useSelectedWallet()
const walletName = useWalletName(wallet)
const {resetToWalletSetup, resetToWalletSelection} = useWalletNavigation()
const walletManager = useWalletManager()
const queryClient = useQueryClient()

const resetToWalletSelectionSync = useNavigateToWalletSelectionSync()
const {removeWallet, isLoading: isRemoveWalletLoading} = useRemoveWallet(wallet.id, {
onSuccess: () => {
resetToWalletSelectionSync()
onSuccess: async () => {
queryClient.invalidateQueries({queryKey: ['hasWallets']})

const walletMetas = await walletManager.listWallets()
const hasWallets = walletMetas.length > 0

if (hasWallets) {
resetToWalletSelection()
return
}

resetToWalletSetup()
},
})

Expand Down Expand Up @@ -140,6 +155,19 @@ const messages = defineMessages({
},
})

export const whetherHasWallets = async (
walletManager: WalletManager,
withWallets: () => void,
withoutWallets: () => void,
) => {
const walletMetas = await walletManager.listWallets()
const hasWallets = walletMetas.length > 0

if (hasWallets) return withWallets()

return withoutWallets()
}

const useStrings = () => {
const intl = useIntl()

Expand Down
20 changes: 0 additions & 20 deletions apps/wallet-mobile/src/navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import {Dimensions, TouchableOpacity, TouchableOpacityProps, ViewStyle} from 're
import {Icon} from './components'
import {ScanFeature} from './features/Scan/common/types'
import {Routes as StakingGovernanceRoutes} from './features/Staking/Governance/common/navigation'
import {useWalletManager} from './wallet-manager/WalletManagerContext'
import {useHasWallets} from './yoroi-wallets/hooks'
import {YoroiUnsignedTx} from './yoroi-wallets/types'

// prettier-ignore
Expand Down Expand Up @@ -536,24 +534,6 @@ export const useWalletNavigation = () => {
} as const).current
}

export const useNavigateToWalletSelectionSync = () => {
const {resetToWalletSetup, resetToWalletSelection} = useWalletNavigation()
const walletManager = useWalletManager()
const {refetch} = useHasWallets(walletManager, {
enabled: false,
onSuccess: (hasWallets) => {
if (hasWallets) {
resetToWalletSelection()
return
}

resetToWalletSetup()
},
})

return refetch
}

export const hideTabBarForRoutes = (route: RouteProp<WalletTabRoutes, 'history'>): ViewStyle | undefined =>
getFocusedRouteNameFromRoute(route)?.startsWith('scan') ||
getFocusedRouteNameFromRoute(route)?.startsWith('swap') ||
Expand Down
80 changes: 40 additions & 40 deletions apps/wallet-mobile/translations/messages/src/WalletNavigator.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,149 +4,149 @@
"defaultMessage": "!!!Transactions",
"file": "src/WalletNavigator.tsx",
"start": {
"line": 239,
"line": 242,
"column": 22,
"index": 8518
"index": 8560
},
"end": {
"line": 242,
"line": 245,
"column": 3,
"index": 8621
"index": 8663
}
},
{
"id": "components.txhistory.txnavigationbuttons.sendButton",
"defaultMessage": "!!!Send",
"file": "src/WalletNavigator.tsx",
"start": {
"line": 243,
"line": 246,
"column": 14,
"index": 8637
"index": 8679
},
"end": {
"line": 246,
"line": 249,
"column": 3,
"index": 8736
"index": 8778
}
},
{
"id": "components.txhistory.txnavigationbuttons.receiveButton",
"defaultMessage": "!!!Receive",
"file": "src/WalletNavigator.tsx",
"start": {
"line": 247,
"line": 250,
"column": 17,
"index": 8755
"index": 8797
},
"end": {
"line": 250,
"line": 253,
"column": 3,
"index": 8860
"index": 8902
}
},
{
"id": "components.common.navigation.dashboardButton",
"defaultMessage": "!!!Dashboard",
"file": "src/WalletNavigator.tsx",
"start": {
"line": 251,
"line": 254,
"column": 19,
"index": 8881
"index": 8923
},
"end": {
"line": 254,
"line": 257,
"column": 3,
"index": 8978
"index": 9020
}
},
{
"id": "components.common.navigation.delegateButton",
"defaultMessage": "!!!Delegate",
"file": "src/WalletNavigator.tsx",
"start": {
"line": 255,
"line": 258,
"column": 18,
"index": 8998
"index": 9040
},
"end": {
"line": 258,
"line": 261,
"column": 3,
"index": 9093
"index": 9135
}
},
{
"id": "components.settings.walletsettingscreen.tabTitle",
"defaultMessage": "!!!Wallet",
"file": "src/WalletNavigator.tsx",
"start": {
"line": 259,
"line": 262,
"column": 16,
"index": 9111
"index": 9153
},
"end": {
"line": 262,
"line": 265,
"column": 3,
"index": 9209
"index": 9251
}
},
{
"id": "global.staking",
"defaultMessage": "!!!Staking",
"file": "src/WalletNavigator.tsx",
"start": {
"line": 263,
"line": 266,
"column": 17,
"index": 9228
"index": 9270
},
"end": {
"line": 266,
"line": 269,
"column": 3,
"index": 9293
"index": 9335
}
},
{
"id": "components.common.navigation.nftGallery",
"defaultMessage": "!!!NFT Gallery",
"file": "src/WalletNavigator.tsx",
"start": {
"line": 267,
"line": 270,
"column": 14,
"index": 9309
"index": 9351
},
"end": {
"line": 270,
"line": 273,
"column": 3,
"index": 9403
"index": 9445
}
},
{
"id": "menu",
"defaultMessage": "!!!Menu",
"file": "src/WalletNavigator.tsx",
"start": {
"line": 271,
"line": 274,
"column": 14,
"index": 9419
"index": 9461
},
"end": {
"line": 274,
"line": 277,
"column": 3,
"index": 9471
"index": 9513
}
},
{
"id": "components.walletselection.walletselectionscreen.header",
"defaultMessage": "!!!My wallets",
"file": "src/WalletNavigator.tsx",
"start": {
"line": 275,
"line": 278,
"column": 31,
"index": 9504
"index": 9546
},
"end": {
"line": 278,
"line": 281,
"column": 3,
"index": 9613
"index": 9655
}
}
]

0 comments on commit 4623b66

Please sign in to comment.