Skip to content

Commit 646f721

Browse files
authored
Merge pull request #5450 from EdgeApp/jon/wallet-details-header
Jon/wallet-details-header
2 parents 8596b17 + fb946f9 commit 646f721

File tree

11 files changed

+63
-41
lines changed

11 files changed

+63
-41
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
## 4.23.0 (staging)
88

99
- added: Add Abstract ETH Layer 2 support
10+
- changed: `WalletDetailsScene` title shows the name of the network for most use cases
1011
- changed: Force max unstake on Kiln ETH positions
1112
- changed: Disconnect `CryptoIcon` from redux
1213
- changed: Use number math when handling exchange rates

src/actions/FirstOpenActions.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,26 @@ const asFirstOpenInfo = asObject({
1616
type FirstOpenInfo = ReturnType<typeof asFirstOpenInfo>
1717

1818
let firstOpenInfo: FirstOpenInfo
19+
let firstLoadPromise: Promise<FirstOpenInfo> | undefined
1920

2021
/**
2122
* Returns whether this session was the first time the user opened the app.
22-
* Repeated calls will return the same result. Also sets the deviceId &
23-
* firstOpenEpoch
23+
* Repeated calls will return the same result. Initial disk read also sets the
24+
* deviceId & firstOpenEpoch if not already present.
2425
*/
2526
export const getFirstOpenInfo = async (): Promise<FirstOpenInfo> => {
27+
if (firstOpenInfo == null) {
28+
if (firstLoadPromise == null) firstLoadPromise = readFirstOpenInfoFromDisk()
29+
return await firstLoadPromise
30+
}
31+
return firstOpenInfo
32+
}
33+
34+
/**
35+
* Reads firstOpenInfo from disk and sets the deviceId & firstOpenEpoch if not
36+
* already present.
37+
*/
38+
const readFirstOpenInfoFromDisk = async (): Promise<FirstOpenInfo> => {
2639
if (firstOpenInfo == null) {
2740
let firstOpenText
2841
try {
@@ -34,7 +47,7 @@ export const getFirstOpenInfo = async (): Promise<FirstOpenInfo> => {
3447
// Not critical if we can't get the country code
3548
firstOpenInfo.countryCode = await getCountryCodeByIp().catch(() => undefined)
3649
}
37-
} catch (error: any) {
50+
} catch (error: unknown) {
3851
// Generate new values.
3952
firstOpenInfo = {
4053
countryCode: await getCountryCodeByIp(),

src/actions/WalletListMenuActions.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -287,15 +287,9 @@ export function walletListMenuAction(
287287

288288
case 'goToParent': {
289289
return async (dispatch, getState) => {
290-
const state = getState()
291-
const { account } = state.core
292-
const { currencyWallets } = account
293-
const wallet = currencyWallets[walletId]
294-
295290
navigation.navigate('walletDetails', {
296291
walletId,
297-
tokenId: null,
298-
walletName: getWalletName(wallet)
292+
tokenId: null
299293
})
300294
}
301295
}

src/components/Main.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ import { SweepPrivateKeyCompletionScene as SweepPrivateKeyCompletionSceneCompone
126126
import { SweepPrivateKeyProcessingScene as SweepPrivateKeyProcessingSceneComponent } from './scenes/SweepPrivateKeyProcessingScene'
127127
import { SweepPrivateKeySelectCryptoScene as SweepPrivateKeySelectCryptoSceneComponent } from './scenes/SweepPrivateKeySelectCryptoScene'
128128
import { TransactionDetailsScene as TransactionDetailsSceneComponent } from './scenes/TransactionDetailsScene'
129-
import { TransactionList as TransactionListComponent } from './scenes/TransactionListScene'
129+
import { TransactionList as TransactionListComponent, TransactionListTitle } from './scenes/TransactionListScene'
130130
import { TransactionsExportScene as TransactionsExportSceneComponent } from './scenes/TransactionsExportScene'
131131
import { UpgradeUsernameScene as UpgradeUsernameSceneComponent } from './scenes/UpgradeUsernameScreen'
132-
import { WalletDetails as WalletDetailsComponent } from './scenes/WalletDetailsScene'
132+
import { WalletDetails as WalletDetailsComponent, WalletDetailsTitle } from './scenes/WalletDetailsScene'
133133
import { WalletListScene as WalletListSceneComponent } from './scenes/WalletListScene'
134134
import { WalletRestoreScene as WalletRestoreSceneComponent } from './scenes/WalletRestoreScene'
135135
import { WcConnectionsScene as WcConnectionsSceneComponent } from './scenes/WcConnectionsScene'
@@ -277,14 +277,14 @@ const EdgeWalletsTabScreen = () => {
277277
name="transactionList"
278278
component={TransactionList}
279279
options={{
280-
headerTitle: () => <ParamHeaderTitle<'transactionList'> fromParams={params => params.walletName} />
280+
headerTitle: () => <TransactionListTitle />
281281
}}
282282
/>
283283
<WalletsStack.Screen
284284
name="walletDetails"
285285
component={WalletDetails}
286286
options={{
287-
headerTitle: () => <ParamHeaderTitle<'walletDetails'> fromParams={params => params.walletName} />
287+
headerTitle: () => <WalletDetailsTitle />
288288
}}
289289
/>
290290
</WalletsStack.Navigator>
@@ -803,7 +803,7 @@ const EdgeAppStack = () => {
803803
name="transactionList"
804804
component={TransactionList}
805805
options={{
806-
headerTitle: () => <ParamHeaderTitle<'transactionList'> fromParams={params => params.walletName} />
806+
headerTitle: () => <TransactionListTitle />
807807
}}
808808
/>
809809
<AppStack.Screen

src/components/cards/InfoCardCarousel.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { getBuildNumber, getVersion } from 'react-native-device-info'
66
import shajs from 'sha.js'
77

88
import { hideMessageTweak } from '../../actions/AccountReferralActions'
9+
import { getFirstOpenInfo } from '../../actions/FirstOpenActions'
10+
import { useAsyncValue } from '../../hooks/useAsyncValue'
911
import { useHandler } from '../../hooks/useHandler'
1012
import { useIsAccountFunded } from '../../hooks/useIsAccountFunded'
1113
import { useDispatch, useSelector } from '../../types/reactRedux'
@@ -22,16 +24,18 @@ interface Props {
2224
enterAnim: Anim
2325
screenWidth: number
2426
cards?: InfoCard[]
25-
countryCode?: string
2627
}
2728

2829
export const InfoCardCarousel = (props: Props) => {
29-
const { enterAnim, countryCode, navigation, screenWidth, cards } = props
30+
const { enterAnim, navigation, screenWidth, cards } = props
3031
const theme = useTheme()
3132
const dispatch = useDispatch()
3233

3334
const accountReferral = useSelector(state => state.account.accountReferral)
3435

36+
const [firstOpenInfo] = useAsyncValue(async () => await getFirstOpenInfo())
37+
const { countryCode } = firstOpenInfo ?? {}
38+
3539
const [filteredCards, setFilteredCards] = React.useState<FilteredInfoCard[]>([])
3640

3741
// Set account funded status

src/components/scenes/HomeScene.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ export const HomeScene = (props: Props) => {
147147
<InfoCardCarousel
148148
enterAnim={fadeInUp110}
149149
cards={infoServerData.rollup?.promoCards2}
150-
countryCode={countryCode}
151150
navigation={navigation as NavigationBase}
152151
screenWidth={screenWidth}
153152
/>

src/components/scenes/TransactionListScene.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useRoute } from '@react-navigation/native'
12
import { EdgeCurrencyWallet, EdgeTokenId, EdgeTokenMap, EdgeTransaction } from 'edge-core-js'
23
import * as React from 'react'
34
import { ListRenderItemInfo, Platform, RefreshControl, View } from 'react-native'
@@ -13,12 +14,14 @@ import { useWatch } from '../../hooks/useWatch'
1314
import { lstrings } from '../../locales/strings'
1415
import { FooterRender } from '../../state/SceneFooterState'
1516
import { useSceneScrollHandler } from '../../state/SceneScrollState'
16-
import { useDispatch } from '../../types/reactRedux'
17-
import { NavigationBase, WalletsTabSceneProps } from '../../types/routerTypes'
17+
import { useDispatch, useSelector } from '../../types/reactRedux'
18+
import { NavigationBase, RouteProp, WalletsTabSceneProps } from '../../types/routerTypes'
19+
import { getWalletName } from '../../util/CurrencyWalletHelpers'
1820
import { unixToLocaleDateTime } from '../../util/utils'
1921
import { EdgeAnim, MAX_LIST_ITEMS_ANIM } from '../common/EdgeAnim'
2022
import { SceneWrapper } from '../common/SceneWrapper'
2123
import { withWallet } from '../hoc/withWallet'
24+
import { HeaderTitle } from '../navigation/HeaderTitle'
2225
import { cacheStyles, useTheme } from '../services/ThemeContext'
2326
import { ExplorerCard } from '../themed/ExplorerCard'
2427
import { SearchFooter } from '../themed/SearchFooter'
@@ -27,9 +30,7 @@ import { TransactionListRow } from '../themed/TransactionListRow'
2730

2831
export interface TransactionListParams {
2932
walletId: string
30-
walletName: string
3133
tokenId: EdgeTokenId
32-
countryCode?: string
3334
searchText?: string
3435
}
3536

@@ -249,6 +250,14 @@ function TransactionListComponent(props: Props) {
249250
)
250251
}
251252

253+
export const TransactionListTitle = () => {
254+
const route = useRoute<RouteProp<'walletDetails'>>()
255+
const account = useSelector(state => state.core.account)
256+
const wallet = account.currencyWallets[route.params.walletId]
257+
const title = wallet == null ? '' : getWalletName(wallet)
258+
return <HeaderTitle title={title} />
259+
}
260+
252261
/**
253262
* If the token gets deleted, the scene will crash.
254263
* Fall back to the main currency code if this happens.

src/components/scenes/WalletDetailsScene.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import { useRoute } from '@react-navigation/native'
12
import { gt, mul } from 'biggystring'
23
import { EdgeCurrencyWallet, EdgeTokenId, EdgeTokenMap, EdgeTransaction } from 'edge-core-js'
34
import * as React from 'react'
45
import { Platform, RefreshControl, View } from 'react-native'
56
import Reanimated from 'react-native-reanimated'
67
import { AnimatedScrollView } from 'react-native-reanimated/lib/typescript/component/ScrollView'
78
import { useSafeAreaFrame } from 'react-native-safe-area-context'
9+
import { sprintf } from 'sprintf-js'
810

911
import { activateWalletTokens } from '../../actions/WalletActions'
1012
import { SCROLL_INDICATOR_INSET_FIX } from '../../constants/constantSettings'
@@ -21,7 +23,7 @@ import { getExchangeRate } from '../../selectors/WalletSelectors'
2123
import { FooterRender } from '../../state/SceneFooterState'
2224
import { useSceneScrollHandler } from '../../state/SceneScrollState'
2325
import { useDispatch, useSelector } from '../../types/reactRedux'
24-
import { NavigationBase, WalletsTabSceneProps } from '../../types/routerTypes'
26+
import { NavigationBase, RouteProp, WalletsTabSceneProps } from '../../types/routerTypes'
2527
import { coinrankListData, infoServerData } from '../../util/network'
2628
import { calculateSpamThreshold, convertNativeToDenomination, darkenHexColor } from '../../util/utils'
2729
import { EdgeCard } from '../cards/EdgeCard'
@@ -32,6 +34,7 @@ import { fadeInDown10 } from '../common/EdgeAnim'
3234
import { SceneWrapper } from '../common/SceneWrapper'
3335
import { SectionHeader as SectionHeaderUi4 } from '../common/SectionHeader'
3436
import { withWallet } from '../hoc/withWallet'
37+
import { HeaderTitle } from '../navigation/HeaderTitle'
3538
import { cacheStyles, Theme, useTheme } from '../services/ThemeContext'
3639
import { BuyCrypto } from '../themed/BuyCrypto'
3740
import { EdgeText, Paragraph } from '../themed/EdgeText'
@@ -43,9 +46,7 @@ import { TransactionListTop } from '../themed/TransactionListTop'
4346

4447
export interface WalletDetailsParams {
4548
walletId: string
46-
walletName: string
4749
tokenId: EdgeTokenId
48-
countryCode?: string
4950
}
5051

5152
interface Props extends WalletsTabSceneProps<'walletDetails'> {
@@ -281,7 +282,6 @@ function WalletDetailsComponent(props: Props) {
281282
enterAnim={fadeInDown10}
282283
cards={(infoServerData.rollup?.assetStatusCards2 ?? {})[`${pluginId}${tokenId == null ? '' : `_${tokenId}`}`]}
283284
navigation={navigation as NavigationBase}
284-
countryCode={route.params.countryCode}
285285
screenWidth={screenWidth}
286286
/>
287287
{assetId != null && <SectionHeaderUi4 leftTitle={displayName} rightNode={lstrings.coin_rank_see_more} onRightPress={handlePressCoinRanking} />}
@@ -312,7 +312,7 @@ function WalletDetailsComponent(props: Props) {
312312
) : isSearching ? (
313313
<EdgeText style={styles.noResultsText}>{lstrings.transaction_list_search_no_result}</EdgeText>
314314
) : (
315-
<BuyCrypto countryCode={route.params.countryCode} navigation={navigation as NavigationBase} wallet={wallet} tokenId={tokenId} />
315+
<BuyCrypto navigation={navigation as NavigationBase} wallet={wallet} tokenId={tokenId} />
316316
)}
317317
</View>
318318
</Reanimated.ScrollView>
@@ -321,6 +321,14 @@ function WalletDetailsComponent(props: Props) {
321321
)
322322
}
323323

324+
export const WalletDetailsTitle = (params: { customTitle?: string }) => {
325+
const route = useRoute<RouteProp<'walletDetails'>>()
326+
const account = useSelector(state => state.core.account)
327+
const wallet = account.currencyWallets[route.params.walletId]
328+
const title = sprintf(lstrings.create_wallet_account_metadata_name, wallet?.currencyInfo.displayName)
329+
return <HeaderTitle title={title} />
330+
}
331+
324332
const getStyles = cacheStyles((theme: Theme) => ({
325333
txListContainer: {
326334
// A bit less than 5 transaction rows:

src/components/themed/BuyCrypto.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import * as React from 'react'
33
import { View } from 'react-native'
44
import { sprintf } from 'sprintf-js'
55

6+
import { getFirstOpenInfo } from '../../actions/FirstOpenActions'
67
import { DONE_THRESHOLD, SPECIAL_CURRENCY_INFO } from '../../constants/WalletAndCurrencyConstants'
8+
import { useAsyncValue } from '../../hooks/useAsyncValue'
79
import { useHandler } from '../../hooks/useHandler'
810
import { useWatch } from '../../hooks/useWatch'
911
import { toPercentString } from '../../locales/intl'
@@ -21,18 +23,20 @@ interface OwnProps {
2123
wallet: EdgeCurrencyWallet
2224
tokenId: EdgeTokenId
2325
navigation: NavigationBase
24-
countryCode?: string
2526
}
2627

2728
type Props = OwnProps
2829

2930
export const BuyCrypto = (props: Props) => {
30-
const { countryCode, wallet, tokenId, navigation } = props
31+
const { wallet, tokenId, navigation } = props
3132
const theme = useTheme()
3233
const styles = getStyles(theme)
3334

3435
const syncRatio = useWatch(wallet, 'syncRatio')
3536

37+
const [firstOpenInfo] = useAsyncValue(async () => await getFirstOpenInfo())
38+
const { countryCode } = firstOpenInfo ?? {}
39+
3640
const handlePress = useHandler(() => {
3741
navigation.navigate('buyTab', { screen: 'pluginListBuy' })
3842
})

src/components/themed/WalletListSwipeable.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { useMemo } from 'react'
44
import { FlatList, RefreshControl } from 'react-native'
55
import Animated from 'react-native-reanimated'
66

7-
import { getFirstOpenInfo } from '../../actions/FirstOpenActions'
87
import { selectWalletToken } from '../../actions/WalletActions'
98
import { SCROLL_INDICATOR_INSET_FIX } from '../../constants/constantSettings'
109
import { useHandler } from '../../hooks/useHandler'
@@ -75,8 +74,6 @@ function WalletListSwipeableComponent(props: Props) {
7574
)
7675

7776
const handleCreateWallet = useHandler(async (walletId: string, tokenId: EdgeTokenId) => {
78-
const wallet = account.currencyWallets[walletId]
79-
const { countryCode } = await getFirstOpenInfo()
8077
dispatch(
8178
selectWalletToken({
8279
navigation: navigation as NavigationBase,
@@ -89,9 +86,7 @@ function WalletListSwipeableComponent(props: Props) {
8986
activationNotRequired &&
9087
navigation.navigate('walletDetails', {
9188
walletId,
92-
tokenId,
93-
walletName: wallet.name ?? wallet.currencyInfo.displayName,
94-
countryCode
89+
tokenId
9590
})
9691
)
9792
.finally(onReset)

0 commit comments

Comments
 (0)