Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/app/wallet/addresses-tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export default function AddressesTab(props: IAddressesTabProps) {
<Stack className={styles.small} justify='space-between'>
<Text className={styles.address} w={width - 40}>
<AddressText address={row.address} />
{row.addressType === 1 ? ' ↩ ' : null}
Copy link
Owner

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 IconArrowBack and also add a tooltip saying it's a Change Address

</Text>
<Group justify='space-between'>
<Group>
Expand Down
116 changes: 58 additions & 58 deletions src/app/wallet/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Copy link
Owner

Choose a reason for hiding this comment

The 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.

lastReceiveAddress is a value stored in the settings to mark the last receive address used. A different one lastChangeAddress can be used for change addresses.

A simpler change to apply for now is:

  • On initial scan, scan for:
    • Change Addresses, show them first
    • Receive Addresses, show them after
  • On follow-up loads, scan up to the lastChangeAddress and lastReceiveAddress

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 = [];
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -537,7 +537,7 @@ export default function Dashboard() {

<Center>
<Button onClick={generateNewAddress} disabled={!enableGenerate}>
Generate New Address
Generate New Addresses
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After applying the fix for maintaining the lastChangeAddress setting too, revert this back. It's simpler for now to just keep generating the Receive address in this legacy UX.

Change addresses in BIP44 compliant wallets (like in LL) are only ever generated through txs anyway.

</Button>
</Center>
</Tabs.Panel>
Expand Down
Loading