From 34492e36aa0deaeb4479853e286e173a63496815 Mon Sep 17 00:00:00 2001 From: lAmeR1 Date: Mon, 20 Oct 2025 22:02:02 +0200 Subject: [PATCH] Support multiple address types in wallet handling Extended wallet logic to manage both receive and change address types. Updated address generation, display, and callbacks to distinguish between the two types. Improved error handling and adjusted state updates accordingly. --- src/app/wallet/addresses-tab.tsx | 1 + src/app/wallet/page.tsx | 116 +++++++++++++++---------------- 2 files changed, 59 insertions(+), 58 deletions(-) diff --git a/src/app/wallet/addresses-tab.tsx b/src/app/wallet/addresses-tab.tsx index 8d1c34f..02a979d 100644 --- a/src/app/wallet/addresses-tab.tsx +++ b/src/app/wallet/addresses-tab.tsx @@ -54,6 +54,7 @@ export default function AddressesTab(props: IAddressesTabProps) { + {row.addressType === 1 ? ' ↩ ' : null} diff --git a/src/app/wallet/page.tsx b/src/app/wallet/page.tsx index 17b684c..1e0ffa6 100644 --- a/src/app/wallet/page.tsx +++ b/src/app/wallet/page.tsx @@ -154,24 +154,25 @@ async function loadOrScanAddressBatch(bip32, callback, callbackSetRawAddresses, } for (let addressIndex = 0; addressIndex <= lastReceiveIndex; addressIndex++) { - const addressType = 0; // Receive - const derivationPath = `44'/111111'/0'/${addressType}/${addressIndex}`; - const address = bip32.getAddress(addressType, addressIndex); - const receiveAddress = { - key: address, - address, - derivationPath, - balance: 0, - loading: true, - addressIndex, - addressType, - utxos: [], - }; - - rawAddresses.push(receiveAddress); - - callbackSetRawAddresses(rawAddresses); - callback(rawAddresses.filter(addressFilter(lastReceiveIndex))); + for (let addressType = 0; addressType <= 1; addressType++) { + const derivationPath = `44'/111111'/0'/${addressType}/${addressIndex}`; + const address = bip32.getAddress(addressType, addressIndex); + const receiveAddress = { + key: address, + address, + derivationPath, + balance: 0, + loading: true, + addressIndex, + addressType, + utxos: [], + }; + + rawAddresses.push(receiveAddress); + + callbackSetRawAddresses(rawAddresses); + callback(rawAddresses.filter(addressFilter(lastReceiveIndex))); + } } let promises = []; @@ -271,7 +272,7 @@ function getDemoXPub() { export default function Dashboard() { const [addresses, setAddresses] = useState([]); - const [rawAddresses, setRawAddresses] = useState([]); + const [_, setRawAddresses] = useState([]); const [selectedAddress, setSelectedAddress] = useState(null); const [activeTab, setActiveTab] = useState('addresses'); const [isTransportInitialized, setTransportInitialized] = useState(false); @@ -288,47 +289,46 @@ export default function Dashboard() { setEnableGenerate(false); try { const newReceiveAddressIndex = userSettings.getSetting('lastReceiveIndex') + 1; + for (let addressType = 0; addressType <= 1; addressType++) { + const derivationPath = `44'/111111'/0'/${addressType}/${newReceiveAddressIndex}`; + const { address } = + deviceType === 'demo' + ? { address: bip32base.getAddress(addressType, newReceiveAddressIndex) } + : await getAddress(derivationPath); + const rawAddress: IAddressData = { + key: address, + derivationPath, + address, + addressType: addressType, + addressIndex: newReceiveAddressIndex, + balance: 0, + loading: true, + utxos: [], + }; + + userSettings.setSetting('lastReceiveIndex', newReceiveAddressIndex); - const derivationPath = `44'/111111'/0'/0/${newReceiveAddressIndex}`; - const { address } = - deviceType === 'demo' - ? { address: bip32base.getAddress(0, newReceiveAddressIndex) } - : await getAddress(derivationPath); - const rawAddress: IAddressData = { - key: address, - derivationPath, - address, - addressType: 0, - addressIndex: newReceiveAddressIndex, - balance: 0, - loading: true, - utxos: [], - }; - - setRawAddresses([...rawAddresses, rawAddress]); - setAddresses([...rawAddresses, rawAddress]); - userSettings.setSetting('lastReceiveIndex', newReceiveAddressIndex); - - try { - if (deviceType === 'demo') { - rawAddress.balance = Math.round(Math.random() * 10000); - await delay(Math.round(Math.random() * 3000)).then(() => { - rawAddress.loading = false; + try { + if (deviceType === 'demo') { + rawAddress.balance = Math.round(Math.random() * 10000); + await delay(Math.round(Math.random() * 3000)).then(() => { + rawAddress.loading = false; + }); + } else { + await loadAddressDetails(rawAddress); + } + + setRawAddresses((rawAddresses) => [...rawAddresses, rawAddress]); + setAddresses((rawAddresses) => [...rawAddresses, rawAddress]); + } catch (e) { + console.error(e); + notifications.show({ + title: 'Error', + message: 'Unable to load address details. Refresh the page to retry.', + autoClose: false, + color: 'red', }); - } else { - await loadAddressDetails(rawAddress); } - - setRawAddresses([...rawAddresses, rawAddress]); - setAddresses([...rawAddresses, rawAddress]); - } catch (e) { - console.error(e); - notifications.show({ - title: 'Error', - message: 'Unable to load address details. Refresh the page to retry.', - autoClose: false, - color: 'red', - }); } } catch (e) { console.info(e); @@ -537,7 +537,7 @@ export default function Dashboard() {