Skip to content

Commit 04f6255

Browse files
committed
Use the new EdgeCurrencyWallet.split method
1 parent fcb0e2a commit 04f6255

4 files changed

Lines changed: 30 additions & 30 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
- changed: Append chain names to token codes in RampCreateScene
2323
- changed: Light mode persistence, theme colors, and images
2424
- changed: ramps: Infinite buy support enabled
25+
- fixed: Handle parallel wallet splits more reliably
2526
- fixed: iOS simulator builds for XCode 26
2627

2728
## 4.42.0 (2025-01-19)

eslint.config.mjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ export default [
248248
'src/components/scenes/CreateWalletAccountSelectScene.tsx',
249249
'src/components/scenes/CreateWalletAccountSetupScene.tsx',
250250
'src/components/scenes/CreateWalletCompletionScene.tsx',
251-
'src/components/scenes/CreateWalletEditNameScene.tsx',
251+
252252
'src/components/scenes/CreateWalletImportOptionsScene.tsx',
253253
'src/components/scenes/CreateWalletImportScene.tsx',
254254

@@ -302,7 +302,6 @@ export default [
302302
'src/components/scenes/SpendingLimitsScene.tsx',
303303
'src/components/scenes/Staking/EarnScene.tsx',
304304

305-
'src/components/scenes/SwapProcessingScene.tsx',
306305
'src/components/scenes/SwapSettingsScene.tsx',
307306
'src/components/scenes/SwapSuccessScene.tsx',
308307
'src/components/scenes/SweepPrivateKeyCalculateFeeScene.tsx',

src/components/scenes/CreateWalletEditNameScene.tsx

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export interface CreateWalletEditNameParams {
4242

4343
interface Props extends EdgeAppSceneProps<'createWalletEditName'> {}
4444

45-
const CreateWalletEditNameComponent = (props: Props) => {
45+
const CreateWalletEditNameComponent: React.FC<Props> = props => {
4646
const { navigation, route } = props
4747
const { createWalletList, splitSourceWalletId } = route.params
4848
const isSplit = splitSourceWalletId != null
@@ -136,25 +136,23 @@ const CreateWalletEditNameComponent = (props: Props) => {
136136
})
137137

138138
const handleSplit = useHandler(async () => {
139-
if (splitSourceWalletId != null) {
140-
for (const item of newWalletItems) {
141-
try {
142-
const splitWalletId = await account.splitWalletInfo(
143-
splitSourceWalletId,
144-
account.currencyConfig[item.pluginId]?.currencyInfo.walletType
145-
)
146-
const splitWallet = await account.waitForCurrencyWallet(splitWalletId)
147-
await splitWallet.renameWallet(walletNames[item.key])
148-
} catch (error: unknown) {
149-
showError(error)
150-
break
151-
}
152-
}
153-
navigation.navigate('edgeTabs', {
154-
screen: 'walletsTab',
155-
params: { screen: 'walletList' }
156-
})
157-
}
139+
if (splitSourceWalletId == null) return
140+
const sourceWallet = account.currencyWallets[splitSourceWalletId]
141+
if (sourceWallet == null) return
142+
143+
const splitItems = newWalletItems.map(item => ({
144+
fiatCurrencyCode: sourceWallet.fiatCurrencyCode,
145+
name: walletNames[item.key],
146+
walletType: account.currencyConfig[item.pluginId].currencyInfo.walletType
147+
}))
148+
const results = await sourceWallet.split(splitItems)
149+
const error = results.find(result => !result.ok)
150+
if (error != null) showError(error.error)
151+
152+
navigation.navigate('edgeTabs', {
153+
screen: 'walletsTab',
154+
params: { screen: 'walletList' }
155+
})
158156
})
159157

160158
const handleImport = useHandler(async () => {

src/components/scenes/SwapProcessingScene.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,21 @@ export const SwapProcessingScene: React.FC<Props> = (props: Props) => {
9898
// If not found, split from the source chain wallet to the destination
9999
// chain wallet type:
100100
isWalletCreated = true
101-
const splitFromWallet = fromWallet
102101
const targetWalletType =
103102
account.currencyConfig[targetPluginId]?.currencyInfo.walletType
104103
if (targetWalletType == null)
105104
throw new Error('Target wallet type unavailable')
106105

107-
const splitWalletId = await account.splitWalletInfo(
108-
splitFromWallet.id,
109-
targetWalletType
110-
)
111-
const newWallet = await account.waitForCurrencyWallet(splitWalletId)
112-
finalToWalletId = newWallet.id
113-
finalToWallet = newWallet
106+
const [result] = await fromWallet.split([
107+
{
108+
fiatCurrencyCode: fromWallet.fiatCurrencyCode,
109+
name: getWalletName(fromWallet),
110+
walletType: targetWalletType
111+
}
112+
])
113+
if (!result.ok) throw result.error
114+
finalToWalletId = result.result.id
115+
finalToWallet = result.result
114116
} else {
115117
finalToWalletId = matchingWalletId
116118
finalToWallet = account.currencyWallets[matchingWalletId]

0 commit comments

Comments
 (0)