-
Notifications
You must be signed in to change notification settings - Fork 17
Support multiple address types in wallet handling #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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++) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The change here makes it so that there is a change address shown for every pair receive address. This is a large change in the UI since if you had 20 receive addresses, you'd now see 40 addresses show up, 20 of which are blank.
A simpler change to apply for now is:
|
||
| 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<IAddressData[]>([]); | ||
| const [rawAddresses, setRawAddresses] = useState<IAddressData[]>([]); | ||
| const [_, setRawAddresses] = useState<IAddressData[]>([]); | ||
| const [selectedAddress, setSelectedAddress] = useState<ISelectedAddress | null>(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() { | |
|
|
||
| <Center> | ||
| <Button onClick={generateNewAddress} disabled={!enableGenerate}> | ||
| Generate New Address | ||
| Generate New Addresses | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After applying the fix for maintaining the Change addresses in BIP44 compliant wallets (like in LL) are only ever generated through txs anyway. |
||
| </Button> | ||
| </Center> | ||
| </Tabs.Panel> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, if we're using icons please use
IconArrowBackand also add a tooltip saying it's aChange Address