diff --git a/class/blue-app.ts b/class/blue-app.ts index fd983dc1e..9bd1e798e 100644 --- a/class/blue-app.ts +++ b/class/blue-app.ts @@ -44,6 +44,10 @@ export type TCounterpartyMetadata = { * custom human-readable name we assign ourselves */ label: string; + /** + * some counterparties cannot be deleted because they sent a notif tx onchain, so we just mark them as hidden when user deletes + */ + hidden?: boolean; }; }; diff --git a/loc/en.json b/loc/en.json index d3cf3d62c..2692da545 100644 --- a/loc/en.json +++ b/loc/en.json @@ -634,6 +634,7 @@ "pay_this_contact": "Pay this contact", "rename_contact": "Rename contact", "copy_payment_code": "Copy Payment Code", + "hide_contact": "Hide contact", "rename": "Rename", "provide_name": "Provide new name for this contact", "add_contact": "Add Contact", diff --git a/screen/wallets/PaymentCodesList.tsx b/screen/wallets/PaymentCodesList.tsx index 9bb716e01..ac0841264 100644 --- a/screen/wallets/PaymentCodesList.tsx +++ b/screen/wallets/PaymentCodesList.tsx @@ -34,6 +34,7 @@ enum Actions { pay, rename, copyToClipboard, + hide, } const actionKeys: Action[] = [ @@ -61,6 +62,14 @@ const actionKeys: Action[] = [ iconValue: 'doc.on.doc', }, }, + { + id: Actions.hide, + text: loc.bip47.hide_contact, + icon: { + iconType: 'SYSTEM', + iconValue: 'eye.slash', + }, + }, ]; function onlyUnique(value: any, index: number, self: any[]) { @@ -160,6 +169,17 @@ export default function PaymentCodesList() { _navigateToSend(pc); } + + if (String(id) === String(Actions.hide)) { + if (!(await confirm(loc.wallets.details_are_you_sure))) { + return; + } + + counterpartyMetadata[pc] = { label: counterpartyMetadata?.[pc]?.label ?? '', hidden: true }; + + setReload(Math.random()); + await saveToDisk(); + } }; const _navigateToSend = (pc: string) => { @@ -176,6 +196,8 @@ export default function PaymentCodesList() { }; const renderItem = (pc: string) => { + if (counterpartyMetadata?.[pc]?.hidden) return null; // hidden contact, do not render + const color = createHash('sha256').update(pc).digest().toString('hex').substring(0, 6); const displayName = shortenContactName(counterpartyMetadata?.[pc]?.label ?? pc); @@ -229,6 +251,14 @@ export default function PaymentCodesList() { const foundWallet = wallets.find(w => w.getID() === walletID) as unknown as HDSegwitBech32Wallet; assert(foundWallet, 'Internal error: cant find walletID ' + walletID); + if (counterpartyMetadata[newPc]?.hidden) { + // contact already present, just need to unhide it + counterpartyMetadata[newPc].hidden = false; + await saveToDisk(); + setReload(Math.random()); + return; + } + const cl = new ContactList(); if (!cl.isPaymentCodeValid(newPc)) { @@ -302,6 +332,7 @@ export default function PaymentCodesList() { } catch (_) {} setLoadingText('Fetching transactions...'); await foundWallet.fetchTransactions(); + setLoadingText(''); } };