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
13 changes: 12 additions & 1 deletion src/components/CollectionPreviewComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -428,11 +428,22 @@ async function renderStamps() {
// Declare a variable to store our new rendered stamps.
const newRenderedStamps: Array<RenderedStamp> = [];

// 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'),
Expand All @@ -442,7 +453,7 @@ async function renderStamps() {
expiry,
wif: wallet.toWif(),
address: wallet.getAddress(),
stampNumber: Number(index + 1).toString(),
stampNumber: Number(stampNumber).toString(),
...globalVariables,
});

Expand Down
26 changes: 25 additions & 1 deletion src/components/CollectionSelectComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@
</q-item-section>
<q-item-section>{{ t('delete') }}</q-item-section>
</q-item>
<q-item clickable v-close-popup @click="onFilterStampsDialog">
<q-item-section avatar>
<q-icon name="filter" />
</q-item-section>
<q-item-section>{{ t('filterStamps') }}</q-item-section>
</q-item>
</q-list>
</q-menu>
</q-btn>
Expand All @@ -56,7 +62,7 @@
</template>

<script setup lang="ts">
import { computed } from 'vue';
import { computed, triggerRef } from 'vue';
import { useQuasar } from 'quasar';
import { useI18n } from 'vue-i18n';

Expand Down Expand Up @@ -254,4 +260,22 @@ async function onShowMnemonicDialog() {
message: activeCollection.value?.mnemonic || t('noStampCollectionSelected'),
});
}

async function onFilterStampsDialog() {
$q.dialog({
title: t('filterStamps'),
message: t('enterListOfStampsNumberToExclude'),
prompt: {
model: activeCollection.value.filterStamps || '',
type: 'textarea',
},
cancel: true,
persistent: true,
}).onOk(async (code: string) => {
// Set the name of the currently active stamp collection.
activeCollection.value.filterStamps = code;

triggerRef(activeCollection);
});
}
</script>
13 changes: 12 additions & 1 deletion src/components/FundingDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,18 @@ async function createFundingTx(): Promise<CashPayServer_Invoice> {
}

// 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,
Expand Down
2 changes: 1 addition & 1 deletion src/templates/V2/Trifold-Minisatoshi/Front.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
and scan the Redeem Key QR!
</p>
<p>Learn more about Bitcoin Cash at:</p>
<p style="font-size: 11px">https://minisatoshi.cash</p>
<p style="font-size: 11px">https://whatisbitcoin.cash</p>
</div>
</div>
<!-- Right Pane -->
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
26 changes: 17 additions & 9 deletions src/utils/wallet-hd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
});
Expand Down Expand Up @@ -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<WalletP2PKH> = [];

let currentIndex = startIndex;
let emptyAddressCount = 0;
let emptyNodes: Array<WalletP2PKH> = [];

// 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<WalletP2PKH> = this.deriveWallets(
addressGap,
Expand All @@ -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;
}
}
Expand Down