add helper function for sharing contact

This commit is contained in:
liamcottle 2025-02-15 22:44:54 +13:00
parent e262772fe3
commit 3040bb54a9
2 changed files with 32 additions and 1 deletions

View file

@ -359,7 +359,7 @@
},
async shareContact(contact) {
await this.connection.sendCommandShareContact(contact.publicKey);
await this.connection.shareContact(contact.publicKey);
},
async exportContact(contact) {
try {

View file

@ -788,6 +788,37 @@ class Connection extends EventEmitter {
});
}
shareContact(pubKey) {
return new Promise(async (resolve, reject) => {
try {
// resolve promise when we receive ok
const onOk = (response) => {
this.off(Constants.ResponseCodes.Ok, onOk);
this.off(Constants.ResponseCodes.Err, onErr);
resolve(response);
}
// reject promise when we receive err
const onErr = () => {
this.off(Constants.ResponseCodes.Ok, onOk);
this.off(Constants.ResponseCodes.Err, onErr);
reject();
}
// listen for events
this.once(Constants.ResponseCodes.Ok, onOk);
this.once(Constants.ResponseCodes.Err, onErr);
// share contact
await this.sendCommandShareContact(pubKey);
} catch(e) {
reject(e);
}
});
}
removeContact(pubKey) {
return new Promise(async (resolve, reject) => {
try {