Skip to content

Commit c343d52

Browse files
committed
refactor(wallet-mobile): moving things around
1 parent 016af30 commit c343d52

File tree

28 files changed

+252
-131
lines changed

28 files changed

+252
-131
lines changed

apps/wallet-mobile/src/features/Banners/common/DismissableBanner.tsx apps/wallet-mobile/src/components/DismissableView.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type Props = {
88
style?: Exclude<ViewStyle, 'opacity'>
99
}
1010

11-
export const DismissibleBanner = ({isVisible, children, style, duration = 300}: Props) => {
11+
export const DismissibleView = ({isVisible, children, style, duration = 300}: Props) => {
1212
const fadeAnim = React.useRef(new Animated.Value(0)).current
1313
const [shouldRender, setShouldRender] = React.useState(isVisible)
1414

apps/wallet-mobile/src/features/Banners/common/strings.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
import * as React from 'react'
12
import {defineMessages, useIntl} from 'react-intl'
23

34
export const useStrings = () => {
45
const intl = useIntl()
5-
return {
6+
7+
return React.useRef({
68
description: intl.formatMessage(messages.description),
79
title: intl.formatMessage(messages.title),
810
cta: intl.formatMessage(messages.cta),
9-
}
11+
} as const).current
1012
}
1113

1214
const messages = defineMessages({

apps/wallet-mobile/src/features/Banners/common/types.ts

-5
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
import {action} from '@storybook/addon-actions'
21
import {storiesOf} from '@storybook/react-native'
3-
import React from 'react'
2+
import * as React from 'react'
43

54
import {ConsiderDelegatingToYoroiBanner} from './ConsiderDelegatingToYoroiBanner'
65

7-
storiesOf('components/ConsiderDelegatingToYoroiBanner', module)
8-
.add('Default', () => <ConsiderDelegatingToYoroiBanner onPress={action('onPress')} />)
9-
.add('With Close Button', () => (
10-
<ConsiderDelegatingToYoroiBanner onPress={action('onPress')} onClose={action('onClose')} />
11-
))
6+
storiesOf('components/ConsiderDelegatingToYoroiBanner', module).add('Initial', () => (
7+
<ConsiderDelegatingToYoroiBanner />
8+
))

apps/wallet-mobile/src/features/Banners/useCases/ConsiderDelegatingToYoroiBanner/ConsiderDelegatingToYoroiBanner.tsx

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,35 @@
1-
import {useBanner, useBanners} from '@yoroi/banners'
1+
import {shouldShowDRep2UsOnStakingCenter, useBanner, useBanners} from '@yoroi/banners'
22
import {useTheme} from '@yoroi/theme'
3+
import {Banners} from '@yoroi/types'
34
import * as React from 'react'
45
import {StyleSheet, TouchableOpacity, View} from 'react-native'
56
import LinearGradient from 'react-native-linear-gradient'
67

78
import {Button} from '../../../../components/Button/Button'
9+
import {DismissibleView} from '../../../../components/DismissableView'
810
import {Icon} from '../../../../components/Icon'
911
import {Text} from '../../../../components/Text'
1012
import {yoroiDRepIdHex} from '../../../../kernel/constants'
11-
import {DismissibleBanner} from '../../common/DismissableBanner'
12-
import {shouldShowDRepConsiderDelegating} from '../../common/should-show-drep-consider-delegating'
1313
import {useStrings} from '../../common/strings'
14-
import {BannerId, BannerStorageKey} from '../../common/types'
1514

1615
export const ConsiderDelegatingToYoroiBanner = () => {
1716
const {styles, colors} = useStyles()
1817
const {title, description, cta} = useStrings()
19-
const {manager} = useBanners<BannerStorageKey>()
20-
const {dismiss, dismissedAt} = useBanner({id: BannerId.DRepConsiderDelegating, manager})
18+
const {manager} = useBanners<Banners.StorageKey>()
19+
const {dismiss, dismissedAt} = useBanner({id: Banners.Id.DRep2UsStakingCenter, manager})
2120

2221
const handleOnClose = React.useCallback(() => dismiss(), [dismiss])
2322
const handleOnCta = React.useCallback(() => console.log('cta'), [])
2423

25-
const shouldShow = shouldShowDRepConsiderDelegating({
24+
const shouldShow = shouldShowDRep2UsOnStakingCenter({
2625
yoroiDRepIdHex,
2726
currentDRepIdHex: 'hi',
2827
isStaking: true,
2928
dismissedAt,
3029
})
3130

3231
return (
33-
<DismissibleBanner isVisible={shouldShow}>
32+
<DismissibleView isVisible={shouldShow}>
3433
<LinearGradient start={{x: 1, y: 1}} end={{x: 0, y: 0}} colors={colors.gradient} style={styles.gradient}>
3534
<View style={styles.root}>
3635
<TouchableOpacity onPress={handleOnClose} style={styles.closeButton}>
@@ -44,7 +43,7 @@ export const ConsiderDelegatingToYoroiBanner = () => {
4443
<Button style={styles.cta} type="Secondary" size="S" onPress={handleOnCta} title={cta} />
4544
</View>
4645
</LinearGradient>
47-
</DismissibleBanner>
46+
</DismissibleView>
4847
)
4948
}
5049

apps/wallet-mobile/src/features/Dev/Playground.tsx

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import {bannersManagerMaker, BannersProvider} from '@yoroi/banners'
22
import {observableStorageMaker} from '@yoroi/common'
33
import {useTheme} from '@yoroi/theme'
4+
import {Banners} from '@yoroi/types'
45
import * as React from 'react'
56
import {SafeAreaView} from 'react-native-safe-area-context'
67

78
import {Button} from '../../components/Button/Button'
89
import {Spacer} from '../../components/Spacer/Spacer'
910
import {logger} from '../../kernel/logger/logger'
10-
import {BannerId, BannerStorageKey} from '../Banners/common/types'
1111
import {ConsiderDelegatingToYoroiBanner} from '../Banners/useCases/ConsiderDelegatingToYoroiBanner/ConsiderDelegatingToYoroiBanner'
1212
import {useSelectedWallet} from '../WalletManager/common/hooks/useSelectedWallet'
1313

@@ -20,15 +20,15 @@ export const Playground = () => {
2020
} = useTheme()
2121
const {wallet} = useSelectedWallet()
2222
const walletStorage = wallet.networkManager.rootStorage.join(`${wallet.id}/`)
23-
const bannersStorage = observableStorageMaker<false, BannerStorageKey>(walletStorage.join('banners/'))
24-
const bannersManager = bannersManagerMaker<BannerStorageKey>({
23+
const bannersStorage = observableStorageMaker<false, Banners.StorageKey>(walletStorage.join('banners/'))
24+
const bannersManager = bannersManagerMaker<Banners.StorageKey>({
2525
storage: bannersStorage,
2626
})
2727
const [refresh, setRefresh] = React.useState(0)
2828

29-
bannersStorage.onChange([BannerId.DRepConsiderDelegating], () => {
30-
logger.debug(`BannersStorageKey ${BannerId.DRepConsiderDelegating}:`, {
31-
dismissedAt: bannersManager.dismissedAt(BannerId.DRepConsiderDelegating),
29+
bannersStorage.onChange([Banners.Id.DRep2UsStakingCenter], () => {
30+
logger.debug(`BannersStorageKey ${Banners.Id.DRep2UsStakingCenter}:`, {
31+
dismissedAt: bannersManager.dismissedAt(Banners.Id.DRep2UsStakingCenter),
3232
})
3333
})
3434

@@ -37,7 +37,7 @@ export const Playground = () => {
3737
<Button
3838
title="Reset"
3939
onPress={() => {
40-
bannersStorage.setItem(BannerId.DRepConsiderDelegating, '0')
40+
bannersStorage.setItem(Banners.Id.DRep2UsStakingCenter, '0')
4141
setRefresh(() => refresh + 1)
4242
}}
4343
/>

apps/wallet-mobile/src/features/Notifications/useCases/common/primary-token-price-changed-notification.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import {isRight, useAsyncStorage} from '@yoroi/common'
1+
import {isRight, time, useAsyncStorage} from '@yoroi/common'
22
import {App, Notifications as NotificationTypes} from '@yoroi/types'
33
import * as React from 'react'
44
import {Subject} from 'rxjs'
55

6-
import {time} from '../../../../kernel/constants'
76
import {fetchPtPriceActivity} from '../../../../yoroi-wallets/cardano/usePrimaryTokenActivity'
87
import {getCurrencySymbol} from '../../../Settings/useCases/changeAppSettings/Currency/CurrencyContext'
98
import {useWalletManager} from '../../../WalletManager/context/WalletManagerProvider'

apps/wallet-mobile/src/features/Portfolio/common/MediaDetailsScreen/MediaDetailsScreen.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {RouteProp, useRoute} from '@react-navigation/native'
2-
import {isString} from '@yoroi/common'
2+
import {isString, time} from '@yoroi/common'
33
import {traitValueExpander, usePortfolioTokenDiscovery, usePortfolioTokenTraits} from '@yoroi/portfolio'
44
import {useTheme} from '@yoroi/theme'
55
import {Explorers, Network, Portfolio} from '@yoroi/types'
@@ -24,7 +24,6 @@ import {MediaPreview} from '../../../../components/MediaPreview/MediaPreview'
2424
import {Spacer} from '../../../../components/Spacer/Spacer'
2525
import {Tab, TabPanel, TabPanels, Tabs} from '../../../../components/Tabs/Tabs'
2626
import {Text} from '../../../../components/Text'
27-
import {time} from '../../../../kernel/constants'
2827
import {useMetrics} from '../../../../kernel/metrics/metricsManager'
2928
import {NftRoutes} from '../../../../kernel/navigation'
3029
import {useSelectedWallet} from '../../../WalletManager/common/hooks/useSelectedWallet'

apps/wallet-mobile/src/features/Portfolio/common/PortfolioTokenActivityProvider.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import {invalid, isNonNullable} from '@yoroi/common'
1+
import {invalid, isNonNullable, time} from '@yoroi/common'
22
import {isPrimaryToken} from '@yoroi/portfolio'
33
import {Portfolio} from '@yoroi/types'
44
import {freeze, produce} from 'immer'
55
import React from 'react'
66
import {useQuery, useQueryClient} from 'react-query'
77
import {merge, switchMap} from 'rxjs'
88

9-
import {time} from '../../../kernel/constants'
109
import {logger} from '../../../kernel/logger/logger'
1110
import {queryInfo} from '../../../kernel/query-client'
1211
import {useSelectedNetwork} from '../../WalletManager/common/hooks/useSelectedNetwork'

apps/wallet-mobile/src/features/Portfolio/common/hooks/useGetPortfolioTokenChart.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import {networkConfigs} from '@yoroi/blockchains'
2-
import {isRight} from '@yoroi/common'
2+
import {isRight, time} from '@yoroi/common'
33
import {isPrimaryToken} from '@yoroi/portfolio'
44
import {Chain, Portfolio} from '@yoroi/types'
55
import {useQuery, UseQueryOptions} from 'react-query'
66

7-
import {supportedCurrencies, time} from '../../../../kernel/constants'
7+
import {supportedCurrencies} from '../../../../kernel/constants'
88
import {useLanguage} from '../../../../kernel/i18n'
99
import {logger} from '../../../../kernel/logger/logger'
1010
import {fetchPtPriceActivity} from '../../../../yoroi-wallets/cardano/usePrimaryTokenActivity'

apps/wallet-mobile/src/features/RegisterCatalyst/common/hooks.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import {time} from '@yoroi/common'
12
import {Catalyst, useCatalyst} from '@yoroi/staking'
23
import {App} from '@yoroi/types'
34
import {useQuery, UseQueryOptions} from 'react-query'
45

5-
import {time} from '../../../kernel/constants'
66
import {throwLoggedError} from '../../../kernel/logger/helpers/throw-logged-error'
77
import {queryInfo} from '../../../kernel/query-client'
88
import {YoroiWallet} from '../../../yoroi-wallets/cardano/types'

apps/wallet-mobile/src/features/ReviewTx/common/TokenDetails.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {time} from '@yoroi/common'
12
import {usePortfolioTokenDiscovery} from '@yoroi/portfolio'
23
import {useTheme} from '@yoroi/theme'
34
import {Portfolio} from '@yoroi/types'
@@ -9,7 +10,6 @@ import {Icon} from '../../../components/Icon'
910
import {MediaPreview} from '../../../components/MediaPreview/MediaPreview'
1011
import {SimpleTab} from '../../../components/SimpleTab/SimpleTab'
1112
import {Space} from '../../../components/Space/Space'
12-
import {time} from '../../../kernel/constants'
1313
import {isEmptyString} from '../../../kernel/utils'
1414
import {useSelectedWallet} from '../../WalletManager/common/hooks/useSelectedWallet'
1515
import {CopiableText} from './CopiableText'

apps/wallet-mobile/src/features/Settings/useCases/changeAppSettings/ChangeNetwork/ChangeNetworkScreen.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {isBoolean, parseSafe, useAsyncStorage, useMutationWithInvalidations} from '@yoroi/common'
1+
import {isBoolean, parseSafe, time, useAsyncStorage, useMutationWithInvalidations} from '@yoroi/common'
22
import {useTheme} from '@yoroi/theme'
33
import React from 'react'
44
import {Platform, StyleSheet, Text, View} from 'react-native'
@@ -10,7 +10,6 @@ import {Button} from '../../../../../components/Button/Button'
1010
import {useModal} from '../../../../../components/Modal/ModalContext'
1111
import {Space} from '../../../../../components/Space/Space'
1212
import {Spacer} from '../../../../../components/Spacer/Spacer'
13-
import {time} from '../../../../../kernel/constants'
1413
import {NetworkPickerList} from './NetworkPickerList'
1514
import {useStrings} from './strings'
1615

apps/wallet-mobile/src/features/WalletManager/common/hooks/useLaunchWalletAfterSyncing.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import {time} from '@yoroi/common'
12
import * as React from 'react'
23

3-
import {time} from '../../../../kernel/constants'
44
import {logger} from '../../../../kernel/logger/logger'
55
import {useWalletNavigation} from '../../../../kernel/navigation'
66
import {YoroiWallet} from '../../../../yoroi-wallets/cardano/types'

apps/wallet-mobile/src/features/WalletManager/wallet-manager.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {walletChecksum} from '@emurgo/cip4-js'
2-
import {difference, parseSafe} from '@yoroi/common'
2+
import {difference, parseSafe, time} from '@yoroi/common'
33
import {Blockies} from '@yoroi/identicon'
44
import {App, Chain, HW, Network, Wallet} from '@yoroi/types'
55
import {freeze} from 'immer'
@@ -17,7 +17,6 @@ import {
1717
} from 'rxjs'
1818
import uuid from 'uuid'
1919

20-
import {time} from '../../kernel/constants'
2120
import {throwLoggedError} from '../../kernel/logger/helpers/throw-logged-error'
2221
import {logger} from '../../kernel/logger/logger'
2322
import {makeWalletEncryptedStorage} from '../../kernel/storage/EncryptedStorage'

apps/wallet-mobile/src/kernel/constants.ts

-20
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,5 @@ export const configCurrencies = freeze({
5858
},
5959
})
6060

61-
export const time = freeze({
62-
oneSecond: 1e3,
63-
oneMinute: 60 * 1e3,
64-
fiveMinutes: 5 * 60 * 1e3,
65-
halfHour: 30 * 60 * 1e3,
66-
oneHour: 60 * 60 * 1e3,
67-
oneDay: 24 * 60 * 60 * 1e3,
68-
oneWeek: 7 * 24 * 60 * 60 * 1e3,
69-
oneMonth: 30 * 24 * 60 * 60 * 1e3,
70-
sixMonths: 182.5 * 24 * 60 * 60 * 1e3,
71-
oneYear: 365 * 24 * 60 * 60 * 1e3,
72-
73-
// helpers
74-
seconds: (seconds: number) => seconds * 1e3,
75-
minutes: (minutes: number) => minutes * 60 * 1e3,
76-
77-
// session here means while the wallet is open
78-
session: Infinity,
79-
})
80-
8161
// NOTE: bech32 'drep1ygr9tuapcanc3kpeyy4dc3vmrz9cfe5q7v9wj3x9j0ap3tswtre9j'
8262
export const yoroiDRepIdHex = '220655f3a1c76788d839212adc459b188b84e680f30ae944c593fa18ae'

apps/wallet-mobile/src/yoroi-wallets/cardano/types.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
TxMetadata as TxMetadataType,
1111
UnsignedTx as UnsignedTxType,
1212
} from '@emurgo/yoroi-lib'
13-
import {Api, App, HW, Network, Portfolio, Wallet} from '@yoroi/types'
13+
import {Api, App, Banners, HW, Network, Portfolio, Wallet} from '@yoroi/types'
1414
import {BigNumber} from 'bignumber.js'
1515

1616
import {WalletEncryptedStorage} from '../../kernel/storage/EncryptedStorage'
@@ -271,3 +271,7 @@ export namespace CardanoTypes {
271271

272272
export {RegistrationStatus} from '@emurgo/yoroi-lib'
273273
export {NoOutputsError, NotEnoughMoneyToSendError} from '@emurgo/yoroi-lib/dist/errors'
274+
275+
export interface WithBanners {
276+
bannersManager: Banners.Manager<Banners.StorageKey>
277+
}

apps/wallet-mobile/src/yoroi-wallets/cardano/usePrimaryTokenActivity.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import {networkConfigs} from '@yoroi/blockchains'
2-
import {fetchData, isRight} from '@yoroi/common'
2+
import {fetchData, isRight, time} from '@yoroi/common'
33
import {Chain} from '@yoroi/types'
44
import {useQuery, UseQueryOptions} from 'react-query'
55

6-
import {time} from '../../kernel/constants'
76
import {queryInfo} from '../../kernel/query-client'
87
import {CurrencySymbol, PriceMultipleResponse} from '../types/other'
98

apps/wallet-mobile/translations/messages/src/features/Banners/common/strings.json

+12-12
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,44 @@
44
"defaultMessage": "!!!Delegate to our DRep and help Cardano evolve in a way that benefits your wallet experience.",
55
"file": "src/features/Banners/common/strings.ts",
66
"start": {
7-
"line": 13,
7+
"line": 15,
88
"column": 15,
9-
"index": 327
9+
"index": 390
1010
},
1111
"end": {
12-
"line": 16,
12+
"line": 18,
1313
"column": 3,
14-
"index": 516
14+
"index": 579
1515
}
1616
},
1717
{
1818
"id": "components.considerDelegatingToYoroiBanner.title",
1919
"defaultMessage": "!!!Consider delegating to Yoroi",
2020
"file": "src/features/Banners/common/strings.ts",
2121
"start": {
22-
"line": 17,
22+
"line": 19,
2323
"column": 9,
24-
"index": 527
24+
"index": 590
2525
},
2626
"end": {
27-
"line": 20,
27+
"line": 22,
2828
"column": 3,
29-
"index": 647
29+
"index": 710
3030
}
3131
},
3232
{
3333
"id": "components.considerDelegatingToYoroiBanner.cta",
3434
"defaultMessage": "!!!Delegate Now",
3535
"file": "src/features/Banners/common/strings.ts",
3636
"start": {
37-
"line": 21,
37+
"line": 23,
3838
"column": 7,
39-
"index": 656
39+
"index": 719
4040
},
4141
"end": {
42-
"line": 24,
42+
"line": 26,
4343
"column": 3,
44-
"index": 758
44+
"index": 821
4545
}
4646
}
4747
]

0 commit comments

Comments
 (0)