mirror of
https://github.com/Qortal/chrome-extension.git
synced 2025-02-11 17:55:49 +00:00
batch of updates 2
This commit is contained in:
parent
d0719a30af
commit
97a0dd7557
@ -30,6 +30,7 @@ import { validateAddress } from "./utils/validateAddress";
|
|||||||
import { Sha256 } from "asmcrypto.js";
|
import { Sha256 } from "asmcrypto.js";
|
||||||
import { TradeBotRespondMultipleRequest } from "./transactions/TradeBotRespondMultipleRequest";
|
import { TradeBotRespondMultipleRequest } from "./transactions/TradeBotRespondMultipleRequest";
|
||||||
import { RESOURCE_TYPE_NUMBER_GROUP_CHAT_REACTIONS } from "./constants/resourceTypes";
|
import { RESOURCE_TYPE_NUMBER_GROUP_CHAT_REACTIONS } from "./constants/resourceTypes";
|
||||||
|
import TradeBotRespondRequest from './transactions/TradeBotRespondRequest';
|
||||||
|
|
||||||
export function cleanUrl(url) {
|
export function cleanUrl(url) {
|
||||||
return url?.replace(/^(https?:\/\/)?(www\.)?/, '');
|
return url?.replace(/^(https?:\/\/)?(www\.)?/, '');
|
||||||
@ -1274,7 +1275,7 @@ async function getDataPublishes(groupId, type) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sendChatForBuyOrder({ qortAddress, recipientPublicKey, message }) {
|
async function sendChatForBuyOrder({ qortAddress, recipientPublicKey, message, isSingle }) {
|
||||||
let _reference = new Uint8Array(64);
|
let _reference = new Uint8Array(64);
|
||||||
self.crypto.getRandomValues(_reference);
|
self.crypto.getRandomValues(_reference);
|
||||||
|
|
||||||
@ -1299,7 +1300,9 @@ async function sendChatForBuyOrder({ qortAddress, recipientPublicKey, message })
|
|||||||
};
|
};
|
||||||
const finalJson = {
|
const finalJson = {
|
||||||
callRequest: jsonData,
|
callRequest: jsonData,
|
||||||
extra: "whatever additional data goes here",
|
extra: {
|
||||||
|
type: isSingle ? "single" : "multiple"
|
||||||
|
},
|
||||||
};
|
};
|
||||||
const messageStringified = JSON.stringify(finalJson);
|
const messageStringified = JSON.stringify(finalJson);
|
||||||
|
|
||||||
@ -2063,24 +2066,45 @@ async function createBuyOrderTx({ crosschainAtInfo, useLocal }) {
|
|||||||
|
|
||||||
export async function createBuyOrderTxQortalRequest({ crosschainAtInfo, isGateway, foreignBlockchain }) {
|
export async function createBuyOrderTxQortalRequest({ crosschainAtInfo, isGateway, foreignBlockchain }) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
if (!isGateway) {
|
if (!isGateway) {
|
||||||
const wallet = await getSaveWallet();
|
const wallet = await getSaveWallet();
|
||||||
|
|
||||||
const address = wallet.address0;
|
const address = wallet.address0;
|
||||||
|
let message
|
||||||
const message = {
|
if(foreignBlockchain === 'PIRATECHAIN'){
|
||||||
addresses: crosschainAtInfo.map((order)=> order.qortalAtAddress),
|
message = {
|
||||||
foreignKey: await getForeignKey(foreignBlockchain),
|
atAddress: crosschainAtInfo[0].qortalAtAddress,
|
||||||
receivingAddress: address,
|
foreignKey: await getForeignKey(foreignBlockchain),
|
||||||
};
|
receivingAddress: address,
|
||||||
let responseVar;
|
};
|
||||||
const txn = new TradeBotRespondMultipleRequest().createTransaction(
|
} else {
|
||||||
message
|
message = {
|
||||||
);
|
addresses: crosschainAtInfo.map((order)=> order.qortalAtAddress),
|
||||||
|
foreignKey: await getForeignKey(foreignBlockchain),
|
||||||
|
receivingAddress: address,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
let responseVar;
|
||||||
const url = await createEndpoint('/crosschain/tradebot/respondmultiple')
|
let txn
|
||||||
|
let url
|
||||||
|
if(foreignBlockchain === 'PIRATECHAIN'){
|
||||||
|
txn = new TradeBotRespondRequest().createTransaction(
|
||||||
|
message
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
url = await createEndpoint('/crosschain/tradebot/respond')
|
||||||
|
} else {
|
||||||
|
txn = new TradeBotRespondMultipleRequest().createTransaction(
|
||||||
|
message
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
url = await createEndpoint('/crosschain/tradebot/respondmultiple')
|
||||||
|
}
|
||||||
|
|
||||||
const responseFetch = await fetch(
|
const responseFetch = await fetch(
|
||||||
url,
|
url,
|
||||||
{
|
{
|
||||||
@ -2093,6 +2117,10 @@ export async function createBuyOrderTxQortalRequest({ crosschainAtInfo, isGatewa
|
|||||||
);
|
);
|
||||||
|
|
||||||
const res = await responseFetch.json();
|
const res = await responseFetch.json();
|
||||||
|
if(res?.error && res?.message){
|
||||||
|
throw new Error(res?.message)
|
||||||
|
}
|
||||||
|
if(!responseFetch?.ok) throw new Error('Failed to submit buy order')
|
||||||
|
|
||||||
if (res === false) {
|
if (res === false) {
|
||||||
responseVar = {
|
responseVar = {
|
||||||
@ -2109,7 +2137,7 @@ export async function createBuyOrderTxQortalRequest({ crosschainAtInfo, isGatewa
|
|||||||
callResponse: response,
|
callResponse: response,
|
||||||
extra: {
|
extra: {
|
||||||
message: "Transaction processed successfully!",
|
message: "Transaction processed successfully!",
|
||||||
atAddresses: crosschainAtInfo.map((order)=> order.qortalAtAddress),
|
atAddresses: foreignBlockchain === 'PIRATECHAIN' ? [crosschainAtInfo[0].qortalAtAddress] : crosschainAtInfo.map((order)=> order.qortalAtAddress),
|
||||||
senderAddress: address,
|
senderAddress: address,
|
||||||
node: url
|
node: url
|
||||||
},
|
},
|
||||||
@ -2119,7 +2147,7 @@ export async function createBuyOrderTxQortalRequest({ crosschainAtInfo, isGatewa
|
|||||||
callResponse: "ERROR",
|
callResponse: "ERROR",
|
||||||
extra: {
|
extra: {
|
||||||
message: response,
|
message: response,
|
||||||
atAddresses: crosschainAtInfo.map((order)=> order.qortalAtAddress),
|
atAddresses: foreignBlockchain === 'PIRATECHAIN' ? [crosschainAtInfo[0].qortalAtAddress] : crosschainAtInfo.map((order)=> order.qortalAtAddress),
|
||||||
senderAddress: address,
|
senderAddress: address,
|
||||||
node: url
|
node: url
|
||||||
},
|
},
|
||||||
@ -2133,7 +2161,7 @@ export async function createBuyOrderTxQortalRequest({ crosschainAtInfo, isGatewa
|
|||||||
|
|
||||||
|
|
||||||
const message = {
|
const message = {
|
||||||
addresses: crosschainAtInfo.map((order)=> order.qortalAtAddress),
|
addresses: foreignBlockchain === 'PIRATECHAIN' ? [crosschainAtInfo[0].qortalAtAddress] : crosschainAtInfo.map((order)=> order.qortalAtAddress),
|
||||||
foreignKey: await getForeignKey(foreignBlockchain),
|
foreignKey: await getForeignKey(foreignBlockchain),
|
||||||
receivingAddress: address,
|
receivingAddress: address,
|
||||||
};
|
};
|
||||||
@ -2141,9 +2169,11 @@ export async function createBuyOrderTxQortalRequest({ crosschainAtInfo, isGatewa
|
|||||||
qortAddress: proxyAccountAddress,
|
qortAddress: proxyAccountAddress,
|
||||||
recipientPublicKey: proxyAccountPublicKey,
|
recipientPublicKey: proxyAccountPublicKey,
|
||||||
message,
|
message,
|
||||||
atAddresses: crosschainAtInfo.map((order)=> order.qortalAtAddress),
|
atAddresses: foreignBlockchain === 'PIRATECHAIN' ? [crosschainAtInfo[0].qortalAtAddress] : crosschainAtInfo.map((order)=> order.qortalAtAddress),
|
||||||
|
isSingle: foreignBlockchain === 'PIRATECHAIN'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (res?.signature) {
|
if (res?.signature) {
|
||||||
|
|
||||||
@ -2159,8 +2189,7 @@ export async function createBuyOrderTxQortalRequest({ crosschainAtInfo, isGatewa
|
|||||||
extra: {
|
extra: {
|
||||||
message: message?.extra?.message,
|
message: message?.extra?.message,
|
||||||
senderAddress: address,
|
senderAddress: address,
|
||||||
node: buyTradeNodeBaseUrl,
|
atAddresses: foreignBlockchain === 'PIRATECHAIN' ? [crosschainAtInfo[0].qortalAtAddress] : crosschainAtInfo.map((order)=> order.qortalAtAddress),
|
||||||
atAddresses: crosschainAtInfo.map((order)=> order.qortalAtAddress),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,36 +1,72 @@
|
|||||||
|
import React, { useState } from "react";
|
||||||
import React from 'react';
|
import QRCode from "react-qr-code";
|
||||||
import QRCode from 'react-qr-code';
|
import { TextP } from "../App-styles";
|
||||||
import { TextP } from '../App-styles';
|
import { Box, Typography } from "@mui/material";
|
||||||
import { Box } from '@mui/material';
|
|
||||||
|
|
||||||
export const AddressQRCode = ({ targetAddress }) => {
|
export const AddressQRCode = ({ targetAddress }) => {
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
return (
|
return (
|
||||||
<Box sx={{
|
<Box
|
||||||
display: 'flex',
|
sx={{
|
||||||
gap: '10px',
|
display: "flex",
|
||||||
width: '100%',
|
gap: "10px",
|
||||||
alignItems: 'center',
|
alignItems: "center",
|
||||||
flexDirection: 'column',
|
flexDirection: "column",
|
||||||
marginTop: '20px'
|
marginTop: '10px'
|
||||||
}}>
|
}}
|
||||||
<TextP
|
>
|
||||||
sx={{
|
<Typography
|
||||||
textAlign: "center",
|
sx={{
|
||||||
lineHeight: 1.2,
|
cursor: "pointer",
|
||||||
fontSize: "16px",
|
fontSize: "14px",
|
||||||
fontWeight: 500,
|
}}
|
||||||
}}
|
onClick={() => {
|
||||||
>
|
setOpen((prev)=> !prev);
|
||||||
Your address
|
}}
|
||||||
</TextP>
|
>
|
||||||
<QRCode
|
{open ? 'Hide QR code' :'See QR code'}
|
||||||
value={targetAddress} // Your address here
|
</Typography>
|
||||||
size={180} // Adjust size as needed
|
|
||||||
level="M" // Error correction level (L, M, Q, H)
|
{open && (
|
||||||
bgColor="#FFFFFF" // Background color (white)
|
<Box
|
||||||
fgColor="#000000" // Foreground color (black)
|
sx={{
|
||||||
/>
|
display: "flex",
|
||||||
|
gap: "10px",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "center",
|
||||||
|
width: "100%",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
display: "flex",
|
||||||
|
gap: "10px",
|
||||||
|
width: "100%",
|
||||||
|
alignItems: "center",
|
||||||
|
flexDirection: "column",
|
||||||
|
marginTop: "20px",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<TextP
|
||||||
|
sx={{
|
||||||
|
textAlign: "center",
|
||||||
|
lineHeight: 1.2,
|
||||||
|
fontSize: "16px",
|
||||||
|
fontWeight: 500,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Your address
|
||||||
|
</TextP>
|
||||||
|
<QRCode
|
||||||
|
value={targetAddress} // Your address here
|
||||||
|
size={150} // Adjust size as needed
|
||||||
|
level="M" // Error correction level (L, M, Q, H)
|
||||||
|
bgColor="#FFFFFF" // Background color (white)
|
||||||
|
fgColor="#000000" // Foreground color (black)
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -6,7 +6,7 @@ import { objectToBase64 } from "../../qdn/encryption/group-encryption";
|
|||||||
import ShortUniqueId from "short-unique-id";
|
import ShortUniqueId from "short-unique-id";
|
||||||
import { LoadingSnackbar } from "../Snackbar/LoadingSnackbar";
|
import { LoadingSnackbar } from "../Snackbar/LoadingSnackbar";
|
||||||
import { getBaseApi, getFee } from "../../background";
|
import { getBaseApi, getFee } from "../../background";
|
||||||
import { decryptPublishes, getTempPublish, saveTempPublish } from "./GroupAnnouncements";
|
import { decryptPublishes, getTempPublish, handleUnencryptedPublishes, saveTempPublish } from "./GroupAnnouncements";
|
||||||
import { AnnouncementList } from "./AnnouncementList";
|
import { AnnouncementList } from "./AnnouncementList";
|
||||||
import { Spacer } from "../../common/Spacer";
|
import { Spacer } from "../../common/Spacer";
|
||||||
import ArrowBackIcon from '@mui/icons-material/ArrowBack';
|
import ArrowBackIcon from '@mui/icons-material/ArrowBack';
|
||||||
@ -22,7 +22,8 @@ export const AnnouncementDiscussion = ({
|
|||||||
secretKey,
|
secretKey,
|
||||||
setSelectedAnnouncement,
|
setSelectedAnnouncement,
|
||||||
show,
|
show,
|
||||||
myName
|
myName,
|
||||||
|
isPrivate
|
||||||
}) => {
|
}) => {
|
||||||
const [isSending, setIsSending] = useState(false);
|
const [isSending, setIsSending] = useState(false);
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
@ -49,7 +50,7 @@ export const AnnouncementDiscussion = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const getData = async ({ identifier, name }) => {
|
const getData = async ({ identifier, name }, isPrivate) => {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
const res = await fetch(
|
const res = await fetch(
|
||||||
@ -57,7 +58,7 @@ export const AnnouncementDiscussion = ({
|
|||||||
);
|
);
|
||||||
if(!res?.ok) return
|
if(!res?.ok) return
|
||||||
const data = await res.text();
|
const data = await res.text();
|
||||||
const response = await decryptPublishes([{ data }], secretKey);
|
const response = isPrivate === false ? handleUnencryptedPublishes([data]) : await decryptPublishes([{ data }], secretKey);
|
||||||
|
|
||||||
const messageData = response[0];
|
const messageData = response[0];
|
||||||
setData((prev) => {
|
setData((prev) => {
|
||||||
@ -134,10 +135,10 @@ export const AnnouncementDiscussion = ({
|
|||||||
extra: {},
|
extra: {},
|
||||||
message: htmlContent,
|
message: htmlContent,
|
||||||
};
|
};
|
||||||
const secretKeyObject = await getSecretKey(false, true);
|
const secretKeyObject = isPrivate === false ? null : await getSecretKey(false, true);
|
||||||
const message64: any = await objectToBase64(message);
|
const message64: any = await objectToBase64(message);
|
||||||
|
|
||||||
const encryptSingle = await encryptChatMessage(
|
const encryptSingle = isPrivate === false ? message64 : await encryptChatMessage(
|
||||||
message64,
|
message64,
|
||||||
secretKeyObject
|
secretKeyObject
|
||||||
);
|
);
|
||||||
@ -171,7 +172,7 @@ export const AnnouncementDiscussion = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getComments = React.useCallback(
|
const getComments = React.useCallback(
|
||||||
async (selectedAnnouncement) => {
|
async (selectedAnnouncement, isPrivate) => {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
@ -192,7 +193,7 @@ export const AnnouncementDiscussion = ({
|
|||||||
setComments(responseData);
|
setComments(responseData);
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
for (const data of responseData) {
|
for (const data of responseData) {
|
||||||
getData({ name: data.name, identifier: data.identifier });
|
getData({ name: data.name, identifier: data.identifier }, isPrivate);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
} finally {
|
} finally {
|
||||||
@ -222,7 +223,7 @@ export const AnnouncementDiscussion = ({
|
|||||||
setComments((prev)=> [...prev, ...responseData]);
|
setComments((prev)=> [...prev, ...responseData]);
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
for (const data of responseData) {
|
for (const data of responseData) {
|
||||||
getData({ name: data.name, identifier: data.identifier });
|
getData({ name: data.name, identifier: data.identifier }, isPrivate);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
||||||
@ -247,11 +248,12 @@ export const AnnouncementDiscussion = ({
|
|||||||
}, [tempPublishedList, comments]);
|
}, [tempPublishedList, comments]);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (selectedAnnouncement && secretKey && !firstMountRef.current) {
|
if(!secretKey && isPrivate) return
|
||||||
getComments(selectedAnnouncement);
|
if (selectedAnnouncement && !firstMountRef.current && isPrivate !== null) {
|
||||||
|
getComments(selectedAnnouncement, isPrivate);
|
||||||
firstMountRef.current = true
|
firstMountRef.current = true
|
||||||
}
|
}
|
||||||
}, [selectedAnnouncement, secretKey]);
|
}, [selectedAnnouncement, secretKey, isPrivate]);
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
|
@ -123,6 +123,23 @@ export const decryptPublishes = async (encryptedMessages: any[], secretKey) => {
|
|||||||
});
|
});
|
||||||
} catch (error) {}
|
} catch (error) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const handleUnencryptedPublishes = (publishes) => {
|
||||||
|
let publishesData = []
|
||||||
|
publishes.forEach((pub)=> {
|
||||||
|
try {
|
||||||
|
const decryptToUnit8Array = base64ToUint8Array(pub);
|
||||||
|
const decodedData = uint8ArrayToObject(decryptToUnit8Array);
|
||||||
|
if(decodedData){
|
||||||
|
publishesData.push({decryptedData: decodedData})
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return publishesData
|
||||||
|
};
|
||||||
|
|
||||||
export const GroupAnnouncements = ({
|
export const GroupAnnouncements = ({
|
||||||
selectedGroup,
|
selectedGroup,
|
||||||
secretKey,
|
secretKey,
|
||||||
@ -133,6 +150,7 @@ export const GroupAnnouncements = ({
|
|||||||
isAdmin,
|
isAdmin,
|
||||||
hide,
|
hide,
|
||||||
myName,
|
myName,
|
||||||
|
isPrivate
|
||||||
}) => {
|
}) => {
|
||||||
const [messages, setMessages] = useState([]);
|
const [messages, setMessages] = useState([]);
|
||||||
const [isSending, setIsSending] = useState(false);
|
const [isSending, setIsSending] = useState(false);
|
||||||
@ -166,7 +184,7 @@ export const GroupAnnouncements = ({
|
|||||||
})();
|
})();
|
||||||
}, [selectedGroup]);
|
}, [selectedGroup]);
|
||||||
|
|
||||||
const getAnnouncementData = async ({ identifier, name, resource }) => {
|
const getAnnouncementData = async ({ identifier, name, resource }, isPrivate) => {
|
||||||
try {
|
try {
|
||||||
let data = dataPublishes.current[`${name}-${identifier}`];
|
let data = dataPublishes.current[`${name}-${identifier}`];
|
||||||
if (
|
if (
|
||||||
@ -186,9 +204,9 @@ export const GroupAnnouncements = ({
|
|||||||
data = data.data;
|
data = data.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await decryptPublishes([{ data }], secretKey);
|
const response = isPrivate === false ? handleUnencryptedPublishes([data]) : await decryptPublishes([{ data }], secretKey);
|
||||||
|
|
||||||
const messageData = response[0];
|
const messageData = response[0];
|
||||||
|
if(!messageData) return
|
||||||
setAnnouncementData((prev) => {
|
setAnnouncementData((prev) => {
|
||||||
return {
|
return {
|
||||||
...prev,
|
...prev,
|
||||||
@ -201,11 +219,11 @@ export const GroupAnnouncements = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!secretKey || hasInitializedWebsocket.current) return;
|
if ((!secretKey && isPrivate) || hasInitializedWebsocket.current || isPrivate === null) return;
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
// initWebsocketMessageGroup()
|
// initWebsocketMessageGroup()
|
||||||
hasInitializedWebsocket.current = true;
|
hasInitializedWebsocket.current = true;
|
||||||
}, [secretKey]);
|
}, [secretKey, isPrivate]);
|
||||||
|
|
||||||
const encryptChatMessage = async (data: string, secretKeyObject: any) => {
|
const encryptChatMessage = async (data: string, secretKeyObject: any) => {
|
||||||
try {
|
try {
|
||||||
@ -264,12 +282,12 @@ export const GroupAnnouncements = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const setTempData = async () => {
|
const setTempData = async (selectedGroup) => {
|
||||||
try {
|
try {
|
||||||
const getTempAnnouncements = await getTempPublish();
|
const getTempAnnouncements = await getTempPublish();
|
||||||
if (getTempAnnouncements?.announcement) {
|
if (getTempAnnouncements?.announcement) {
|
||||||
let tempData = [];
|
let tempData = [];
|
||||||
Object.keys(getTempAnnouncements?.announcement || {}).map((key) => {
|
Object.keys(getTempAnnouncements?.announcement || {}).filter((annKey)=> annKey?.startsWith(`grp-${selectedGroup}-anc`)).map((key) => {
|
||||||
const value = getTempAnnouncements?.announcement[key];
|
const value = getTempAnnouncements?.announcement[key];
|
||||||
tempData.push(value.data);
|
tempData.push(value.data);
|
||||||
});
|
});
|
||||||
@ -296,9 +314,9 @@ export const GroupAnnouncements = ({
|
|||||||
extra: {},
|
extra: {},
|
||||||
message: htmlContent,
|
message: htmlContent,
|
||||||
};
|
};
|
||||||
const secretKeyObject = await getSecretKey(false, true);
|
const secretKeyObject = isPrivate === false ? null : await getSecretKey(false, true);
|
||||||
const message64: any = await objectToBase64(message);
|
const message64: any = await objectToBase64(message);
|
||||||
const encryptSingle = await encryptChatMessage(
|
const encryptSingle = isPrivate === false ? message64 : await encryptChatMessage(
|
||||||
message64,
|
message64,
|
||||||
secretKeyObject
|
secretKeyObject
|
||||||
);
|
);
|
||||||
@ -320,7 +338,7 @@ export const GroupAnnouncements = ({
|
|||||||
data: dataToSaveToStorage,
|
data: dataToSaveToStorage,
|
||||||
key: "announcement",
|
key: "announcement",
|
||||||
});
|
});
|
||||||
setTempData();
|
setTempData(selectedGroup);
|
||||||
clearEditorContent();
|
clearEditorContent();
|
||||||
}
|
}
|
||||||
// send chat message
|
// send chat message
|
||||||
@ -338,7 +356,7 @@ export const GroupAnnouncements = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getAnnouncements = React.useCallback(
|
const getAnnouncements = React.useCallback(
|
||||||
async (selectedGroup) => {
|
async (selectedGroup, isPrivate) => {
|
||||||
try {
|
try {
|
||||||
const offset = 0;
|
const offset = 0;
|
||||||
|
|
||||||
@ -353,7 +371,7 @@ export const GroupAnnouncements = ({
|
|||||||
});
|
});
|
||||||
const responseData = await response.json();
|
const responseData = await response.json();
|
||||||
|
|
||||||
setTempData();
|
setTempData(selectedGroup);
|
||||||
setAnnouncements(responseData);
|
setAnnouncements(responseData);
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
for (const data of responseData) {
|
for (const data of responseData) {
|
||||||
@ -361,7 +379,7 @@ export const GroupAnnouncements = ({
|
|||||||
name: data.name,
|
name: data.name,
|
||||||
identifier: data.identifier,
|
identifier: data.identifier,
|
||||||
resource: data,
|
resource: data,
|
||||||
});
|
}, isPrivate);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
} finally {
|
} finally {
|
||||||
@ -372,11 +390,12 @@ export const GroupAnnouncements = ({
|
|||||||
);
|
);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (selectedGroup && secretKey && !hasInitialized.current && !hide) {
|
if(!secretKey && isPrivate) return
|
||||||
getAnnouncements(selectedGroup);
|
if (selectedGroup && !hasInitialized.current && !hide && isPrivate !== null) {
|
||||||
|
getAnnouncements(selectedGroup, isPrivate);
|
||||||
hasInitialized.current = true;
|
hasInitialized.current = true;
|
||||||
}
|
}
|
||||||
}, [selectedGroup, secretKey, hide]);
|
}, [selectedGroup, secretKey, hide, isPrivate]);
|
||||||
|
|
||||||
const loadMore = async () => {
|
const loadMore = async () => {
|
||||||
try {
|
try {
|
||||||
@ -396,7 +415,7 @@ export const GroupAnnouncements = ({
|
|||||||
setAnnouncements((prev) => [...prev, ...responseData]);
|
setAnnouncements((prev) => [...prev, ...responseData]);
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
for (const data of responseData) {
|
for (const data of responseData) {
|
||||||
getAnnouncementData({ name: data.name, identifier: data.identifier });
|
getAnnouncementData({ name: data.name, identifier: data.identifier }, isPrivate);
|
||||||
}
|
}
|
||||||
} catch (error) {}
|
} catch (error) {}
|
||||||
};
|
};
|
||||||
@ -421,7 +440,7 @@ export const GroupAnnouncements = ({
|
|||||||
getAnnouncementData({
|
getAnnouncementData({
|
||||||
name: data.name,
|
name: data.name,
|
||||||
identifier: data.identifier,
|
identifier: data.identifier,
|
||||||
});
|
}, isPrivate);
|
||||||
} catch (error) {}
|
} catch (error) {}
|
||||||
}
|
}
|
||||||
setAnnouncements(responseData);
|
setAnnouncements(responseData);
|
||||||
@ -436,7 +455,7 @@ export const GroupAnnouncements = ({
|
|||||||
|
|
||||||
for (const data of newArray) {
|
for (const data of newArray) {
|
||||||
try {
|
try {
|
||||||
getAnnouncementData({ name: data.name, identifier: data.identifier });
|
getAnnouncementData({ name: data.name, identifier: data.identifier }, isPrivate);
|
||||||
} catch (error) {}
|
} catch (error) {}
|
||||||
}
|
}
|
||||||
setAnnouncements((prev) => [...newArray, ...prev]);
|
setAnnouncements((prev) => [...newArray, ...prev]);
|
||||||
@ -456,14 +475,14 @@ export const GroupAnnouncements = ({
|
|||||||
}, [checkNewMessages]);
|
}, [checkNewMessages]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!secretKey || hide) return;
|
if ((!secretKey && isPrivate) || hide || isPrivate === null) return;
|
||||||
checkNewMessagesFunc();
|
checkNewMessagesFunc();
|
||||||
return () => {
|
return () => {
|
||||||
if (interval?.current) {
|
if (interval?.current) {
|
||||||
clearInterval(interval.current);
|
clearInterval(interval.current);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}, [checkNewMessagesFunc, hide]);
|
}, [checkNewMessagesFunc, hide, isPrivate]);
|
||||||
|
|
||||||
const combinedListTempAndReal = useMemo(() => {
|
const combinedListTempAndReal = useMemo(() => {
|
||||||
// Combine the two lists
|
// Combine the two lists
|
||||||
@ -505,6 +524,7 @@ export const GroupAnnouncements = ({
|
|||||||
setSelectedAnnouncement={setSelectedAnnouncement}
|
setSelectedAnnouncement={setSelectedAnnouncement}
|
||||||
encryptChatMessage={encryptChatMessage}
|
encryptChatMessage={encryptChatMessage}
|
||||||
getSecretKey={getSecretKey}
|
getSecretKey={getSecretKey}
|
||||||
|
isPrivate={isPrivate}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -24,7 +24,8 @@ export const GroupForum = ({
|
|||||||
myAddress,
|
myAddress,
|
||||||
hide,
|
hide,
|
||||||
defaultThread,
|
defaultThread,
|
||||||
setDefaultThread
|
setDefaultThread,
|
||||||
|
isPrivate
|
||||||
}) => {
|
}) => {
|
||||||
const { rootHeight } = useContext(MyContext);
|
const { rootHeight } = useContext(MyContext);
|
||||||
const [isMoved, setIsMoved] = useState(false);
|
const [isMoved, setIsMoved] = useState(false);
|
||||||
@ -50,7 +51,7 @@ export const GroupForum = ({
|
|||||||
left: hide && '-1000px'
|
left: hide && '-1000px'
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<GroupMail hide={hide} getSecretKey={getSecretKey} selectedGroup={selectedGroup} userInfo={userInfo} secretKey={secretKey} defaultThread={defaultThread} setDefaultThread={setDefaultThread} />
|
<GroupMail isPrivate={isPrivate} hide={hide} getSecretKey={getSecretKey} selectedGroup={selectedGroup} userInfo={userInfo} secretKey={secretKey} defaultThread={defaultThread} setDefaultThread={setDefaultThread} />
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -46,7 +46,7 @@ import LazyLoad from "../../../common/LazyLoad";
|
|||||||
import { delay } from "../../../utils/helpers";
|
import { delay } from "../../../utils/helpers";
|
||||||
import { NewThread } from "./NewThread";
|
import { NewThread } from "./NewThread";
|
||||||
import { getBaseApi } from "../../../background";
|
import { getBaseApi } from "../../../background";
|
||||||
import { decryptPublishes, getTempPublish } from "../../Chat/GroupAnnouncements";
|
import { decryptPublishes, getTempPublish, handleUnencryptedPublishes } from "../../Chat/GroupAnnouncements";
|
||||||
import CheckSVG from "../../../assets/svgs/Check.svg";
|
import CheckSVG from "../../../assets/svgs/Check.svg";
|
||||||
import SortSVG from "../../../assets/svgs/Sort.svg";
|
import SortSVG from "../../../assets/svgs/Sort.svg";
|
||||||
import ArrowDownSVG from "../../../assets/svgs/ArrowDown.svg";
|
import ArrowDownSVG from "../../../assets/svgs/ArrowDown.svg";
|
||||||
@ -66,7 +66,8 @@ export const GroupMail = ({
|
|||||||
secretKey,
|
secretKey,
|
||||||
defaultThread,
|
defaultThread,
|
||||||
setDefaultThread,
|
setDefaultThread,
|
||||||
hide
|
hide,
|
||||||
|
isPrivate
|
||||||
}) => {
|
}) => {
|
||||||
const [viewedThreads, setViewedThreads] = React.useState<any>({});
|
const [viewedThreads, setViewedThreads] = React.useState<any>({});
|
||||||
const [filterMode, setFilterMode] = useState<string>("Recently active");
|
const [filterMode, setFilterMode] = useState<string>("Recently active");
|
||||||
@ -123,7 +124,7 @@ export const GroupMail = ({
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const getEncryptedResource = async ({ name, identifier, resource }) => {
|
const getEncryptedResource = async ({ name, identifier, resource }, isPrivate) => {
|
||||||
let data = dataPublishes.current[`${name}-${identifier}`]
|
let data = dataPublishes.current[`${name}-${identifier}`]
|
||||||
if(!data || (data?.update || data?.created !== (resource?.updated || resource?.created))){
|
if(!data || (data?.update || data?.created !== (resource?.updated || resource?.created))){
|
||||||
const res = await fetch(
|
const res = await fetch(
|
||||||
@ -136,7 +137,7 @@ export const GroupMail = ({
|
|||||||
} else {
|
} else {
|
||||||
data = data.data
|
data = data.data
|
||||||
}
|
}
|
||||||
const response = await decryptPublishes([{ data }], secretKey);
|
const response = isPrivate === false ? handleUnencryptedPublishes([data]) : await decryptPublishes([{ data }], secretKey);
|
||||||
|
|
||||||
const messageData = response[0];
|
const messageData = response[0];
|
||||||
return messageData.decryptedData;
|
return messageData.decryptedData;
|
||||||
@ -211,7 +212,7 @@ export const GroupMail = ({
|
|||||||
name: message.name,
|
name: message.name,
|
||||||
identifier: message.identifier,
|
identifier: message.identifier,
|
||||||
resource: message
|
resource: message
|
||||||
}),
|
}, isPrivate),
|
||||||
delay(5000),
|
delay(5000),
|
||||||
]);
|
]);
|
||||||
} catch (error) {}
|
} catch (error) {}
|
||||||
@ -254,7 +255,7 @@ export const GroupMail = ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[allThreads]
|
[allThreads, isPrivate]
|
||||||
);
|
);
|
||||||
const getMailMessages = React.useCallback(
|
const getMailMessages = React.useCallback(
|
||||||
async (groupId: string, members: any) => {
|
async (groupId: string, members: any) => {
|
||||||
@ -331,7 +332,7 @@ export const GroupMail = ({
|
|||||||
name: thread.name,
|
name: thread.name,
|
||||||
identifier: message.threadId,
|
identifier: message.threadId,
|
||||||
resource: thread
|
resource: thread
|
||||||
}),
|
}, isPrivate),
|
||||||
delay(10000),
|
delay(10000),
|
||||||
]);
|
]);
|
||||||
if (threadRes?.title) {
|
if (threadRes?.title) {
|
||||||
@ -360,16 +361,16 @@ export const GroupMail = ({
|
|||||||
// dispatch(setIsLoadingCustom(null));
|
// dispatch(setIsLoadingCustom(null));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[secretKey]
|
[secretKey, isPrivate]
|
||||||
);
|
);
|
||||||
|
|
||||||
const getMessages = React.useCallback(async () => {
|
const getMessages = React.useCallback(async () => {
|
||||||
|
|
||||||
// if ( !groupId || members?.length === 0) return;
|
// if ( !groupId || members?.length === 0) return;
|
||||||
if (!groupId) return;
|
if (!groupId || isPrivate === null) return;
|
||||||
|
|
||||||
await getMailMessages(groupId, members);
|
await getMailMessages(groupId, members);
|
||||||
}, [getMailMessages, groupId, members, secretKey]);
|
}, [getMailMessages, groupId, members, secretKey, isPrivate]);
|
||||||
|
|
||||||
const interval = useRef<any>(null);
|
const interval = useRef<any>(null);
|
||||||
|
|
||||||
@ -382,7 +383,7 @@ export const GroupMail = ({
|
|||||||
firstMount.current = false;
|
firstMount.current = false;
|
||||||
}
|
}
|
||||||
// if (groupId && !firstMount.current && members.length > 0) {
|
// if (groupId && !firstMount.current && members.length > 0) {
|
||||||
if (groupId && !firstMount.current) {
|
if (groupId && !firstMount.current && isPrivate !== null) {
|
||||||
if (filterMode === "Recently active") {
|
if (filterMode === "Recently active") {
|
||||||
getMessages();
|
getMessages();
|
||||||
} else if (filterMode === "Newest") {
|
} else if (filterMode === "Newest") {
|
||||||
@ -393,7 +394,7 @@ export const GroupMail = ({
|
|||||||
setTempData()
|
setTempData()
|
||||||
firstMount.current = true;
|
firstMount.current = true;
|
||||||
}
|
}
|
||||||
}, [groupId, members, filterMode, hide]);
|
}, [groupId, members, filterMode, hide, isPrivate]);
|
||||||
|
|
||||||
const closeThread = useCallback(() => {
|
const closeThread = useCallback(() => {
|
||||||
setCurrentThread(null);
|
setCurrentThread(null);
|
||||||
@ -484,7 +485,7 @@ export const GroupMail = ({
|
|||||||
} else if (filterMode === "Oldest") {
|
} else if (filterMode === "Oldest") {
|
||||||
getAllThreads(groupId, "Oldest", true);
|
getAllThreads(groupId, "Oldest", true);
|
||||||
}
|
}
|
||||||
}, [filterMode])
|
}, [filterMode, isPrivate])
|
||||||
|
|
||||||
const updateThreadActivityCurrentThread = ()=> {
|
const updateThreadActivityCurrentThread = ()=> {
|
||||||
if(!currentThread) return
|
if(!currentThread) return
|
||||||
@ -556,6 +557,7 @@ export const GroupMail = ({
|
|||||||
secretKey={secretKey}
|
secretKey={secretKey}
|
||||||
getSecretKey={getSecretKey}
|
getSecretKey={getSecretKey}
|
||||||
updateThreadActivityCurrentThread={updateThreadActivityCurrentThread}
|
updateThreadActivityCurrentThread={updateThreadActivityCurrentThread}
|
||||||
|
isPrivate={isPrivate}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -636,6 +638,7 @@ export const GroupMail = ({
|
|||||||
userInfo={userInfo}
|
userInfo={userInfo}
|
||||||
getSecretKey={getSecretKey}
|
getSecretKey={getSecretKey}
|
||||||
myName={userInfo?.name}
|
myName={userInfo?.name}
|
||||||
|
isPrivate={isPrivate}
|
||||||
/>
|
/>
|
||||||
<ComposeContainerBlank
|
<ComposeContainerBlank
|
||||||
sx={{
|
sx={{
|
||||||
|
@ -148,7 +148,8 @@ export const NewThread = ({
|
|||||||
closeCallback,
|
closeCallback,
|
||||||
postReply,
|
postReply,
|
||||||
myName,
|
myName,
|
||||||
setPostReply
|
setPostReply,
|
||||||
|
isPrivate
|
||||||
}: NewMessageProps) => {
|
}: NewMessageProps) => {
|
||||||
const { show } = React.useContext(MyContext);
|
const { show } = React.useContext(MyContext);
|
||||||
|
|
||||||
@ -249,8 +250,8 @@ export const NewThread = ({
|
|||||||
reply,
|
reply,
|
||||||
};
|
};
|
||||||
|
|
||||||
const secretKey = await getSecretKey(false, true);
|
const secretKey = isPrivate === false ? null : await getSecretKey(false, true);
|
||||||
if (!secretKey) {
|
if (!secretKey && isPrivate) {
|
||||||
throw new Error("Cannot get group secret key");
|
throw new Error("Cannot get group secret key");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,7 +259,7 @@ export const NewThread = ({
|
|||||||
const idThread = uid.rnd();
|
const idThread = uid.rnd();
|
||||||
const idMsg = uid.rnd();
|
const idMsg = uid.rnd();
|
||||||
const messageToBase64 = await objectToBase64(mailObject);
|
const messageToBase64 = await objectToBase64(mailObject);
|
||||||
const encryptSingleFirstPost = await encryptSingleFunc(
|
const encryptSingleFirstPost = isPrivate === false ? messageToBase64 : await encryptSingleFunc(
|
||||||
messageToBase64,
|
messageToBase64,
|
||||||
secretKey
|
secretKey
|
||||||
);
|
);
|
||||||
@ -270,7 +271,7 @@ export const NewThread = ({
|
|||||||
};
|
};
|
||||||
const threadToBase64 = await objectToBase64(threadObject);
|
const threadToBase64 = await objectToBase64(threadObject);
|
||||||
|
|
||||||
const encryptSingleThread = await encryptSingleFunc(
|
const encryptSingleThread = isPrivate === false ? threadToBase64 : await encryptSingleFunc(
|
||||||
threadToBase64,
|
threadToBase64,
|
||||||
secretKey
|
secretKey
|
||||||
);
|
);
|
||||||
@ -325,7 +326,7 @@ export const NewThread = ({
|
|||||||
if (!currentThread) throw new Error("unable to locate thread Id");
|
if (!currentThread) throw new Error("unable to locate thread Id");
|
||||||
const idThread = currentThread.threadId;
|
const idThread = currentThread.threadId;
|
||||||
const messageToBase64 = await objectToBase64(mailObject);
|
const messageToBase64 = await objectToBase64(mailObject);
|
||||||
const encryptSinglePost = await encryptSingleFunc(
|
const encryptSinglePost = isPrivate === false ? messageToBase64 : await encryptSingleFunc(
|
||||||
messageToBase64,
|
messageToBase64,
|
||||||
secretKey
|
secretKey
|
||||||
);
|
);
|
||||||
|
@ -37,6 +37,7 @@ import { NewThread } from "./NewThread";
|
|||||||
import {
|
import {
|
||||||
decryptPublishes,
|
decryptPublishes,
|
||||||
getTempPublish,
|
getTempPublish,
|
||||||
|
handleUnencryptedPublishes,
|
||||||
} from "../../Chat/GroupAnnouncements";
|
} from "../../Chat/GroupAnnouncements";
|
||||||
import { LoadingSnackbar } from "../../Snackbar/LoadingSnackbar";
|
import { LoadingSnackbar } from "../../Snackbar/LoadingSnackbar";
|
||||||
import { subscribeToEvent, unsubscribeFromEvent } from "../../../utils/events";
|
import { subscribeToEvent, unsubscribeFromEvent } from "../../../utils/events";
|
||||||
@ -71,7 +72,7 @@ const getEncryptedResource = async ({
|
|||||||
resource,
|
resource,
|
||||||
groupId,
|
groupId,
|
||||||
dataPublishes,
|
dataPublishes,
|
||||||
}) => {
|
}, isPrivate) => {
|
||||||
let data = dataPublishes[`${name}-${identifier}`];
|
let data = dataPublishes[`${name}-${identifier}`];
|
||||||
if (
|
if (
|
||||||
!data ||
|
!data ||
|
||||||
@ -99,7 +100,7 @@ const getEncryptedResource = async ({
|
|||||||
} else {
|
} else {
|
||||||
data = data.data;
|
data = data.data;
|
||||||
}
|
}
|
||||||
const response = await decryptPublishes([{ data }], secretKey);
|
const response = isPrivate === false ? handleUnencryptedPublishes([data]) : await decryptPublishes([{ data }], secretKey);
|
||||||
|
|
||||||
const messageData = response[0];
|
const messageData = response[0];
|
||||||
return messageData.decryptedData;
|
return messageData.decryptedData;
|
||||||
@ -114,6 +115,7 @@ export const Thread = ({
|
|||||||
secretKey,
|
secretKey,
|
||||||
getSecretKey,
|
getSecretKey,
|
||||||
updateThreadActivityCurrentThread,
|
updateThreadActivityCurrentThread,
|
||||||
|
isPrivate
|
||||||
}: ThreadProps) => {
|
}: ThreadProps) => {
|
||||||
const [tempPublishedList, setTempPublishedList] = useState([]);
|
const [tempPublishedList, setTempPublishedList] = useState([]);
|
||||||
const [messages, setMessages] = useState<any[]>([]);
|
const [messages, setMessages] = useState<any[]>([]);
|
||||||
@ -164,7 +166,7 @@ export const Thread = ({
|
|||||||
resource: message,
|
resource: message,
|
||||||
groupId: groupInfo?.groupId,
|
groupId: groupInfo?.groupId,
|
||||||
dataPublishes: dataPublishes.current,
|
dataPublishes: dataPublishes.current,
|
||||||
});
|
}, isPrivate);
|
||||||
|
|
||||||
if (responseDataMessage?.error) {
|
if (responseDataMessage?.error) {
|
||||||
const fullObject = {
|
const fullObject = {
|
||||||
@ -323,9 +325,9 @@ export const Thread = ({
|
|||||||
[messages, secretKey]
|
[messages, secretKey]
|
||||||
);
|
);
|
||||||
const getMessages = React.useCallback(async () => {
|
const getMessages = React.useCallback(async () => {
|
||||||
if (!currentThread || !secretKey || !groupInfo?.groupId) return;
|
if (!currentThread || (!secretKey && isPrivate) || !groupInfo?.groupId || isPrivate === null) return;
|
||||||
await getMailMessages(currentThread, null, null, false, groupInfo?.groupId);
|
await getMailMessages(currentThread, null, null, false, groupInfo?.groupId);
|
||||||
}, [getMailMessages, currentThread, secretKey, groupInfo?.groupId]);
|
}, [getMailMessages, currentThread, secretKey, groupInfo?.groupId, isPrivate]);
|
||||||
const firstMount = useRef(false);
|
const firstMount = useRef(false);
|
||||||
|
|
||||||
const saveTimestamp = useCallback((currentThread: any, username?: string) => {
|
const saveTimestamp = useCallback((currentThread: any, username?: string) => {
|
||||||
@ -380,10 +382,11 @@ export const Thread = ({
|
|||||||
if (currentThreadRef.current?.threadId !== currentThread?.threadId) {
|
if (currentThreadRef.current?.threadId !== currentThread?.threadId) {
|
||||||
firstMount.current = false;
|
firstMount.current = false;
|
||||||
}
|
}
|
||||||
if (currentThread && secretKey && !firstMount.current) {
|
if(!secretKey && isPrivate) return
|
||||||
|
if (currentThread && !firstMount.current && isPrivate !== null) {
|
||||||
getMessagesMiddleware();
|
getMessagesMiddleware();
|
||||||
}
|
}
|
||||||
}, [currentThread, secretKey]);
|
}, [currentThread, secretKey, isPrivate]);
|
||||||
const messageCallback = useCallback((msg: any) => {
|
const messageCallback = useCallback((msg: any) => {
|
||||||
// dispatch(addToHashMapMail(msg))
|
// dispatch(addToHashMapMail(msg))
|
||||||
// setMessages((prev) => [msg, ...prev])
|
// setMessages((prev) => [msg, ...prev])
|
||||||
@ -576,6 +579,8 @@ export const Thread = ({
|
|||||||
myName={userInfo?.name}
|
myName={userInfo?.name}
|
||||||
publishCallback={setTempData}
|
publishCallback={setTempData}
|
||||||
setPostReply={setPostReply}
|
setPostReply={setPostReply}
|
||||||
|
isPrivate={isPrivate}
|
||||||
|
|
||||||
/>
|
/>
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
|
@ -52,7 +52,27 @@ const sellerForeignFee = {
|
|||||||
'LITECOIN': {
|
'LITECOIN': {
|
||||||
value: '~0.00005',
|
value: '~0.00005',
|
||||||
ticker: 'LTC'
|
ticker: 'LTC'
|
||||||
}
|
},
|
||||||
|
DOGECOIN: {
|
||||||
|
value: "~0.005",
|
||||||
|
ticker: "DOGE",
|
||||||
|
},
|
||||||
|
BITCOIN: {
|
||||||
|
value: "~0.0001",
|
||||||
|
ticker: "BTC",
|
||||||
|
},
|
||||||
|
DIGIBYTE: {
|
||||||
|
value: "~0.0005",
|
||||||
|
ticker: "DGB",
|
||||||
|
},
|
||||||
|
RAVENCOIN: {
|
||||||
|
value: "~0.006",
|
||||||
|
ticker: "RVN",
|
||||||
|
},
|
||||||
|
PIRATECHAIN: {
|
||||||
|
value: "~0.0002",
|
||||||
|
ticker: "ARRR",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1727,38 +1747,68 @@ export const getWalletBalance = async (data, bypassPermission?: boolean, isFromE
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getPirateWallet = async (arrrSeed58)=> {
|
||||||
|
const bodyToString = arrrSeed58;
|
||||||
|
const url = await createEndpoint(`/crosschain/arrr/walletaddress`);
|
||||||
|
const response = await fetch(url, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: bodyToString,
|
||||||
|
});
|
||||||
|
let res;
|
||||||
|
try {
|
||||||
|
res = await response.clone().json();
|
||||||
|
} catch (e) {
|
||||||
|
res = await response.text();
|
||||||
|
}
|
||||||
|
if (res?.error && res?.message) {
|
||||||
|
throw new Error(res.message);
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
export const getUserWalletFunc = async (coin) => {
|
export const getUserWalletFunc = async (coin) => {
|
||||||
let userWallet = {};
|
let userWallet = {};
|
||||||
const wallet = await getSaveWallet();
|
const wallet = await getSaveWallet();
|
||||||
const address = wallet.address0;
|
const address = wallet.address0;
|
||||||
const resKeyPair = await getKeyPair();
|
const resKeyPair = await getKeyPair();
|
||||||
const parsedData = JSON.parse(resKeyPair);
|
const parsedData = resKeyPair;
|
||||||
switch (coin) {
|
switch (coin) {
|
||||||
case "QORT":
|
case "QORT":
|
||||||
userWallet["address"] = address;
|
userWallet["address"] = address;
|
||||||
userWallet["publickey"] = parsedData.publicKey;
|
userWallet["publickey"] = parsedData.publicKey;
|
||||||
break;
|
break;
|
||||||
case "BTC":
|
case "BTC":
|
||||||
|
case "BITCOIN":
|
||||||
userWallet["address"] = parsedData.btcAddress;
|
userWallet["address"] = parsedData.btcAddress;
|
||||||
userWallet["publickey"] = parsedData.btcPublicKey;
|
userWallet["publickey"] = parsedData.btcPublicKey;
|
||||||
break;
|
break;
|
||||||
case "LTC":
|
case "LTC":
|
||||||
|
case "LITECOIN":
|
||||||
userWallet["address"] = parsedData.ltcAddress;
|
userWallet["address"] = parsedData.ltcAddress;
|
||||||
userWallet["publickey"] = parsedData.ltcPublicKey;
|
userWallet["publickey"] = parsedData.ltcPublicKey;
|
||||||
break;
|
break;
|
||||||
case "DOGE":
|
case "DOGE":
|
||||||
|
case "DOGECOIN":
|
||||||
userWallet["address"] = parsedData.dogeAddress;
|
userWallet["address"] = parsedData.dogeAddress;
|
||||||
userWallet["publickey"] = parsedData.dogePublicKey;
|
userWallet["publickey"] = parsedData.dogePublicKey;
|
||||||
break;
|
break;
|
||||||
case "DGB":
|
case "DGB":
|
||||||
|
case "DIGIBYTE":
|
||||||
userWallet["address"] = parsedData.dgbAddress;
|
userWallet["address"] = parsedData.dgbAddress;
|
||||||
userWallet["publickey"] = parsedData.dgbPublicKey;
|
userWallet["publickey"] = parsedData.dgbPublicKey;
|
||||||
break;
|
break;
|
||||||
case "RVN":
|
case "RVN":
|
||||||
|
case "RAVENCOIN":
|
||||||
userWallet["address"] = parsedData.rvnAddress;
|
userWallet["address"] = parsedData.rvnAddress;
|
||||||
userWallet["publickey"] = parsedData.rvnPublicKey;
|
userWallet["publickey"] = parsedData.rvnPublicKey;
|
||||||
break;
|
break;
|
||||||
case "ARRR":
|
case "ARRR":
|
||||||
|
case "PIRATECHAIN":
|
||||||
|
const arrrAddress = await getPirateWallet(parsedData.arrrSeed58)
|
||||||
|
userWallet["address"] = arrrAddress
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -2334,9 +2384,9 @@ export const sendCoin = async (data, isFromExtension) => {
|
|||||||
throw new Error('Unable to fetch BTC balance')
|
throw new Error('Unable to fetch BTC balance')
|
||||||
}
|
}
|
||||||
const btcWalletBalanceDecimals = Number(btcWalletBalance)
|
const btcWalletBalanceDecimals = Number(btcWalletBalance)
|
||||||
const btcAmountDecimals = Number(amount) * QORT_DECIMALS
|
const btcAmountDecimals = Number(amount)
|
||||||
const fee = feePerByte * 500 // default 0.00050000
|
const fee = feePerByte * 500 // default 0.00050000
|
||||||
if (btcAmountDecimals + (fee * QORT_DECIMALS) > btcWalletBalanceDecimals) {
|
if (btcAmountDecimals + fee > btcWalletBalanceDecimals) {
|
||||||
throw new Error("INSUFFICIENT_FUNDS")
|
throw new Error("INSUFFICIENT_FUNDS")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2391,10 +2441,9 @@ export const sendCoin = async (data, isFromExtension) => {
|
|||||||
throw new Error(errorMsg)
|
throw new Error(errorMsg)
|
||||||
}
|
}
|
||||||
const ltcWalletBalanceDecimals = Number(ltcWalletBalance)
|
const ltcWalletBalanceDecimals = Number(ltcWalletBalance)
|
||||||
const ltcAmountDecimals = Number(amount) * QORT_DECIMALS
|
const ltcAmountDecimals = Number(amount)
|
||||||
const balance = (Number(ltcWalletBalance) / 1e8).toFixed(8)
|
|
||||||
const fee = feePerByte * 1000 // default 0.00030000
|
const fee = feePerByte * 1000 // default 0.00030000
|
||||||
if (ltcAmountDecimals + (fee * QORT_DECIMALS) > ltcWalletBalanceDecimals) {
|
if (ltcAmountDecimals + fee > ltcWalletBalanceDecimals) {
|
||||||
throw new Error("Insufficient Funds!")
|
throw new Error("Insufficient Funds!")
|
||||||
}
|
}
|
||||||
const resPermission = await getUserPermission({
|
const resPermission = await getUserPermission({
|
||||||
@ -2446,10 +2495,10 @@ export const sendCoin = async (data, isFromExtension) => {
|
|||||||
throw new Error(errorMsg)
|
throw new Error(errorMsg)
|
||||||
}
|
}
|
||||||
const dogeWalletBalanceDecimals = Number(dogeWalletBalance)
|
const dogeWalletBalanceDecimals = Number(dogeWalletBalance)
|
||||||
const dogeAmountDecimals = Number(amount) * QORT_DECIMALS
|
const dogeAmountDecimals = Number(amount)
|
||||||
const balance = (Number(dogeWalletBalance) / 1e8).toFixed(8)
|
const balance = (Number(dogeWalletBalance) / 1e8).toFixed(8)
|
||||||
const fee = feePerByte * 5000 // default 0.05000000
|
const fee = feePerByte * 5000 // default 0.05000000
|
||||||
if (dogeAmountDecimals + (fee * QORT_DECIMALS) > dogeWalletBalanceDecimals) {
|
if (dogeAmountDecimals + fee > dogeWalletBalanceDecimals) {
|
||||||
let errorMsg = "Insufficient Funds!"
|
let errorMsg = "Insufficient Funds!"
|
||||||
throw new Error(errorMsg)
|
throw new Error(errorMsg)
|
||||||
}
|
}
|
||||||
@ -2502,9 +2551,9 @@ export const sendCoin = async (data, isFromExtension) => {
|
|||||||
throw new Error(errorMsg)
|
throw new Error(errorMsg)
|
||||||
}
|
}
|
||||||
const dgbWalletBalanceDecimals = Number(dgbWalletBalance)
|
const dgbWalletBalanceDecimals = Number(dgbWalletBalance)
|
||||||
const dgbAmountDecimals = Number(amount) * QORT_DECIMALS
|
const dgbAmountDecimals = Number(amount)
|
||||||
const fee = feePerByte * 500 // default 0.00005000
|
const fee = feePerByte * 500 // default 0.00005000
|
||||||
if (dgbAmountDecimals + (fee * QORT_DECIMALS) > dgbWalletBalanceDecimals) {
|
if (dgbAmountDecimals + fee > dgbWalletBalanceDecimals) {
|
||||||
let errorMsg = "Insufficient Funds!"
|
let errorMsg = "Insufficient Funds!"
|
||||||
throw new Error(errorMsg)
|
throw new Error(errorMsg)
|
||||||
}
|
}
|
||||||
@ -2558,10 +2607,10 @@ export const sendCoin = async (data, isFromExtension) => {
|
|||||||
throw new Error(errorMsg)
|
throw new Error(errorMsg)
|
||||||
}
|
}
|
||||||
const rvnWalletBalanceDecimals = Number(rvnWalletBalance)
|
const rvnWalletBalanceDecimals = Number(rvnWalletBalance)
|
||||||
const rvnAmountDecimals = Number(amount) * QORT_DECIMALS
|
const rvnAmountDecimals = Number(amount)
|
||||||
const balance = (Number(rvnWalletBalance) / 1e8).toFixed(8)
|
const balance = (Number(rvnWalletBalance) / 1e8).toFixed(8)
|
||||||
const fee = feePerByte * 500 // default 0.00562500
|
const fee = feePerByte * 500 // default 0.00562500
|
||||||
if (rvnAmountDecimals + (fee * QORT_DECIMALS) > rvnWalletBalanceDecimals) {
|
if (rvnAmountDecimals + fee > rvnWalletBalanceDecimals) {
|
||||||
|
|
||||||
let errorMsg = "Insufficient Funds!"
|
let errorMsg = "Insufficient Funds!"
|
||||||
throw new Error(errorMsg)
|
throw new Error(errorMsg)
|
||||||
@ -2614,9 +2663,9 @@ export const sendCoin = async (data, isFromExtension) => {
|
|||||||
throw new Error(errorMsg)
|
throw new Error(errorMsg)
|
||||||
}
|
}
|
||||||
const arrrWalletBalanceDecimals = Number(arrrWalletBalance)
|
const arrrWalletBalanceDecimals = Number(arrrWalletBalance)
|
||||||
const arrrAmountDecimals = Number(amount) * QORT_DECIMALS
|
const arrrAmountDecimals = Number(amount)
|
||||||
const fee = 0.00010000
|
const fee = 0.00010000
|
||||||
if (arrrAmountDecimals + (fee * QORT_DECIMALS) > arrrWalletBalanceDecimals) {
|
if (arrrAmountDecimals + fee > arrrWalletBalanceDecimals) {
|
||||||
let errorMsg = "Insufficient Funds!"
|
let errorMsg = "Insufficient Funds!"
|
||||||
throw new Error(errorMsg)
|
throw new Error(errorMsg)
|
||||||
}
|
}
|
||||||
@ -2867,7 +2916,7 @@ export const createSellOrder = async (data, isFromExtension) => {
|
|||||||
throw new Error(errorMsg);
|
throw new Error(errorMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
const receivingAddress = await getUserWalletFunc('LTC')
|
const receivingAddress = await getUserWalletFunc(data.foreignBlockchain)
|
||||||
try {
|
try {
|
||||||
const resPermission = await getUserPermission({
|
const resPermission = await getUserPermission({
|
||||||
text1: "Do you give this application permission to perform a sell order?",
|
text1: "Do you give this application permission to perform a sell order?",
|
||||||
|
41
src/transactions/TradeBotRespondRequest.ts
Normal file
41
src/transactions/TradeBotRespondRequest.ts
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
// @ts-nocheck
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CrossChain - TradeBot Respond Request (Buy Action)
|
||||||
|
*
|
||||||
|
* These are special types of transactions (JSON ENCODED)
|
||||||
|
*/
|
||||||
|
|
||||||
|
export default class TradeBotRespondRequest {
|
||||||
|
constructor() {
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
|
||||||
|
createTransaction(txnReq) {
|
||||||
|
this.atAddress(txnReq.atAddress)
|
||||||
|
this.foreignKey(txnReq.foreignKey)
|
||||||
|
this.receivingAddress(txnReq.receivingAddress)
|
||||||
|
|
||||||
|
return this.txnRequest()
|
||||||
|
}
|
||||||
|
|
||||||
|
atAddress(atAddress) {
|
||||||
|
this._atAddress = atAddress
|
||||||
|
}
|
||||||
|
|
||||||
|
foreignKey(foreignKey) {
|
||||||
|
this._foreignKey = foreignKey
|
||||||
|
}
|
||||||
|
|
||||||
|
receivingAddress(receivingAddress) {
|
||||||
|
this._receivingAddress = receivingAddress
|
||||||
|
}
|
||||||
|
|
||||||
|
txnRequest() {
|
||||||
|
return {
|
||||||
|
atAddress: this._atAddress,
|
||||||
|
foreignKey: this._foreignKey,
|
||||||
|
receivingAddress: this._receivingAddress
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user