add button to export contact to clipboard as meshcore://<hex> url

This commit is contained in:
liamcottle
2025-02-15 23:58:50 +13:00
parent c433abb9f5
commit fa056987b5
2 changed files with 23 additions and 0 deletions

View File

@@ -41,6 +41,14 @@
<span>Share (Zero Hop Advert)</span> <span>Share (Zero Hop Advert)</span>
</DropDownMenuItem> </DropDownMenuItem>
<!-- export contact button -->
<DropDownMenuItem @click="exportContact(contact)">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="size-5">
<path fill-rule="evenodd" d="M15.75 4.5a3 3 0 1 1 .825 2.066l-8.421 4.679a3.002 3.002 0 0 1 0 1.51l8.421 4.679a3 3 0 1 1-.729 1.31l-8.421-4.678a3 3 0 1 1 0-4.132l8.421-4.679a3 3 0 0 1-.096-.755Z" clip-rule="evenodd" />
</svg>
<span>Export to Clipboard</span>
</DropDownMenuItem>
<!-- reset path button --> <!-- reset path button -->
<DropDownMenuItem @click="onResetPath(contact)"> <DropDownMenuItem @click="onResetPath(contact)">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-5"> <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-5">
@@ -104,6 +112,17 @@ export default {
alert("Failed to share this contact!"); alert("Failed to share this contact!");
} }
}, },
async exportContact(contact) {
try {
const exportedContact = await Connection.exportContact(contact.publicKey);
const advertPacketAsHex = Utils.bytesToHex(exportedContact.advertPacketBytes);
const meshCoreContactUrl = `meshcore://${advertPacketAsHex}`;
await Utils.copyToClipboard(meshCoreContactUrl);
} catch(e) {
console.log(e);
alert("Failed to export this contact!");
}
},
async onResetPath(contact) { async onResetPath(contact) {
// confirm user wants to reset path // confirm user wants to reset path

View File

@@ -195,6 +195,10 @@ class Connection {
await GlobalState.connection.shareContact(publicKey); await GlobalState.connection.shareContact(publicKey);
} }
static async exportContact(publicKey) {
return await GlobalState.connection.exportContact(publicKey);
}
static async sendMessage(publicKey, text) { static async sendMessage(publicKey, text) {
// send message // send message