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 58a2bfc

Browse files
Merge pull request #5782 from EdgeApp/sam/fix-auto-switching
Add a loading state for rampLastCryptoSelection
2 parents 5f21881 + 4ae1d80 commit 58a2bfc

File tree

3 files changed

+77
-64
lines changed

3 files changed

+77
-64
lines changed

‎src/components/scenes/RampCreateScene.tsx‎

Lines changed: 17 additions & 22 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
@@ -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: 4 additions & 42 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==
@@ -17410,16 +17397,7 @@ string-length@^4.0.2:
1741017397
char-regex "^1.0.2"
1741117398
strip-ansi "^6.0.0"
1741217399

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

17522-
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
17500+
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
1752317501
version "6.0.1"
1752417502
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
1752517503
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
@@ -17533,13 +17511,6 @@ strip-ansi@^5.0.0, strip-ansi@^5.2.0:
1753317511
dependencies:
1753417512
ansi-regex "^4.1.0"
1753517513

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

19232-
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
19203+
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
1923319204
version "7.0.0"
1923419205
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
1923519206
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
@@ -19247,15 +19218,6 @@ wrap-ansi@^6.2.0:
1924719218
string-width "^4.1.0"
1924819219
strip-ansi "^6.0.0"
1924919220

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

0 commit comments

Comments
(0)

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