From 2cf8def1bd215fb3dc220b432cbf04e80d4c08dd Mon Sep 17 00:00:00 2001
From: James Zuccon
Date: Sat, 17 May 2025 11:05:42 +1000
Subject: [PATCH] feat: Ability to ignore stamp numbers
Signed-off-by: James Zuccon
---
src/components/CollectionPreviewComponent.vue | 13 +++++++++-
src/components/CollectionSelectComponent.vue | 26 ++++++++++++++++++-
src/components/FundingDialog.vue | 13 +++++++++-
.../V2/Trifold-Minisatoshi/Front.html | 2 +-
src/types.ts | 2 ++
src/utils/wallet-hd.ts | 26 ++++++++++++-------
6 files changed, 69 insertions(+), 13 deletions(-)
diff --git a/src/components/CollectionPreviewComponent.vue b/src/components/CollectionPreviewComponent.vue
index 990bfea..e5a051e 100644
--- a/src/components/CollectionPreviewComponent.vue
+++ b/src/components/CollectionPreviewComponent.vue
@@ -428,11 +428,22 @@ async function renderStamps() {
// Declare a variable to store our new rendered stamps.
const newRenderedStamps: Array = [];
+ // Try to compile list of stamps that should be ignored.
+ const ignoreStamps = props.stampCollection.filterStamps ? props.stampCollection.filterStamps.split(/\r?\n/).map((value) => Number(value)) : [];
+
// Iterate over each stamp and render them.
for (const [index, wallet] of props.wallet.wallets.value.entries()) {
// Get the template side we are printing (front or back).
const templateSide = state.activeTemplate[state.showingSide];
+ // Assign the stamp number (indexes start at zero, so we plus one).
+ const stampNumber = index + 1;
+
+ // Filter out any stamps that should be ignored.
+ if(ignoreStamps.includes(stampNumber)) {
+ continue;
+ }
+
// Compile this stamp.
const compiledStamp = await compileTemplate(templateSide, {
valueBch: formatStampValue(wallet.balance.value, 'BCH'),
@@ -442,7 +453,7 @@ async function renderStamps() {
expiry,
wif: wallet.toWif(),
address: wallet.getAddress(),
- stampNumber: Number(index + 1).toString(),
+ stampNumber: Number(stampNumber).toString(),
...globalVariables,
});
diff --git a/src/components/CollectionSelectComponent.vue b/src/components/CollectionSelectComponent.vue
index af8f130..c89b8ff 100644
--- a/src/components/CollectionSelectComponent.vue
+++ b/src/components/CollectionSelectComponent.vue
@@ -48,6 +48,12 @@
{{ t('delete') }}
+
+
+
+
+ {{ t('filterStamps') }}
+
@@ -56,7 +62,7 @@
diff --git a/src/components/FundingDialog.vue b/src/components/FundingDialog.vue
index 1f31bb3..f8f2ec2 100755
--- a/src/components/FundingDialog.vue
+++ b/src/components/FundingDialog.vue
@@ -126,7 +126,18 @@ async function createFundingTx(): Promise {
}
// Add addresses to transaction
- for (const node of props.wallet.wallets.value) {
+ for (const [i, node] of props.wallet.wallets.value.entries()) {
+ // Try to compile list of stamps that should be ignored.
+ const ignoreStamps = props.stampCollection.filterStamps ? props.stampCollection.filterStamps.split(/\r?\n/).map((value) => Number(value)) : [];
+
+ const currentStampNumber = i + 1;
+
+ console.log(i, currentStampNumber);
+
+ if(ignoreStamps.includes(currentStampNumber)) {
+ continue;
+ }
+
const address = node.getAddress();
invoice.addAddress(
address,
diff --git a/src/templates/V2/Trifold-Minisatoshi/Front.html b/src/templates/V2/Trifold-Minisatoshi/Front.html
index 5f3cc74..e60c879 100644
--- a/src/templates/V2/Trifold-Minisatoshi/Front.html
+++ b/src/templates/V2/Trifold-Minisatoshi/Front.html
@@ -28,7 +28,7 @@
and scan the Redeem Key QR!
Learn more about Bitcoin Cash at:
- https://minisatoshi.cash
+ https://whatisbitcoin.cash
diff --git a/src/types.ts b/src/types.ts
index e9967b9..74becc5 100755
--- a/src/types.ts
+++ b/src/types.ts
@@ -32,6 +32,8 @@ export type StampCollection = {
expiry: string;
templateUUID?: string;
templateData?: TemplateData;
+ // A JS callback that can be used to filter stamps.
+ filterStamps?: string;
};
export type CashPayServer_Output = {
diff --git a/src/utils/wallet-hd.ts b/src/utils/wallet-hd.ts
index 77a51b0..dae1b09 100644
--- a/src/utils/wallet-hd.ts
+++ b/src/utils/wallet-hd.ts
@@ -38,7 +38,7 @@ export class WalletHD extends HDPrivateNode {
});
public isFunded = computed(() => {
- return this.wallets.value.every(
+ return this.wallets.value.some(
(node) => node.transactions.value.length > 0
);
});
@@ -124,15 +124,15 @@ export class WalletHD extends HDPrivateNode {
return wallets;
}
- async scan(startIndex = 0, addressGap = 20) {
+ async scan(startIndex = 0, addressGap = 100) {
// Array to store active wallet nodes
const nodes: Array = [];
let currentIndex = startIndex;
- let emptyAddressCount = 0;
+ let emptyNodes: Array = [];
// Continue scanning until we find 'addressGap' consecutive empty addresses
- while (emptyAddressCount < addressGap) {
+ while (emptyNodes.length < addressGap) {
// Derive a number of wallets equivalent to our addressGap.
const batch: Array = this.deriveWallets(
addressGap,
@@ -146,19 +146,27 @@ export class WalletHD extends HDPrivateNode {
// Process the results
for (let i = 0; i < results.length; i++) {
+ // This address has transactions...
if (results[i].length > 0) {
- // This address has transactions, add it to nodes and reset empty address count
+ // And add any empty nodes inbetween to our list of nodes.
+ emptyNodes.forEach((emptyNode) => {
+ nodes.push(emptyNode);
+ });
+
+ // Add it to our list of nodes
nodes.push(batch[i]);
- emptyAddressCount = 0;
+
+ // Reset our list of of empty nodes.
+ emptyNodes = [];
} else {
- // This address is empty, increment the empty address count
- emptyAddressCount++;
+ // This address is empty, add it to our list of empty nodes (as we may want to include it regardless).
+ emptyNodes.push(batch[i]);
}
currentIndex++;
// If we've found 'addressGap' consecutive empty addresses, stop scanning
- if (emptyAddressCount >= addressGap) {
+ if (emptyNodes.length >= addressGap) {
break;
}
}