Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e7d6038

Browse files
Add a loading state for rampLastCryptoSelection
1 parent 6edc8e0 commit e7d6038

File tree

3 files changed

+83
-70
lines changed

3 files changed

+83
-70
lines changed

‎src/components/scenes/RampCreateScene.tsx‎

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
import { FLAG_LOGO_URL } from '../../constants/CdnConstants'
1616
import { COUNTRY_CODES, FIAT_COUNTRY } from '../../constants/CountryConstants'
1717
import { useHandler } from '../../hooks/useHandler'
18+
import { useRampLastCryptoSelection } from '../../hooks/useRampLastCryptoSelection'
1819
import { useRampPlugins } from '../../hooks/useRampPlugins'
1920
import { useRampQuotes } from '../../hooks/useRampQuotes'
2021
import {
@@ -95,9 +96,6 @@ export const RampCreateScene: React.FC<Props> = (props: Props) => {
9596
const rampLastFiatCurrencyCode = useSelector(
9697
state => state.ui.settings.rampLastFiatCurrencyCode
9798
)
98-
const rampLastCryptoSelection = useSelector(
99-
state => state.ui.settings.rampLastCryptoSelection
100-
)
10199

102100
// State for trade form
103101
const [userInput, setUserInput] = useState('')
@@ -112,23 +110,12 @@ export const RampCreateScene: React.FC<Props> = (props: Props) => {
112110
const defaultFiat = useSelector(state => getDefaultFiat(state))
113111
const selectedFiatCurrencyCode = rampLastFiatCurrencyCode ?? defaultFiat
114112

115-
const persistedCryptoSelection = React.useMemo<
116-
WalletListWalletResult | undefined
117-
>(() => {
118-
if (
119-
rampLastCryptoSelection == null ||
120-
currencyWallets[rampLastCryptoSelection.walletId] == null
121-
) {
122-
return undefined
123-
}
124-
return {
125-
type: 'wallet',
126-
walletId: rampLastCryptoSelection.walletId,
127-
tokenId: rampLastCryptoSelection.tokenId
128-
}
129-
}, [currencyWallets, rampLastCryptoSelection])
113+
const {
114+
selection: rampLastCryptoSelection,
115+
isLoading: isLoadingPersistedCryptoSelection
116+
} = useRampLastCryptoSelection()
130117

131-
const selectedCrypto = forcedWalletResult ?? persistedCryptoSelection
118+
const selectedCrypto = forcedWalletResult ?? rampLastCryptoSelection
132119

133120
const [selectedWallet, selectedCryptoCurrencyCode] =
134121
selectedCrypto != null
@@ -513,8 +500,8 @@ export const RampCreateScene: React.FC<Props> = (props: Props) => {
513500
))
514501
if (result?.type === 'wallet') {
515502
if (
516-
rampLastCryptoSelection?.walletId === result.walletId &&
517-
rampLastCryptoSelection?.tokenId === result.tokenId
503+
selectedCrypto?.walletId === result.walletId &&
504+
selectedCrypto?.tokenId === result.tokenId
518505
) {
519506
return
520507
}
@@ -783,7 +770,8 @@ export const RampCreateScene: React.FC<Props> = (props: Props) => {
783770

784771
{/* Bottom Input (Crypto by design) */}
785772
<View style={styles.inputRowView}>
786-
{selectedCryptoCurrencyCode == null ? (
773+
{selectedCryptoCurrencyCode == null &&
774+
!isLoadingPersistedCryptoSelection ? (
787775
<EdgeButton
788776
type="secondary"
789777
onPress={handleCryptDropdown}
@@ -796,7 +784,10 @@ export const RampCreateScene: React.FC<Props> = (props: Props) => {
796784
) : (
797785
<>
798786
<DropdownInputButton onPress={handleCryptDropdown}>
799-
{selectedCrypto == null || selectedWallet == null ? null : (
787+
{isLoadingPersistedCryptoSelection ? (
788+
<ActivityIndicator />
789+
) : selectedCrypto == null ||
790+
selectedWallet == null ? null : (
800791
<CryptoIcon
801792
sizeRem={1.5}
802793
pluginId={selectedWallet?.currencyInfo.pluginId ?? ''}
@@ -817,7 +808,11 @@ export const RampCreateScene: React.FC<Props> = (props: Props) => {
817808
maxDecimals={6}
818809
returnKeyType="done"
819810
showSpinner={isFetchingQuotes && lastUsedInput === 'fiat'}
820-
disabled={isMaxAmount || cryptoInputDisabled}
811+
disabled={
812+
isLoadingPersistedCryptoSelection ||
813+
isMaxAmount ||
814+
cryptoInputDisabled
815+
}
821816
expand
822817
/>
823818
</>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { useQuery } from '@tanstack/react-query'
2+
3+
import type { WalletListWalletResult } from '../components/modals/WalletListModal'
4+
import { useSelector } from '../types/reactRedux'
5+
import { useWatch } from './useWatch'
6+
7+
interface UseRampsPersistedCryptoSelectionResult {
8+
selection?: WalletListWalletResult
9+
isLoading: boolean
10+
}
11+
12+
export const useRampLastCryptoSelection =
13+
(): UseRampsPersistedCryptoSelectionResult => {
14+
const account = useSelector(state => state.core.account)
15+
const currencyWallets = useWatch(account, 'currencyWallets')
16+
17+
const rampLastCryptoSelection = useSelector(
18+
state => state.ui.settings.rampLastCryptoSelection
19+
)
20+
21+
const { data: allWalletsReady = false } = useQuery<boolean>({
22+
queryKey: ['waitForAllWallets', account?.id],
23+
queryFn: async () => {
24+
if (account == null) return false
25+
await account.waitForAllWallets()
26+
return true
27+
},
28+
enabled: account != null,
29+
staleTime: Infinity,
30+
gcTime: 300000,
31+
refetchOnWindowFocus: false
32+
})
33+
34+
if (rampLastCryptoSelection == null) {
35+
return { selection: undefined, isLoading: false }
36+
}
37+
38+
const { walletId, tokenId } = rampLastCryptoSelection
39+
40+
if (currencyWallets[walletId] == null) {
41+
// Before we know wallet readiness, keep loading state true
42+
if (!allWalletsReady) return { selection: undefined, isLoading: true }
43+
// Otherwise we know there is not wallet for the selection (invalid
44+
// selection state).
45+
return { selection: undefined, isLoading: false }
46+
}
47+
48+
return {
49+
selection: {
50+
type: 'wallet',
51+
walletId,
52+
tokenId
53+
},
54+
isLoading: false
55+
}
56+
}

‎yarn.lock‎

Lines changed: 8 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,20 +1063,7 @@
10631063
"@babel/parser" "^7.27.2"
10641064
"@babel/types" "^7.27.1"
10651065

1066-
"@babel/traverse--for-generate-function-map@npm:@babel/traverse@^7.25.3":
1067-
version "7.28.0"
1068-
resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.28.0.tgz#518aa113359b062042379e333db18380b537e34b"
1069-
integrity sha512-mGe7UK5wWyh0bKRfupsUchrQGqvDbZDbKJw+kcRGSmdHVYrv+ltd0pnpDTVpiTqnaBru9iEvA8pz8W46v0Amwg==
1070-
dependencies:
1071-
"@babel/code-frame" "^7.27.1"
1072-
"@babel/generator" "^7.28.0"
1073-
"@babel/helper-globals" "^7.28.0"
1074-
"@babel/parser" "^7.28.0"
1075-
"@babel/template" "^7.27.2"
1076-
"@babel/types" "^7.28.0"
1077-
debug "^4.3.1"
1078-
1079-
"@babel/traverse@^7.25.3", "@babel/traverse@^7.27.1", "@babel/traverse@^7.27.3", "@babel/traverse@^7.28.0", "@babel/traverse@^7.7.0":
1066+
"@babel/traverse--for-generate-function-map@npm:@babel/traverse@^7.25.3", "@babel/traverse@^7.25.3", "@babel/traverse@^7.27.1", "@babel/traverse@^7.27.3", "@babel/traverse@^7.28.0", "@babel/traverse@^7.7.0":
10801067
version "7.28.0"
10811068
resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.28.0.tgz#518aa113359b062042379e333db18380b537e34b"
10821069
integrity sha512-mGe7UK5wWyh0bKRfupsUchrQGqvDbZDbKJw+kcRGSmdHVYrv+ltd0pnpDTVpiTqnaBru9iEvA8pz8W46v0Amwg==
@@ -2127,9 +2114,9 @@
21272114
randombytes "^2.1.0"
21282115
text-encoding "0.7.0"
21292116

2130-
"@fioprotocol/fiosdk@git+https://github.com/jon-edge/fiosdk_typescript.git#92a0fb895b2ce57e5955cd30cb4b7fa2bcc66bf2":
2117+
"@fioprotocol/fiosdk@https://github.com/jon-edge/fiosdk_typescript.git#92a0fb895b2ce57e5955cd30cb4b7fa2bcc66bf2":
21312118
version "1.9.0"
2132-
resolved "git+https://github.com/jon-edge/fiosdk_typescript.git#92a0fb895b2ce57e5955cd30cb4b7fa2bcc66bf2"
2119+
resolved "https://github.com/jon-edge/fiosdk_typescript.git#92a0fb895b2ce57e5955cd30cb4b7fa2bcc66bf2"
21332120
dependencies:
21342121
"@fioprotocol/fiojs" "1.0.1"
21352122
"@types/text-encoding" "0.0.35"
@@ -10648,9 +10635,9 @@ eyes@^0.1.8:
1064810635
resolved "https://registry.yarnpkg.com/eyes/-/eyes-0.1.8.tgz#62cf120234c683785d902348a800ef3e0cc20bc0"
1064910636
integrity sha512-GipyPsXO1anza0AOZdy69Im7hGFCNB7Y/NGjDlZGJ3GJJLtwNSb2vrzYrTYJRrRloVx7pl+bhUaTB8yiccPvFQ==
1065010637

10651-
"eztz.js@git+https://github.com/EdgeApp/eztz.git#edge-fixes":
10638+
"eztz.js@https://github.com/EdgeApp/eztz.git#edge-fixes":
1065210639
version "0.0.1"
10653-
resolved "git+https://github.com/EdgeApp/eztz.git#eefa603586810c3d62f852e7f28cfe57c523b7db"
10640+
resolved "https://github.com/EdgeApp/eztz.git#eefa603586810c3d62f852e7f28cfe57c523b7db"
1065410641
dependencies:
1065510642
bignumber.js "^7.2.1"
1065610643
bip39 "^3.0.2"
@@ -17409,16 +17396,7 @@ string-length@^4.0.2:
1740917396
char-regex "^1.0.2"
1741017397
strip-ansi "^6.0.0"
1741117398

17412-
"string-width-cjs@npm:string-width@^4.2.0":
17413-
version "4.2.3"
17414-
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
17415-
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
17416-
dependencies:
17417-
emoji-regex "^8.0.0"
17418-
is-fullwidth-code-point "^3.0.0"
17419-
strip-ansi "^6.0.1"
17420-
17421-
string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
17399+
"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
1742217400
version "4.2.3"
1742317401
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
1742417402
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -17518,7 +17496,7 @@ stringify-object@^3.3.0:
1751817496
is-obj "^1.0.1"
1751917497
is-regexp "^1.0.0"
1752017498

17521-
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
17499+
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
1752217500
version "6.0.1"
1752317501
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
1752417502
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
@@ -17532,13 +17510,6 @@ strip-ansi@^5.0.0, strip-ansi@^5.2.0:
1753217510
dependencies:
1753317511
ansi-regex "^4.1.0"
1753417512

17535-
strip-ansi@^6.0.0, strip-ansi@^6.0.1:
17536-
version "6.0.1"
17537-
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
17538-
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
17539-
dependencies:
17540-
ansi-regex "^5.0.1"
17541-
1754217513
strip-ansi@^7.0.0, strip-ansi@^7.0.1:
1754317514
version "7.1.0"
1754417515
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45"
@@ -19228,7 +19199,7 @@ wordwrapjs@^4.0.0:
1922819199
reduce-flatten "^2.0.0"
1922919200
typical "^5.2.0"
1923019201

19231-
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
19202+
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
1923219203
version "7.0.0"
1923319204
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
1923419205
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
@@ -19246,15 +19217,6 @@ wrap-ansi@^6.2.0:
1924619217
string-width "^4.1.0"
1924719218
strip-ansi "^6.0.0"
1924819219

19249-
wrap-ansi@^7.0.0:
19250-
version "7.0.0"
19251-
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
19252-
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
19253-
dependencies:
19254-
ansi-styles "^4.0.0"
19255-
string-width "^4.1.0"
19256-
strip-ansi "^6.0.0"
19257-
1925819220
wrap-ansi@^8.1.0:
1925919221
version "8.1.0"
1926019222
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /