ADD: option to hide contact

This commit is contained in:
overtorment 2024-06-11 23:18:13 +01:00
parent 9d56d63c8f
commit 6a82c12576
3 changed files with 36 additions and 0 deletions

View file

@ -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;
};
};

View file

@ -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",

View file

@ -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('');
}
};