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