mirror of
https://github.com/Qortal/qortal-mobile.git
synced 2025-04-01 18:15:54 +00:00
update send chat message qortalRequest
This commit is contained in:
parent
d54bb9decd
commit
e19f57f7f9
@ -162,7 +162,7 @@ export const AppViewer = React.forwardRef(({ app , hide}, iframeRef) => {
|
|||||||
height: !isMobile ? '100vh' : `calc(${rootHeight} - 60px - 45px )`,
|
height: !isMobile ? '100vh' : `calc(${rootHeight} - 60px - 45px )`,
|
||||||
border: 'none',
|
border: 'none',
|
||||||
width: '100%'
|
width: '100%'
|
||||||
}} id="browser-iframe" src={defaultUrl} sandbox="allow-scripts allow-same-origin allow-forms allow-modals" allow="fullscreen">
|
}} id="browser-iframe" src={defaultUrl} sandbox="allow-scripts allow-same-origin allow-forms allow-modals" allow="fullscreen; clipboard-read; clipboard-write">
|
||||||
|
|
||||||
</iframe>
|
</iframe>
|
||||||
</Box>
|
</Box>
|
||||||
|
@ -339,7 +339,7 @@ export const isRunningGateway = async ()=> {
|
|||||||
|
|
||||||
case "GET_USER_WALLET": {
|
case "GET_USER_WALLET": {
|
||||||
try {
|
try {
|
||||||
const res = await getUserWallet(request.payload, isFromExtension);
|
const res = await getUserWallet(request.payload, isFromExtension, appInfo);
|
||||||
event.source.postMessage({
|
event.source.postMessage({
|
||||||
requestId: request.requestId,
|
requestId: request.requestId,
|
||||||
action: request.action,
|
action: request.action,
|
||||||
@ -379,7 +379,7 @@ export const isRunningGateway = async ()=> {
|
|||||||
|
|
||||||
case "GET_USER_WALLET_INFO": {
|
case "GET_USER_WALLET_INFO": {
|
||||||
try {
|
try {
|
||||||
const res = await getUserWalletInfo(request.payload, isFromExtension);
|
const res = await getUserWalletInfo(request.payload, isFromExtension, appInfo);
|
||||||
event.source.postMessage({
|
event.source.postMessage({
|
||||||
requestId: request.requestId,
|
requestId: request.requestId,
|
||||||
action: request.action,
|
action: request.action,
|
||||||
|
@ -1306,13 +1306,39 @@ export const createPoll = async (data, isFromExtension) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function isBase64(str) {
|
||||||
|
const base64Regex = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
|
||||||
|
return base64Regex.test(str) && str.length % 4 === 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkValue(value) {
|
||||||
|
if (typeof value === "string") {
|
||||||
|
if (isBase64(value)) {
|
||||||
|
return 'string'
|
||||||
|
} else {
|
||||||
|
return 'string'
|
||||||
|
}
|
||||||
|
} else if (typeof value === "object" && value !== null) {
|
||||||
|
return 'object'
|
||||||
|
} else {
|
||||||
|
throw new Error('Field fullContent is in an invalid format. Either use a string, base64 or an object.')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const sendChatMessage = async (data, isFromExtension, appInfo) => {
|
export const sendChatMessage = async (data, isFromExtension, appInfo) => {
|
||||||
const message = data?.message;
|
const message = data?.message;
|
||||||
const fullMessageObject = data?.fullMessageObject
|
const fullMessageObject = data?.fullMessageObject || data?.fullContent
|
||||||
const recipient = data.destinationAddress;
|
const recipient = data?.destinationAddress || data.recipient;
|
||||||
const groupId = data.groupId;
|
const groupId = data.groupId;
|
||||||
const isRecipient = !groupId;
|
const isRecipient = groupId === undefined;
|
||||||
|
const chatReference = data?.chatReference
|
||||||
|
if(groupId === undefined && recipient === undefined){
|
||||||
|
throw new Error('Please provide a recipient or groupId')
|
||||||
|
}
|
||||||
|
let fullMessageObjectType
|
||||||
|
if(fullMessageObject){
|
||||||
|
fullMessageObjectType = checkValue(fullMessageObject)
|
||||||
|
}
|
||||||
const value =
|
const value =
|
||||||
(await getPermission(`qAPPSendChatMessage-${appInfo?.name}`)) || false;
|
(await getPermission(`qAPPSendChatMessage-${appInfo?.name}`)) || false;
|
||||||
let skip = false;
|
let skip = false;
|
||||||
@ -1326,7 +1352,7 @@ if (!skip) {
|
|||||||
text1:
|
text1:
|
||||||
"Do you give this application permission to send this chat message?",
|
"Do you give this application permission to send this chat message?",
|
||||||
text2: `To: ${isRecipient ? recipient : `group ${groupId}`}`,
|
text2: `To: ${isRecipient ? recipient : `group ${groupId}`}`,
|
||||||
text3: `${message?.slice(0, 25)}${message?.length > 25 ? "..." : ""}`,
|
text3: fullMessageObject ? fullMessageObjectType === 'string' ? `${fullMessageObject?.slice(0, 25)}${fullMessageObject?.length > 25 ? "..." : ""}` : `${JSON.stringify(fullMessageObject)?.slice(0, 25)}${JSON.stringify(fullMessageObject)?.length > 25 ? "..." : ""}` : `${message?.slice(0, 25)}${message?.length > 25 ? "..." : ""}`,
|
||||||
checkbox1: {
|
checkbox1: {
|
||||||
value: false,
|
value: false,
|
||||||
label: "Always allow chat messages from this app",
|
label: "Always allow chat messages from this app",
|
||||||
@ -1361,7 +1387,11 @@ if (!skip) {
|
|||||||
version: 3,
|
version: 3,
|
||||||
};
|
};
|
||||||
|
|
||||||
const stringifyMessageObject = JSON.stringify(messageObject);
|
let stringifyMessageObject = JSON.stringify(messageObject);
|
||||||
|
if(fullMessageObjectType === 'string'){
|
||||||
|
stringifyMessageObject = messageObject
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const balance = await getBalanceInfo();
|
const balance = await getBalanceInfo();
|
||||||
const hasEnoughBalance = +balance < 4 ? false : true;
|
const hasEnoughBalance = +balance < 4 ? false : true;
|
||||||
@ -1417,16 +1447,22 @@ if (!skip) {
|
|||||||
publicKey: uint8PublicKey,
|
publicKey: uint8PublicKey,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let handleDynamicValues = {}
|
||||||
|
if(chatReference){
|
||||||
|
handleDynamicValues['chatReference'] = chatReference
|
||||||
|
}
|
||||||
|
|
||||||
const tx = await createTransaction(18, keyPair, {
|
const tx = await createTransaction(18, keyPair, {
|
||||||
timestamp: sendTimestamp,
|
timestamp: sendTimestamp,
|
||||||
recipient: recipient,
|
recipient: recipient,
|
||||||
recipientPublicKey: key,
|
recipientPublicKey: key,
|
||||||
hasChatReference: 0,
|
hasChatReference: chatReference ? 1 : 0,
|
||||||
message: stringifyMessageObject,
|
message: stringifyMessageObject,
|
||||||
lastReference: reference,
|
lastReference: reference,
|
||||||
proofOfWorkNonce: 0,
|
proofOfWorkNonce: 0,
|
||||||
isEncrypted: 1,
|
isEncrypted: 1,
|
||||||
isText: 1,
|
isText: 1,
|
||||||
|
...handleDynamicValues
|
||||||
});
|
});
|
||||||
|
|
||||||
const chatBytes = tx.chatBytes;
|
const chatBytes = tx.chatBytes;
|
||||||
@ -1455,16 +1491,22 @@ if (!skip) {
|
|||||||
publicKey: uint8PublicKey,
|
publicKey: uint8PublicKey,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let handleDynamicValues = {}
|
||||||
|
if(chatReference){
|
||||||
|
handleDynamicValues['chatReference'] = chatReference
|
||||||
|
}
|
||||||
|
|
||||||
const txBody = {
|
const txBody = {
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
groupID: Number(groupId),
|
groupID: Number(groupId),
|
||||||
hasReceipient: 0,
|
hasReceipient: 0,
|
||||||
hasChatReference: 0,
|
hasChatReference: chatReference ? 1 : 0,
|
||||||
message: stringifyMessageObject,
|
message: stringifyMessageObject,
|
||||||
lastReference: reference,
|
lastReference: reference,
|
||||||
proofOfWorkNonce: 0,
|
proofOfWorkNonce: 0,
|
||||||
isEncrypted: 0, // Set default to not encrypted for groups
|
isEncrypted: 0, // Set default to not encrypted for groups
|
||||||
isText: 1,
|
isText: 1,
|
||||||
|
...handleDynamicValues
|
||||||
};
|
};
|
||||||
|
|
||||||
const tx = await createTransaction(181, keyPair, txBody);
|
const tx = await createTransaction(181, keyPair, txBody);
|
||||||
@ -1652,7 +1694,7 @@ export const deployAt = async (data, isFromExtension) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getUserWallet = async (data, isFromExtension) => {
|
export const getUserWallet = async (data, isFromExtension, appInfo) => {
|
||||||
const requiredFields = ["coin"];
|
const requiredFields = ["coin"];
|
||||||
const missingFields: string[] = [];
|
const missingFields: string[] = [];
|
||||||
requiredFields.forEach((field) => {
|
requiredFields.forEach((field) => {
|
||||||
@ -1671,14 +1713,39 @@ export const getUserWallet = async (data, isFromExtension) => {
|
|||||||
throw new Error(
|
throw new Error(
|
||||||
"Cannot view ARRR wallet info through the gateway. Please use your local node."
|
"Cannot view ARRR wallet info through the gateway. Please use your local node."
|
||||||
);
|
);
|
||||||
const resPermission = await getUserPermission({
|
const value =
|
||||||
|
(await getPermission(
|
||||||
|
`qAPPAutoGetUserWallet-${appInfo?.name}-${data.coin}`
|
||||||
|
)) || false;
|
||||||
|
let skip = false;
|
||||||
|
if (value) {
|
||||||
|
skip = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
let resPermission;
|
||||||
|
|
||||||
|
if (!skip) {
|
||||||
|
resPermission = await getUserPermission({
|
||||||
text1:
|
text1:
|
||||||
"Do you give this application permission to get your wallet information?",
|
"Do you give this application permission to get your wallet information?",
|
||||||
highlightedText: `coin: ${data.coin}`
|
highlightedText: `coin: ${data.coin}`,
|
||||||
|
checkbox1: {
|
||||||
|
value: true,
|
||||||
|
label: "Always allow wallet to be retrieved automatically",
|
||||||
|
},
|
||||||
}, isFromExtension);
|
}, isFromExtension);
|
||||||
const { accepted } = resPermission;
|
}
|
||||||
|
|
||||||
if (accepted) {
|
const { accepted = false, checkbox1 = false } = resPermission || {};
|
||||||
|
|
||||||
|
if (resPermission) {
|
||||||
|
setPermission(
|
||||||
|
`qAPPAutoGetUserWallet-${appInfo?.name}-${data.coin}`,
|
||||||
|
checkbox1
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (accepted || skip) {
|
||||||
let coin = data.coin;
|
let coin = data.coin;
|
||||||
let userWallet = {};
|
let userWallet = {};
|
||||||
let arrrAddress = "";
|
let arrrAddress = "";
|
||||||
@ -1950,7 +2017,7 @@ export const getUserWalletFunc = async (coin) => {
|
|||||||
return userWallet;
|
return userWallet;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getUserWalletInfo = async (data, isFromExtension) => {
|
export const getUserWalletInfo = async (data, isFromExtension, appInfo) => {
|
||||||
const requiredFields = ["coin"];
|
const requiredFields = ["coin"];
|
||||||
const missingFields: string[] = [];
|
const missingFields: string[] = [];
|
||||||
requiredFields.forEach((field) => {
|
requiredFields.forEach((field) => {
|
||||||
@ -1969,13 +2036,37 @@ export const getUserWalletInfo = async (data, isFromExtension) => {
|
|||||||
"ARRR is not supported for this call."
|
"ARRR is not supported for this call."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const resPermission = await getUserPermission({
|
const value =
|
||||||
text1: "Do you give this application permission to retrieve your wallet information",
|
(await getPermission(
|
||||||
highlightedText: `coin: ${data.coin}`
|
`getUserWalletInfo-${appInfo?.name}-${data.coin}`
|
||||||
}, isFromExtension);
|
)) || false;
|
||||||
const { accepted } = resPermission;
|
let skip = false;
|
||||||
|
if (value) {
|
||||||
|
skip = true;
|
||||||
|
}
|
||||||
|
let resPermission;
|
||||||
|
|
||||||
if (accepted) {
|
if (!skip) {
|
||||||
|
|
||||||
|
resPermission = await getUserPermission({
|
||||||
|
text1: "Do you give this application permission to retrieve your wallet information",
|
||||||
|
highlightedText: `coin: ${data.coin}`,
|
||||||
|
checkbox1: {
|
||||||
|
value: true,
|
||||||
|
label: "Always allow wallet info to be retrieved automatically",
|
||||||
|
},
|
||||||
|
}, isFromExtension);
|
||||||
|
}
|
||||||
|
const { accepted = false, checkbox1 = false } = resPermission || {};
|
||||||
|
|
||||||
|
if (resPermission) {
|
||||||
|
setPermission(
|
||||||
|
`getUserWalletInfo-${appInfo?.name}-${data.coin}`,
|
||||||
|
checkbox1
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (accepted || skip) {
|
||||||
let coin = data.coin;
|
let coin = data.coin;
|
||||||
let walletKeys = await getUserWalletFunc(coin);
|
let walletKeys = await getUserWalletFunc(coin);
|
||||||
const _url = await createEndpoint(
|
const _url = await createEndpoint(
|
||||||
@ -2440,7 +2531,7 @@ export const getTxActivitySummary = async (data) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const sendCoin = async (data, isFromExtension) => {
|
export const sendCoin = async (data, isFromExtension) => {
|
||||||
const requiredFields = ['coin', 'destinationAddress', 'amount']
|
const requiredFields = ['coin', 'amount']
|
||||||
const missingFields: string[] = []
|
const missingFields: string[] = []
|
||||||
requiredFields.forEach((field) => {
|
requiredFields.forEach((field) => {
|
||||||
if (!data[field]) {
|
if (!data[field]) {
|
||||||
@ -2452,6 +2543,10 @@ export const sendCoin = async (data, isFromExtension) => {
|
|||||||
const errorMsg = `Missing fields: ${missingFieldsString}`
|
const errorMsg = `Missing fields: ${missingFieldsString}`
|
||||||
throw new Error(errorMsg)
|
throw new Error(errorMsg)
|
||||||
}
|
}
|
||||||
|
if(!data?.destinationAddress && !data?.recipient){
|
||||||
|
throw new Error('Missing fields: recipient')
|
||||||
|
}
|
||||||
|
|
||||||
let checkCoin = data.coin
|
let checkCoin = data.coin
|
||||||
const wallet = await getSaveWallet();
|
const wallet = await getSaveWallet();
|
||||||
const address = wallet.address0;
|
const address = wallet.address0;
|
||||||
@ -2466,7 +2561,8 @@ export const sendCoin = async (data, isFromExtension) => {
|
|||||||
// 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 = Number(data.amount)
|
const amount = Number(data.amount)
|
||||||
const recipient = data.destinationAddress
|
const recipient = data?.recipient || data.destinationAddress;
|
||||||
|
|
||||||
|
|
||||||
const url = await createEndpoint(`/addresses/balance/${address}`);
|
const url = await createEndpoint(`/addresses/balance/${address}`);
|
||||||
const response = await fetch(url);
|
const response = await fetch(url);
|
||||||
@ -2516,7 +2612,8 @@ export const sendCoin = async (data, isFromExtension) => {
|
|||||||
|
|
||||||
} else if (checkCoin === "BTC") {
|
} else if (checkCoin === "BTC") {
|
||||||
const amount = Number(data.amount)
|
const amount = Number(data.amount)
|
||||||
const recipient = data.destinationAddress
|
const recipient = data?.recipient || data.destinationAddress;
|
||||||
|
|
||||||
const xprv58 = parsedData.btcPrivateKey
|
const xprv58 = parsedData.btcPrivateKey
|
||||||
const feePerByte = data.fee ? data.fee : btcFeePerByte
|
const feePerByte = data.fee ? data.fee : btcFeePerByte
|
||||||
|
|
||||||
@ -2573,7 +2670,8 @@ export const sendCoin = async (data, isFromExtension) => {
|
|||||||
} else if (checkCoin === "LTC") {
|
} else if (checkCoin === "LTC") {
|
||||||
|
|
||||||
const amount = Number(data.amount)
|
const amount = Number(data.amount)
|
||||||
const recipient = data.destinationAddress
|
const recipient = data?.recipient || data.destinationAddress;
|
||||||
|
|
||||||
const xprv58 = parsedData.ltcPrivateKey
|
const xprv58 = parsedData.ltcPrivateKey
|
||||||
const feePerByte = data.fee ? data.fee : ltcFeePerByte
|
const feePerByte = data.fee ? data.fee : ltcFeePerByte
|
||||||
const ltcWalletBalance = await getWalletBalance({coin: checkCoin}, true)
|
const ltcWalletBalance = await getWalletBalance({coin: checkCoin}, true)
|
||||||
@ -2627,7 +2725,8 @@ export const sendCoin = async (data, isFromExtension) => {
|
|||||||
} else if (checkCoin === "DOGE") {
|
} else if (checkCoin === "DOGE") {
|
||||||
|
|
||||||
const amount = Number(data.amount)
|
const amount = Number(data.amount)
|
||||||
const recipient = data.destinationAddress
|
const recipient = data?.recipient || data.destinationAddress;
|
||||||
|
|
||||||
const coin = data.coin
|
const coin = data.coin
|
||||||
const xprv58 = parsedData.dogePrivateKey
|
const xprv58 = parsedData.dogePrivateKey
|
||||||
const feePerByte = data.fee ? data.fee : dogeFeePerByte
|
const feePerByte = data.fee ? data.fee : dogeFeePerByte
|
||||||
@ -2683,7 +2782,8 @@ export const sendCoin = async (data, isFromExtension) => {
|
|||||||
|
|
||||||
} else if (checkCoin === "DGB") {
|
} else if (checkCoin === "DGB") {
|
||||||
const amount = Number(data.amount)
|
const amount = Number(data.amount)
|
||||||
const recipient = data.destinationAddress
|
const recipient = data?.recipient || data.destinationAddress;
|
||||||
|
|
||||||
const xprv58 = parsedData.dbgPrivateKey
|
const xprv58 = parsedData.dbgPrivateKey
|
||||||
const feePerByte = data.fee ? data.fee : dgbFeePerByte
|
const feePerByte = data.fee ? data.fee : dgbFeePerByte
|
||||||
const dgbWalletBalance = await getWalletBalance({coin: checkCoin}, true)
|
const dgbWalletBalance = await getWalletBalance({coin: checkCoin}, true)
|
||||||
@ -2738,7 +2838,8 @@ export const sendCoin = async (data, isFromExtension) => {
|
|||||||
|
|
||||||
} else if (checkCoin === "RVN") {
|
} else if (checkCoin === "RVN") {
|
||||||
const amount = Number(data.amount)
|
const amount = Number(data.amount)
|
||||||
const recipient = data.destinationAddress
|
const recipient = data?.recipient || data.destinationAddress;
|
||||||
|
|
||||||
const coin = data.coin
|
const coin = data.coin
|
||||||
const xprv58 = parsedData.rvnPrivateKey
|
const xprv58 = parsedData.rvnPrivateKey
|
||||||
const feePerByte = data.fee ? data.fee : rvnFeePerByte
|
const feePerByte = data.fee ? data.fee : rvnFeePerByte
|
||||||
@ -2794,7 +2895,8 @@ export const sendCoin = async (data, isFromExtension) => {
|
|||||||
}
|
}
|
||||||
} else if (checkCoin === "ARRR") {
|
} else if (checkCoin === "ARRR") {
|
||||||
const amount = Number(data.amount)
|
const amount = Number(data.amount)
|
||||||
const recipient = data.destinationAddress
|
const recipient = data?.recipient || data.destinationAddress;
|
||||||
|
|
||||||
const memo = data?.memo
|
const memo = data?.memo
|
||||||
const arrrWalletBalance = await getWalletBalance({coin: checkCoin}, true)
|
const arrrWalletBalance = await getWalletBalance({coin: checkCoin}, true)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user