From 3534bdcca84f2a73b4d3a8cb91f34dae47b8a77c Mon Sep 17 00:00:00 2001 From: Matthew Date: Mon, 19 May 2025 14:39:45 -0700 Subject: [PATCH 1/2] Render custom token template rows at the top of the edit token scene Specifically, if a field called "contractAddress' exists put it at the top --- src/components/scenes/EditTokenScene.tsx | 50 +++++++++++++----------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/src/components/scenes/EditTokenScene.tsx b/src/components/scenes/EditTokenScene.tsx index 752d19529f3..d0c616bfa73 100644 --- a/src/components/scenes/EditTokenScene.tsx +++ b/src/components/scenes/EditTokenScene.tsx @@ -187,10 +187,38 @@ function EditTokenSceneComponent(props: Props) { } }) + const renderCustomTokenTemplateRows = () => { + return customTokenTemplate + .sort((a, b) => (a.key === 'contractAddress' ? -1 : 1)) + .map(item => { + if (item.type === 'nativeAmount') return null + return ( + + setLocation(location => { + const out = new Map(location) + out.set(item.key, value.replace(/\s/g, '')) + return out + }) + } + /> + ) + }) + } + return ( + {renderCustomTokenTemplateRows()} - {customTokenTemplate.map(item => { - if (item.type === 'nativeAmount') return null - return ( - - setLocation(location => { - const out = new Map(location) - out.set(item.key, value.replace(/\s/g, '')) - return out - }) - } - /> - ) - })} Date: Mon, 19 May 2025 14:52:31 -0700 Subject: [PATCH 2/2] Add auto-complete to EditTokenScene --- CHANGELOG.md | 1 + src/components/scenes/EditTokenScene.tsx | 42 ++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 68afb491c55..9649879f6d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - added: Add eCash. - added: Thorchain TCY stake and unstake - added: Add Fantom to Sonic bridge +- added: Use `getTokenDetails` to auto-complete fields in `EditTokenScene` - added: Toast notifications for PIN changes. - added: Scam warning to camera access request modal - changed: Auto launch QR scanner for multi-out payments if previously used diff --git a/src/components/scenes/EditTokenScene.tsx b/src/components/scenes/EditTokenScene.tsx index d0c616bfa73..71b65831256 100644 --- a/src/components/scenes/EditTokenScene.tsx +++ b/src/components/scenes/EditTokenScene.tsx @@ -70,6 +70,10 @@ function EditTokenSceneComponent(props: Props) { return out }) + // Keep track of whether we auto-completed a token: + const [didAutoCompleteToken, setDidAutoCompleteToken] = React.useState(false) + const isAutoCompleteTokenLoading = React.useRef(false) + const handleDelete = useHandler(async () => { if (tokenId == null) return await Airship.show<'ok' | 'cancel' | undefined>(bridge => ( @@ -187,6 +191,36 @@ function EditTokenSceneComponent(props: Props) { } }) + const autoCompleteToken = async (searchString: string) => { + if ( + // Ignore autocomplete if it's already loading + isAutoCompleteTokenLoading.current || + // and ggnore autocomplete if the scene was initialized with any of the token details prefilled, + route.params.currencyCode != null || + route.params.displayName != null || + route.params.multiplier != null || + route.params.networkLocation != null + ) { + return + } + + isAutoCompleteTokenLoading.current = true + const [token] = await wallet.currencyConfig.getTokenDetails({ contractAddress: searchString }).catch(() => []) + isAutoCompleteTokenLoading.current = false + + if (token != null) { + setCurrencyCode(token.currencyCode) + setDisplayName(token.displayName) + setDecimalPlaces((token.denominations[0].multiplier.length - 1).toString()) + setDidAutoCompleteToken(true) + } else if (token == null && didAutoCompleteToken) { + setCurrencyCode('') + setDisplayName('') + setDecimalPlaces('18') + setDidAutoCompleteToken(false) + } + } + const renderCustomTokenTemplateRows = () => { return customTokenTemplate .sort((a, b) => (a.key === 'contractAddress' ? -1 : 1)) @@ -202,13 +236,17 @@ function EditTokenSceneComponent(props: Props) { placeholder={translateDescription(item.displayName)} keyboardType={item.type === 'number' ? 'numeric' : 'default'} value={location.get(item.key) ?? ''} - onChangeText={value => + onChangeText={value => { setLocation(location => { const out = new Map(location) out.set(item.key, value.replace(/\s/g, '')) return out }) - } + + if (item.key === 'contractAddress') { + autoCompleteToken(value).catch(() => {}) + } + }} /> ) })