format file
This commit is contained in:
parent
8bc0161a70
commit
fb9da8d1d4
@ -453,8 +453,8 @@ class WebBrowser extends LitElement {
|
|||||||
console.log('UI received event: ' + JSON.stringify(data));
|
console.log('UI received event: ' + JSON.stringify(data));
|
||||||
|
|
||||||
switch (data.action) {
|
switch (data.action) {
|
||||||
case 'GET_USER_ACCOUNT':
|
case 'GET_USER_ACCOUNT':
|
||||||
case actions.GET_USER_ACCOUNT:
|
case actions.GET_USER_ACCOUNT:
|
||||||
const res1 = await showModalAndWait(
|
const res1 = await showModalAndWait(
|
||||||
actions.GET_USER_ACCOUNT
|
actions.GET_USER_ACCOUNT
|
||||||
);
|
);
|
||||||
@ -573,139 +573,139 @@ class WebBrowser extends LitElement {
|
|||||||
window.crypto.getRandomValues(_reference);
|
window.crypto.getRandomValues(_reference);
|
||||||
let reference = window.parent.Base58.encode(_reference);
|
let reference = window.parent.Base58.encode(_reference);
|
||||||
const sendMessageRequest = async () => {
|
const sendMessageRequest = async () => {
|
||||||
let chatResponse = await parentEpml.request('chat', {
|
let chatResponse = await parentEpml.request('chat', {
|
||||||
type: 18,
|
type: 18,
|
||||||
nonce: this.selectedAddress.nonce,
|
nonce: this.selectedAddress.nonce,
|
||||||
params: {
|
params: {
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
recipient: recipient,
|
recipient: recipient,
|
||||||
recipientPublicKey: this._publicKey.key,
|
recipientPublicKey: this._publicKey.key,
|
||||||
hasChatReference: 0,
|
hasChatReference: 0,
|
||||||
chatReference: chatReference,
|
chatReference: chatReference,
|
||||||
message: messageText,
|
message: messageText,
|
||||||
lastReference: reference,
|
lastReference: reference,
|
||||||
proofOfWorkNonce: 0,
|
proofOfWorkNonce: 0,
|
||||||
isEncrypted: 1,
|
isEncrypted: 1,
|
||||||
isText: 1
|
isText: 1
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const msgResponse = await _computePow(chatResponse)
|
const msgResponse = await _computePow(chatResponse)
|
||||||
return msgResponse;
|
return msgResponse;
|
||||||
};
|
};
|
||||||
|
|
||||||
const _computePow = async (chatBytes) => {
|
const _computePow = async (chatBytes) => {
|
||||||
const difficulty = 8;
|
const difficulty = 8;
|
||||||
const path = window.parent.location.origin + '/memory-pow/memory-pow.wasm.full'
|
const path = window.parent.location.origin + '/memory-pow/memory-pow.wasm.full'
|
||||||
const worker = new WebWorkerChat();
|
const worker = new WebWorkerChat();
|
||||||
let nonce = null;
|
let nonce = null;
|
||||||
let chatBytesArray = null;
|
let chatBytesArray = null;
|
||||||
|
|
||||||
await new Promise((res) => {
|
await new Promise((res) => {
|
||||||
worker.postMessage({chatBytes, path, difficulty});
|
worker.postMessage({ chatBytes, path, difficulty });
|
||||||
worker.onmessage = e => {
|
worker.onmessage = e => {
|
||||||
chatBytesArray = e.data.chatBytesArray;
|
chatBytesArray = e.data.chatBytesArray;
|
||||||
nonce = e.data.nonce;
|
nonce = e.data.nonce;
|
||||||
res();
|
res();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let _response = await parentEpml.request('sign_chat', {
|
let _response = await parentEpml.request('sign_chat', {
|
||||||
nonce: this.selectedAddress.nonce,
|
nonce: this.selectedAddress.nonce,
|
||||||
chatBytesArray: chatBytesArray,
|
chatBytesArray: chatBytesArray,
|
||||||
chatNonce: nonce
|
chatNonce: nonce
|
||||||
});
|
});
|
||||||
|
|
||||||
const chatResponse = getSendChatResponse(_response);
|
const chatResponse = getSendChatResponse(_response);
|
||||||
return chatResponse;
|
return chatResponse;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getSendChatResponse = (res) => {
|
const getSendChatResponse = (res) => {
|
||||||
if (res === true) {
|
if (res === true) {
|
||||||
let successString = get("browserpage.bchange23");
|
let successString = get("browserpage.bchange23");
|
||||||
parentEpml.request('showSnackBar', `${successString}`);
|
parentEpml.request('showSnackBar', `${successString}`);
|
||||||
} else if (res.error) {
|
} else if (res.error) {
|
||||||
parentEpml.request('showSnackBar', res.message);
|
parentEpml.request('showSnackBar', res.message);
|
||||||
}
|
}
|
||||||
this.loader.hide();
|
this.loader.hide();
|
||||||
return res;
|
return res;
|
||||||
};
|
};
|
||||||
|
|
||||||
const chatResponse = await sendMessageRequest();
|
const chatResponse = await sendMessageRequest();
|
||||||
return chatResponse;
|
return chatResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await showModalAndWait(
|
const result = await showModalAndWait(
|
||||||
actions.SEND_CHAT_MESSAGE
|
actions.SEND_CHAT_MESSAGE
|
||||||
);
|
);
|
||||||
if (result.action === "accept") {
|
if (result.action === "accept") {
|
||||||
let hasPublicKey = true;
|
let hasPublicKey = true;
|
||||||
const res = await parentEpml.request('apiCall', {
|
const res = await parentEpml.request('apiCall', {
|
||||||
type: 'api',
|
type: 'api',
|
||||||
url: `/addresses/publickey/${recipient}`
|
url: `/addresses/publickey/${recipient}`
|
||||||
});
|
});
|
||||||
|
|
||||||
if (res.error === 102) {
|
if (res.error === 102) {
|
||||||
this._publicKey.key = ''
|
this._publicKey.key = ''
|
||||||
this._publicKey.hasPubKey = false
|
this._publicKey.hasPubKey = false
|
||||||
hasPublicKey = false;
|
hasPublicKey = false;
|
||||||
} else if (res !== false) {
|
} else if (res !== false) {
|
||||||
this._publicKey.key = res
|
this._publicKey.key = res
|
||||||
this._publicKey.hasPubKey = true
|
this._publicKey.hasPubKey = true
|
||||||
} else {
|
} else {
|
||||||
this._publicKey.key = ''
|
this._publicKey.key = ''
|
||||||
this._publicKey.hasPubKey = false
|
this._publicKey.hasPubKey = false
|
||||||
hasPublicKey = false;
|
hasPublicKey = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hasPublicKey) {
|
if (!hasPublicKey) {
|
||||||
let err4string = get("chatpage.cchange39");
|
let err4string = get("chatpage.cchange39");
|
||||||
parentEpml.request('showSnackBar', `${err4string}`)
|
parentEpml.request('showSnackBar', `${err4string}`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
this.loader.show();
|
this.loader.show();
|
||||||
|
|
||||||
const tiptapJson = {
|
const tiptapJson = {
|
||||||
type: 'doc',
|
type: 'doc',
|
||||||
content: [
|
content: [
|
||||||
{
|
{
|
||||||
type: 'paragraph',
|
type: 'paragraph',
|
||||||
content: [
|
content: [
|
||||||
{
|
{
|
||||||
type: 'text',
|
type: 'text',
|
||||||
text: message,
|
text: message,
|
||||||
},
|
},
|
||||||
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
const messageObject = {
|
const messageObject = {
|
||||||
messageText: tiptapJson,
|
messageText: tiptapJson,
|
||||||
images: [''],
|
images: [''],
|
||||||
repliedTo: '',
|
repliedTo: '',
|
||||||
version: 2
|
version: 2
|
||||||
};
|
};
|
||||||
|
|
||||||
const stringifyMessageObject = JSON.stringify(messageObject);
|
const stringifyMessageObject = JSON.stringify(messageObject);
|
||||||
// if (this.balance < 4) {
|
// if (this.balance < 4) {
|
||||||
// this.myTrimmedMeassage = ''
|
// this.myTrimmedMeassage = ''
|
||||||
// this.myTrimmedMeassage = stringifyMessageObject
|
// this.myTrimmedMeassage = stringifyMessageObject
|
||||||
// this.shadowRoot.getElementById('confirmDialog').open()
|
// this.shadowRoot.getElementById('confirmDialog').open()
|
||||||
// } else {
|
// } else {
|
||||||
// this.sendMessage(stringifyMessageObject, typeMessage);
|
// this.sendMessage(stringifyMessageObject, typeMessage);
|
||||||
// }
|
// }
|
||||||
try {
|
try {
|
||||||
const msgResponse = await sendMessage(stringifyMessageObject);
|
const msgResponse = await sendMessage(stringifyMessageObject);
|
||||||
response = msgResponse;
|
response = msgResponse;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
return '{"error": "Request could not be fulfilled"}';
|
return '{"error": "Request could not be fulfilled"}';
|
||||||
} finally {
|
} finally {
|
||||||
this.loader.hide();
|
this.loader.hide();
|
||||||
console.log("Case completed.");
|
console.log("Case completed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
response = '{"error": "User declined request"}';
|
response = '{"error": "User declined request"}';
|
||||||
@ -823,85 +823,85 @@ class WebBrowser extends LitElement {
|
|||||||
// TODO: prompt user to share wallet balance. If they confirm, call `GET /crosschain/:coin/walletbalance`, or for QORT, call `GET /addresses/balance/:address`
|
// TODO: prompt user to share wallet balance. If they confirm, call `GET /crosschain/:coin/walletbalance`, or for QORT, call `GET /addresses/balance/:address`
|
||||||
// then set the response string from the core to the `response` variable (defined above)
|
// then set the response string from the core to the `response` variable (defined above)
|
||||||
// If they decline, send back JSON that includes an `error` key, such as `{"error": "User declined request"}`
|
// If they decline, send back JSON that includes an `error` key, such as `{"error": "User declined request"}`
|
||||||
const res3 = await showModalAndWait(
|
const res3 = await showModalAndWait(
|
||||||
actions.GET_WALLET_BALANCE
|
actions.GET_WALLET_BALANCE
|
||||||
);
|
);
|
||||||
if (res3.action === 'accept') {
|
if (res3.action === 'accept') {
|
||||||
let coin = data.coin;
|
let coin = data.coin;
|
||||||
if (coin === "QORT") {
|
if (coin === "QORT") {
|
||||||
let qortAddress = window.parent.reduxStore.getState().app.selectedAddress.address
|
let qortAddress = window.parent.reduxStore.getState().app.selectedAddress.address
|
||||||
try {
|
try {
|
||||||
this.loader.show();
|
this.loader.show();
|
||||||
const QORTBalance = await parentEpml.request('apiCall', {
|
const QORTBalance = await parentEpml.request('apiCall', {
|
||||||
url: `/addresses/balance/${qortAddress}?apiKey=${this.getApiKey()}`,
|
url: `/addresses/balance/${qortAddress}?apiKey=${this.getApiKey()}`,
|
||||||
})
|
})
|
||||||
return QORTBalance;
|
return QORTBalance;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
const data = {};
|
const data = {};
|
||||||
const errorMsg = error.message || get("browserpage.bchange21");
|
const errorMsg = error.message || get("browserpage.bchange21");
|
||||||
data['error'] = errorMsg;
|
data['error'] = errorMsg;
|
||||||
response = JSON.stringify(data);
|
response = JSON.stringify(data);
|
||||||
return;
|
return;
|
||||||
} finally {
|
} finally {
|
||||||
this.loader.hide();
|
this.loader.hide();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let _url = ``
|
let _url = ``
|
||||||
let _body = null
|
let _body = null
|
||||||
|
|
||||||
switch (coin) {
|
switch (coin) {
|
||||||
case 'LTC':
|
case 'LTC':
|
||||||
_url = `/crosschain/ltc/walletbalance?apiKey=${this.getApiKey()}`
|
_url = `/crosschain/ltc/walletbalance?apiKey=${this.getApiKey()}`
|
||||||
_body = window.parent.reduxStore.getState().app.selectedAddress.ltcWallet.derivedMasterPublicKey
|
_body = window.parent.reduxStore.getState().app.selectedAddress.ltcWallet.derivedMasterPublicKey
|
||||||
break
|
break
|
||||||
case 'DOGE':
|
case 'DOGE':
|
||||||
_url = `/crosschain/doge/walletbalance?apiKey=${this.getApiKey()}`
|
_url = `/crosschain/doge/walletbalance?apiKey=${this.getApiKey()}`
|
||||||
_body = window.parent.reduxStore.getState().app.selectedAddress.dogeWallet.derivedMasterPublicKey
|
_body = window.parent.reduxStore.getState().app.selectedAddress.dogeWallet.derivedMasterPublicKey
|
||||||
break
|
break
|
||||||
case 'DGB':
|
case 'DGB':
|
||||||
_url = `/crosschain/dgb/walletbalance?apiKey=${this.getApiKey()}`
|
_url = `/crosschain/dgb/walletbalance?apiKey=${this.getApiKey()}`
|
||||||
_body = window.parent.reduxStore.getState().app.selectedAddress.dgbWallet.derivedMasterPublicKey
|
_body = window.parent.reduxStore.getState().app.selectedAddress.dgbWallet.derivedMasterPublicKey
|
||||||
break
|
break
|
||||||
case 'RVN':
|
case 'RVN':
|
||||||
_url = `/crosschain/rvn/walletbalance?apiKey=${this.getApiKey()}`
|
_url = `/crosschain/rvn/walletbalance?apiKey=${this.getApiKey()}`
|
||||||
_body = window.parent.reduxStore.getState().app.selectedAddress.rvnWallet.derivedMasterPublicKey
|
_body = window.parent.reduxStore.getState().app.selectedAddress.rvnWallet.derivedMasterPublicKey
|
||||||
break
|
break
|
||||||
case 'ARRR':
|
case 'ARRR':
|
||||||
_url = `/crosschain/arrr/walletbalance?apiKey=${this.getApiKey()}`
|
_url = `/crosschain/arrr/walletbalance?apiKey=${this.getApiKey()}`
|
||||||
_body = window.parent.reduxStore.getState().app.selectedAddress.arrrWallet.seed58
|
_body = window.parent.reduxStore.getState().app.selectedAddress.arrrWallet.seed58
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
this.loader.show();
|
this.loader.show();
|
||||||
const res = await parentEpml.request('apiCall', {
|
const res = await parentEpml.request('apiCall', {
|
||||||
url: _url,
|
url: _url,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: _body,
|
body: _body,
|
||||||
})
|
})
|
||||||
if (isNaN(Number(res))) {
|
if (isNaN(Number(res))) {
|
||||||
const data = {};
|
const data = {};
|
||||||
const errorMsg = error.message || get("browserpage.bchange21");
|
const errorMsg = error.message || get("browserpage.bchange21");
|
||||||
data['error'] = errorMsg;
|
data['error'] = errorMsg;
|
||||||
response = JSON.stringify(data);
|
response = JSON.stringify(data);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
response = (Number(res) / 1e8).toFixed(8);
|
response = (Number(res) / 1e8).toFixed(8);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
const data = {};
|
const data = {};
|
||||||
const errorMsg = error.message || get("browserpage.bchange21");
|
const errorMsg = error.message || get("browserpage.bchange21");
|
||||||
data['error'] = errorMsg;
|
data['error'] = errorMsg;
|
||||||
response = JSON.stringify(data);
|
response = JSON.stringify(data);
|
||||||
return;
|
return;
|
||||||
} finally {
|
} finally {
|
||||||
this.loader.hide()
|
this.loader.hide()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (res3.action === 'reject') {
|
} else if (res3.action === 'reject') {
|
||||||
response = '{"error": "User declined request"}';
|
response = '{"error": "User declined request"}';
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -911,170 +911,170 @@ class WebBrowser extends LitElement {
|
|||||||
// TODO: prompt user to send. If they confirm, call `POST /crosschain/:coin/send`, or for QORT, broadcast a PAYMENT transaction
|
// TODO: prompt user to send. If they confirm, call `POST /crosschain/:coin/send`, or for QORT, broadcast a PAYMENT transaction
|
||||||
// then set the response string from the core to the `response` variable (defined above)
|
// then set the response string from the core to the `response` variable (defined above)
|
||||||
// If they decline, send back JSON that includes an `error` key, such as `{"error": "User declined request"}`
|
// If they decline, send back JSON that includes an `error` key, such as `{"error": "User declined request"}`
|
||||||
const amount = data.amount;
|
const amount = data.amount;
|
||||||
let recipient = data.destinationAddress;
|
let recipient = data.destinationAddress;
|
||||||
const fee = data.fee
|
const fee = data.fee
|
||||||
this.loader.show();
|
this.loader.show();
|
||||||
|
|
||||||
const walletBalance = await parentEpml.request('apiCall', {
|
const walletBalance = await parentEpml.request('apiCall', {
|
||||||
url: `/addresses/balance/${this.myAddress.address}?apiKey=${this.getApiKey()}`,
|
url: `/addresses/balance/${this.myAddress.address}?apiKey=${this.getApiKey()}`,
|
||||||
}).then((res) => {
|
}).then((res) => {
|
||||||
if (isNaN(Number(res))) {
|
if (isNaN(Number(res))) {
|
||||||
let snack4string = get("chatpage.cchange48")
|
let snack4string = get("chatpage.cchange48")
|
||||||
parentEpml.request('showSnackBar', `${snack4string}`)
|
parentEpml.request('showSnackBar', `${snack4string}`)
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
return Number(res).toFixed(8);
|
return Number(res).toFixed(8);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const myRef = await parentEpml.request("apiCall", {
|
const myRef = await parentEpml.request("apiCall", {
|
||||||
type: "api",
|
type: "api",
|
||||||
url: `/addresses/lastreference/${this.myAddress.address}`,
|
url: `/addresses/lastreference/${this.myAddress.address}`,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (parseFloat(amount) + parseFloat(data.fee) > parseFloat(walletBalance)) {
|
if (parseFloat(amount) + parseFloat(data.fee) > parseFloat(walletBalance)) {
|
||||||
this.loader.hide();
|
this.loader.hide();
|
||||||
let snack1string = get("chatpage.cchange51");
|
let snack1string = get("chatpage.cchange51");
|
||||||
parentEpml.request('showSnackBar', `${snack1string}`);
|
parentEpml.request('showSnackBar', `${snack1string}`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parseFloat(amount) <= 0) {
|
if (parseFloat(amount) <= 0) {
|
||||||
this.loader.hide();
|
this.loader.hide();
|
||||||
let snack2string = get("chatpage.cchange52");
|
let snack2string = get("chatpage.cchange52");
|
||||||
parentEpml.request('showSnackBar', `${snack2string}`);
|
parentEpml.request('showSnackBar', `${snack2string}`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (recipient.length === 0) {
|
if (recipient.length === 0) {
|
||||||
this.loader.hide();
|
this.loader.hide();
|
||||||
let snack3string = get("chatpage.cchange53");
|
let snack3string = get("chatpage.cchange53");
|
||||||
parentEpml.request('showSnackBar', `${snack3string}`);
|
parentEpml.request('showSnackBar', `${snack3string}`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const validateName = async (receiverName) => {
|
const validateName = async (receiverName) => {
|
||||||
let myRes;
|
let myRes;
|
||||||
let myNameRes = await parentEpml.request('apiCall', {
|
let myNameRes = await parentEpml.request('apiCall', {
|
||||||
type: 'api',
|
type: 'api',
|
||||||
url: `/names/${receiverName}`,
|
url: `/names/${receiverName}`,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (myNameRes.error === 401) {
|
if (myNameRes.error === 401) {
|
||||||
myRes = false;
|
myRes = false;
|
||||||
} else {
|
} else {
|
||||||
myRes = myNameRes;
|
myRes = myNameRes;
|
||||||
}
|
}
|
||||||
return myRes;
|
return myRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
const validateAddress = async (receiverAddress) => {
|
const validateAddress = async (receiverAddress) => {
|
||||||
let myAddress = await window.parent.validateAddress(receiverAddress);
|
let myAddress = await window.parent.validateAddress(receiverAddress);
|
||||||
return myAddress;
|
return myAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
const validateReceiver = async (recipient) => {
|
const validateReceiver = async (recipient) => {
|
||||||
let lastRef = myRef;
|
let lastRef = myRef;
|
||||||
let isAddress;
|
let isAddress;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
isAddress = await validateAddress(recipient);
|
isAddress = await validateAddress(recipient);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
isAddress = false;
|
isAddress = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isAddress) {
|
if (isAddress) {
|
||||||
let myTransaction = await makeTransactionRequest(recipient, lastRef);
|
let myTransaction = await makeTransactionRequest(recipient, lastRef);
|
||||||
return getTxnRequestResponse(myTransaction);
|
return getTxnRequestResponse(myTransaction);
|
||||||
} else {
|
} else {
|
||||||
let myNameRes = await validateName(recipient);
|
let myNameRes = await validateName(recipient);
|
||||||
if (myNameRes !== false) {
|
if (myNameRes !== false) {
|
||||||
let myNameAddress = myNameRes.owner
|
let myNameAddress = myNameRes.owner
|
||||||
let myTransaction = await makeTransactionRequest(myNameAddress, lastRef)
|
let myTransaction = await makeTransactionRequest(myNameAddress, lastRef)
|
||||||
return getTxnRequestResponse(myTransaction)
|
return getTxnRequestResponse(myTransaction)
|
||||||
} else {
|
} else {
|
||||||
console.error(`${translate("chatpage.cchange54")}`)
|
console.error(`${translate("chatpage.cchange54")}`)
|
||||||
parentEpml.request('showSnackBar', `${translate("chatpage.cchange54")}`)
|
parentEpml.request('showSnackBar', `${translate("chatpage.cchange54")}`)
|
||||||
this.loader.hide();
|
this.loader.hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const getName = async (recipient)=> {
|
const getName = async (recipient) => {
|
||||||
try {
|
try {
|
||||||
const getNames = await parentEpml.request("apiCall", {
|
const getNames = await parentEpml.request("apiCall", {
|
||||||
type: "api",
|
type: "api",
|
||||||
url: `/names/address/${recipient}`,
|
url: `/names/address/${recipient}`,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (getNames.length > 0 ) {
|
if (getNames.length > 0) {
|
||||||
return getNames[0].name;
|
return getNames[0].name;
|
||||||
} else {
|
} else {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const makeTransactionRequest = async (receiver, lastRef) => {
|
const makeTransactionRequest = async (receiver, lastRef) => {
|
||||||
let myReceiver = receiver;
|
let myReceiver = receiver;
|
||||||
let mylastRef = lastRef;
|
let mylastRef = lastRef;
|
||||||
let dialogamount = get("transactions.amount");
|
let dialogamount = get("transactions.amount");
|
||||||
let dialogAddress = get("login.address");
|
let dialogAddress = get("login.address");
|
||||||
let dialogName = get("login.name");
|
let dialogName = get("login.name");
|
||||||
let dialogto = get("transactions.to");
|
let dialogto = get("transactions.to");
|
||||||
let recipientName = await getName(myReceiver);
|
let recipientName = await getName(myReceiver);
|
||||||
let myTxnrequest = await parentEpml.request('transaction', {
|
let myTxnrequest = await parentEpml.request('transaction', {
|
||||||
type: 2,
|
type: 2,
|
||||||
nonce: this.myAddress.nonce,
|
nonce: this.myAddress.nonce,
|
||||||
params: {
|
params: {
|
||||||
recipient: myReceiver,
|
recipient: myReceiver,
|
||||||
recipientName: recipientName,
|
recipientName: recipientName,
|
||||||
amount: amount,
|
amount: amount,
|
||||||
lastReference: mylastRef,
|
lastReference: mylastRef,
|
||||||
fee: fee,
|
fee: fee,
|
||||||
dialogamount: dialogamount,
|
dialogamount: dialogamount,
|
||||||
dialogto: dialogto,
|
dialogto: dialogto,
|
||||||
dialogAddress,
|
dialogAddress,
|
||||||
dialogName
|
dialogName
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
return myTxnrequest;
|
return myTxnrequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
const getTxnRequestResponse = (txnResponse) => {
|
const getTxnRequestResponse = (txnResponse) => {
|
||||||
if (txnResponse.success === false && txnResponse.message) {
|
if (txnResponse.success === false && txnResponse.message) {
|
||||||
parentEpml.request('showSnackBar', `${txnResponse.message}`);
|
parentEpml.request('showSnackBar', `${txnResponse.message}`);
|
||||||
this.loader.hide();
|
this.loader.hide();
|
||||||
throw new Error(txnResponse);
|
throw new Error(txnResponse);
|
||||||
} else if (txnResponse.success === true && !txnResponse.data.error) {
|
} else if (txnResponse.success === true && !txnResponse.data.error) {
|
||||||
parentEpml.request('showSnackBar', `${get("chatpage.cchange55")}`)
|
parentEpml.request('showSnackBar', `${get("chatpage.cchange55")}`)
|
||||||
this.loader.hide();
|
this.loader.hide();
|
||||||
} else {
|
} else {
|
||||||
parentEpml.request('showSnackBar', `${txnResponse.data.message}`);
|
parentEpml.request('showSnackBar', `${txnResponse.data.message}`);
|
||||||
this.loader.hide();
|
this.loader.hide();
|
||||||
throw new Error(txnResponse);
|
throw new Error(txnResponse);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const result = await validateReceiver(recipient);
|
const result = await validateReceiver(recipient);
|
||||||
if (result) {
|
if (result) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
return '{"error": "Request could not be fulfilled"}';
|
return '{"error": "Request could not be fulfilled"}';
|
||||||
} finally {
|
} finally {
|
||||||
console.log("Case completed.");
|
console.log("Case completed.");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
console.log('Unhandled message: ' + JSON.stringify(data));
|
console.log('Unhandled message: ' + JSON.stringify(data));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse response
|
// Parse response
|
||||||
let responseObj;
|
let responseObj;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user