diff --git a/package-lock.json b/package-lock.json
index 9544375..bd6bd42 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -69,6 +69,7 @@
"react-frame-component": "^5.2.7",
"react-infinite-scroller": "^1.2.6",
"react-intersection-observer": "^9.13.0",
+ "react-json-view-lite": "^2.0.1",
"react-qr-code": "^2.0.15",
"react-quill": "^2.0.0",
"react-redux": "^9.1.2",
@@ -14416,6 +14417,17 @@
"resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz",
"integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ=="
},
+ "node_modules/react-json-view-lite": {
+ "version": "2.0.1",
+ "resolved": "https://registry.npmjs.org/react-json-view-lite/-/react-json-view-lite-2.0.1.tgz",
+ "integrity": "sha512-yElNMSzL7UJ9rMDQIbTiBemXbvfAoqpxM/0IQd3nr52CLLBC0HxOSKcta/bayct2QCq7ZVzLzI8CGfuf387hHw==",
+ "engines": {
+ "node": ">=18"
+ },
+ "peerDependencies": {
+ "react": "^18.0.0"
+ }
+ },
"node_modules/react-lifecycles-compat": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz",
diff --git a/package.json b/package.json
index 214fa1f..0cf5df4 100644
--- a/package.json
+++ b/package.json
@@ -73,6 +73,7 @@
"react-frame-component": "^5.2.7",
"react-infinite-scroller": "^1.2.6",
"react-intersection-observer": "^9.13.0",
+ "react-json-view-lite": "^2.0.1",
"react-qr-code": "^2.0.15",
"react-quill": "^2.0.0",
"react-redux": "^9.1.2",
diff --git a/src/App.tsx b/src/App.tsx
index 2154a66..3f555f4 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -25,6 +25,8 @@ import {
Tooltip,
Typography,
} from "@mui/material";
+import { JsonView, allExpanded, darkStyles } from 'react-json-view-lite';
+import 'react-json-view-lite/dist/index.css';
import { decryptStoredWallet } from "./utils/decryptWallet";
import { CountdownCircleTimer } from "react-countdown-circle-timer";
import Logo1 from "./assets/svgs/Logo1.svg";
@@ -113,12 +115,14 @@ import {
} from "./atoms/global";
import { useAppFullScreen } from "./useAppFullscreen";
import { NotAuthenticated } from "./ExtStates/NotAuthenticated";
-import { openIndexedDB, showSaveFilePicker } from "./components/Apps/useQortalMessageListener";
+import {
+ openIndexedDB,
+ showSaveFilePicker,
+} from "./components/Apps/useQortalMessageListener";
import { fileToBase64 } from "./utils/fileReading";
import { handleGetFileFromIndexedDB } from "./utils/indexedDB";
import { CoreSyncStatus } from "./components/CoreSyncStatus";
-
type extStates =
| "not-authenticated"
| "authenticated"
@@ -372,16 +376,17 @@ function App() {
useRetrieveDataLocalStorage();
useQortalGetSaveSettings(userInfo?.name);
const [fullScreen, setFullScreen] = useRecoilState(fullScreenAtom);
- const [isEnabledDevMode, setIsEnabledDevMode] = useRecoilState(enabledDevModeAtom)
+ const [isEnabledDevMode, setIsEnabledDevMode] =
+ useRecoilState(enabledDevModeAtom);
const { toggleFullScreen } = useAppFullScreen(setFullScreen);
- useEffect(()=> {
- const isDevModeFromStorage = localStorage.getItem('isEnabledDevMode');
- if(isDevModeFromStorage){
- setIsEnabledDevMode(JSON.parse(isDevModeFromStorage))
- }
- }, [])
+ useEffect(() => {
+ const isDevModeFromStorage = localStorage.getItem("isEnabledDevMode");
+ if (isDevModeFromStorage) {
+ setIsEnabledDevMode(JSON.parse(isDevModeFromStorage));
+ }
+ }, []);
useEffect(() => {
// Attach a global event listener for double-click
@@ -575,7 +580,6 @@ function App() {
};
};
-
const getBalanceFunc = () => {
setQortBalanceLoading(true);
window
@@ -651,11 +655,12 @@ function App() {
const qortalRequestPermissonFromExtension = async (message, event) => {
if (message.action === "QORTAL_REQUEST_PERMISSION") {
try {
- if(message?.payload?.checkbox1){
- qortalRequestCheckbox1Ref.current = message?.payload?.checkbox1?.value || false
+ if (message?.payload?.checkbox1) {
+ qortalRequestCheckbox1Ref.current =
+ message?.payload?.checkbox1?.value || false;
}
await showQortalRequestExtension(message?.payload);
-
+
if (qortalRequestCheckbox1Ref.current) {
event.source.postMessage(
{
@@ -694,13 +699,12 @@ function App() {
}
}
};
-
useEffect(() => {
// Handler function for incoming messages
const messageHandler = (event) => {
if (event.origin !== window.location.origin) {
- return;
+ return;
}
const message = event.data;
@@ -717,15 +721,11 @@ function App() {
executeEvent("openGroupMessage", {
from: message.payload.from,
});
- } else if (
- message.action === "NOTIFICATION_OPEN_ANNOUNCEMENT_GROUP"
- ) {
+ } else if (message.action === "NOTIFICATION_OPEN_ANNOUNCEMENT_GROUP") {
executeEvent("openGroupAnnouncement", {
from: message.payload.from,
});
- } else if (
- message.action === "NOTIFICATION_OPEN_THREAD_NEW_POST"
- ) {
+ } else if (message.action === "NOTIFICATION_OPEN_THREAD_NEW_POST") {
executeEvent("openThreadNewPost", {
data: message.payload.data,
});
@@ -734,8 +734,7 @@ function App() {
message?.isFromExtension
) {
qortalRequestPermissonFromExtension(message, event);
- }
- else if(message?.action === 'getFileFromIndexedDB'){
+ } else if (message?.action === "getFileFromIndexedDB") {
handleGetFileFromIndexedDB(event);
}
};
@@ -780,9 +779,8 @@ function App() {
holdRefExtState.current === "web-app-request-buy-order"
)
return;
- if(response?.hasKeyPair){
+ if (response?.hasKeyPair) {
setExtstate("authenticated");
-
} else {
setExtstate("wallet-dropped");
}
@@ -869,7 +867,6 @@ function App() {
walletToBeDownloaded.wallet,
walletToBeDownloaded.qortAddress
);
-
} catch (error: any) {
setWalletToBeDownloadedError(error?.message);
} finally {
@@ -1014,7 +1011,7 @@ function App() {
resetAllRecoil();
};
- function roundUpToDecimals(number, decimals = 8) {
+ function roundUpToDecimals(number, decimals = 8) {
const factor = Math.pow(10, decimals); // Create a factor based on the number of decimals
return Math.ceil(+number * factor) / factor;
}
@@ -1029,10 +1026,14 @@ function App() {
}, 250);
});
window
- .sendMessage("decryptWallet", {
- password: authenticatePassword,
- wallet: rawWallet,
- }, 120000)
+ .sendMessage(
+ "decryptWallet",
+ {
+ password: authenticatePassword,
+ wallet: rawWallet,
+ },
+ 120000
+ )
.then((response) => {
if (response && !response.error) {
setAuthenticatePassword("");
@@ -1078,9 +1079,6 @@ function App() {
}
};
-
-
-
useEffect(() => {
if (!isMainWindow) return;
// Handler for when the window gains focus
@@ -1220,7 +1218,7 @@ function App() {
width: isMobile ? "100vw" : "auto",
display: "flex",
backgroundColor: "var(--bg-2)",
- justifyContent: 'flex-end'
+ justifyContent: "flex-end",
}}
>
{isMobile && (
@@ -1242,237 +1240,268 @@ function App() {
/>
)}
- {desktopViewMode !== "apps" && desktopViewMode !== "dev" && desktopViewMode !== "chat" && (
-
-
-
- {authenticatedMode === "ltc" ? (
- <>
-
-
-
-
- {rawWallet?.ltcAddress?.slice(0, 6)}...
- {rawWallet?.ltcAddress?.slice(-4)}
-
-
-
- {ltcBalanceLoading && (
-
- )}
- {!isNaN(+ltcBalance) && !ltcBalanceLoading && (
-
+
+
+ {authenticatedMode === "ltc" ? (
+ <>
+
+
+
+
+ {rawWallet?.ltcAddress?.slice(0, 6)}...
+ {rawWallet?.ltcAddress?.slice(-4)}
+
+
+
+ {ltcBalanceLoading && (
+
+ )}
+ {!isNaN(+ltcBalance) && !ltcBalanceLoading && (
+
+
+ {ltcBalance} LTC
+
+
+
+ )}
+
+ >
+ ) : (
+ <>
+
+
+
+ {userInfo?.name}
+
+
+
+
+ {rawWallet?.address0?.slice(0, 6)}...
+ {rawWallet?.address0?.slice(-4)}
+
+
+
+ {qortBalanceLoading && (
+
+ )}
+ {!qortBalanceLoading && balance >= 0 && (
+
+
+ {balance?.toFixed(2)} QORT
+
+
+
+ )}
+
+
+ {userInfo && !userInfo?.name && (
+ {
+ setOpenRegisterName(true);
+ }}
+ >
+ REGISTER NAME
+
+ )}
+
+ {
+ setIsOpenSendQort(true);
+ // setExtstate("send-qort");
+ setIsOpenDrawerProfile(false);
+ }}
+ >
+ Transfer QORT
+
+
+ >
+ )}
{
+ executeEvent("addTab", {
+ data: { service: "APP", name: "q-trade" },
+ });
+ executeEvent("open-apps-mode", {});
}}
>
- {ltcBalance} LTC
+ Get QORT at Q-Trade
-
-
+
)}
-
- >
- ) : (
- <>
-
-
-
+
- {userInfo?.name}
-
-
-
-
- {rawWallet?.address0?.slice(0, 6)}...
- {rawWallet?.address0?.slice(-4)}
-
-
-
- {qortBalanceLoading && (
-
- )}
- {!qortBalanceLoading && balance >= 0 && (
-
+
+ {!isMobile && (
+ <>
+
+
{
+ logoutFunc();
+ setIsOpenDrawerProfile(false);
+ }}
+ style={{
+ cursor: "pointer",
+ width: '20px',
+ height: 'auto'
+ }}
+ />
+ >
+ )}
+
+
+ {
+ setIsSettingsOpen(true);
}}
>
-
- {balance?.toFixed(2)} QORT
-
-
-
- )}
-
-
- {userInfo && !userInfo?.name && (
- {
- setOpenRegisterName(true);
- }}
- >
- REGISTER NAME
-
- )}
-
- {
- setIsOpenSendQort(true);
- // setExtstate("send-qort");
- setIsOpenDrawerProfile(false);
- }}
- >
- Transfer QORT
-
-
- >
- )}
- {
- executeEvent("addTab", { data: { service: 'APP', name: 'q-trade' } });
- executeEvent("open-apps-mode", { });
- }}
- >
- Get QORT at Q-Trade
-
-
- )}
-
-
-
-
-
{
- setExtstate("download-wallet");
- setIsOpenDrawerProfile(false);
- }}
- src={Download}
- style={{
- cursor: "pointer",
- }}
- />
- {!isMobile && (
- <>
-
+
+
+ {authenticatedMode === "qort" && (
{
- logoutFunc();
- setIsOpenDrawerProfile(false);
+ setAuthenticatedMode("ltc");
}}
+ src={ltcLogo}
style={{
cursor: "pointer",
+ width: "20px",
+ height: "auto",
}}
/>
- >
- )}
-
-
- {
- setIsSettingsOpen(true);
+ )}
+ {authenticatedMode === "ltc" && (
+
{
+ setAuthenticatedMode("qort");
+ }}
+ src={qortLogo}
+ style={{
+ cursor: "pointer",
+ width: "20px",
+ height: "auto",
+ }}
+ />
+ )}
+
+
+
+
-
-
-
- {authenticatedMode === "qort" && (
-
{
- setAuthenticatedMode("ltc");
+ setExtstate("download-wallet");
+ setIsOpenDrawerProfile(false);
}}
- src={ltcLogo}
+ src={Download}
style={{
cursor: "pointer",
- width: "20px",
- height: "auto",
+ width: '20px'
}}
/>
- )}
- {authenticatedMode === "ltc" && (
-
{
- setAuthenticatedMode("qort");
- }}
- src={qortLogo}
- style={{
- cursor: "pointer",
- width: "20px",
- height: "auto",
- }}
- />
- )}
-
-
+
+
);
@@ -1516,10 +1545,10 @@ function App() {
message,
rootHeight,
showInfo,
- openSnackGlobal: openSnack,
+ openSnackGlobal: openSnack,
setOpenSnackGlobal: setOpenSnack,
infoSnackCustom: infoSnack,
- setInfoSnackCustom: setInfoSnack
+ setInfoSnackCustom: setInfoSnack,
}}
>
- {!isMobile && renderProfile()}
+ {!isMobile && renderProfile()}
{
setRawWallet(null);
setExtstate("not-authenticated");
- logoutFunc()
+ logoutFunc();
}}
src={Return}
/>
@@ -2308,12 +2337,14 @@ function App() {
{walletToBeDownloaded && (
<>
- {
- await saveFileToDiskFunc()
-await showInfo({
- message: `Keep your wallet file secure.`,
- })
- }}>
+ {
+ await saveFileToDiskFunc();
+ await showInfo({
+ message: `Keep your wallet file secure.`,
+ });
+ }}
+ >
Download wallet
>
@@ -2417,7 +2448,7 @@ await showInfo({
returnToMain();
await showInfo({
message: `Keep your wallet file secure.`,
- })
+ });
}}
>
Backup Account
@@ -2567,10 +2598,8 @@ await showInfo({
{messageInfo.message}
-
-
@@ -2734,6 +2763,16 @@ await showInfo({
{messageQortalRequestExtension?.highlightedText}
+ {messageQortalRequestExtension?.json && (
+ <>
+
+
+
+
+
+ >
+ )}
+
{messageQortalRequestExtension?.fee && (
<>
diff --git a/src/components/Apps/useQortalMessageListener.tsx b/src/components/Apps/useQortalMessageListener.tsx
index 9638826..8cb95f9 100644
--- a/src/components/Apps/useQortalMessageListener.tsx
+++ b/src/components/Apps/useQortalMessageListener.tsx
@@ -182,7 +182,7 @@ const UIQortalRequests = [
'GET_WALLET_BALANCE', 'GET_USER_WALLET_INFO', 'GET_CROSSCHAIN_SERVER_INFO',
'GET_TX_ACTIVITY_SUMMARY', 'GET_FOREIGN_FEE', 'UPDATE_FOREIGN_FEE',
'GET_SERVER_CONNECTION_HISTORY', 'SET_CURRENT_FOREIGN_SERVER',
- 'ADD_FOREIGN_SERVER', 'REMOVE_FOREIGN_SERVER', 'GET_DAY_SUMMARY', 'CREATE_TRADE_BUY_ORDER', 'CREATE_TRADE_SELL_ORDER', 'CANCEL_TRADE_SELL_ORDER', 'IS_USING_GATEWAY', 'ADMIN_ACTION'
+ 'ADD_FOREIGN_SERVER', 'REMOVE_FOREIGN_SERVER', 'GET_DAY_SUMMARY', 'CREATE_TRADE_BUY_ORDER', 'CREATE_TRADE_SELL_ORDER', 'CANCEL_TRADE_SELL_ORDER', 'IS_USING_GATEWAY', 'ADMIN_ACTION', 'SIGN_TRANSACTION'
];
diff --git a/src/qdn/publish/pubish.ts b/src/qdn/publish/pubish.ts
index 79bd6f2..08c4d15 100644
--- a/src/qdn/publish/pubish.ts
+++ b/src/qdn/publish/pubish.ts
@@ -113,6 +113,7 @@ export const publishData = async ({
transactionBytesBase58
)
+
if (convertedBytesBase58.error) {
throw new Error('Error when signing')
}
diff --git a/src/qortalRequests.ts b/src/qortalRequests.ts
index 6d78abd..d7fb583 100644
--- a/src/qortalRequests.ts
+++ b/src/qortalRequests.ts
@@ -1,5 +1,5 @@
import { gateways, getApiKeyFromStorage } from "./background";
-import { addForeignServer, addListItems, adminAction, cancelSellOrder, createBuyOrder, createPoll, createSellOrder, decryptData, deleteListItems, deployAt, encryptData, getCrossChainServerInfo, getDaySummary, getForeignFee, getListItems, getServerConnectionHistory, getTxActivitySummary, getUserAccount, getUserWallet, getUserWalletInfo, getWalletBalance, joinGroup, publishMultipleQDNResources, publishQDNResource, removeForeignServer, saveFile, sendChatMessage, sendCoin, setCurrentForeignServer, updateForeignFee, voteOnPoll } from "./qortalRequests/get";
+import { addForeignServer, addListItems, adminAction, cancelSellOrder, createBuyOrder, createPoll, createSellOrder, decryptData, deleteListItems, deployAt, encryptData, getCrossChainServerInfo, getDaySummary, getForeignFee, getListItems, getServerConnectionHistory, getTxActivitySummary, getUserAccount, getUserWallet, getUserWalletInfo, getWalletBalance, joinGroup, publishMultipleQDNResources, publishQDNResource, removeForeignServer, saveFile, sendChatMessage, sendCoin, setCurrentForeignServer, signTransaction, updateForeignFee, voteOnPoll } from "./qortalRequests/get";
import { getData, storeData } from "./utils/chromeStorage";
@@ -691,6 +691,26 @@ export const isRunningGateway = async ()=> {
}
break;
}
+ case "SIGN_TRANSACTION": {
+ try {
+ const res = await signTransaction(request.payload, isFromExtension)
+ event.source.postMessage({
+ requestId: request.requestId,
+ action: request.action,
+ payload: res,
+ type: "backgroundMessageResponse",
+ }, event.origin);
+ } catch (error) {
+ event.source.postMessage({
+ requestId: request.requestId,
+ action: request.action,
+ error: error?.message,
+ type: "backgroundMessageResponse",
+ }, event.origin);
+ }
+ break;
+ }
+
default:
break;
}
diff --git a/src/qortalRequests/get.ts b/src/qortalRequests/get.ts
index 8b81322..0ac2cac 100644
--- a/src/qortalRequests/get.ts
+++ b/src/qortalRequests/get.ts
@@ -14,12 +14,13 @@ import {
sendCoin as sendCoinFunc,
isUsingLocal,
createBuyOrderTx,
- performPowTask
+ performPowTask,
} from "../background";
import { getNameInfo } from "../backgroundFunctions/encryption";
import { showSaveFilePicker } from "../components/Apps/useQortalMessageListener";
import { QORT_DECIMALS } from "../constants/constants";
import Base58 from "../deps/Base58";
+import nacl from "../deps/nacl-fast";
import {
base64ToUint8Array,
decryptDeprecatedSingle,
@@ -29,41 +30,52 @@ import {
uint8ArrayToBase64,
} from "../qdn/encryption/group-encryption";
import { publishData } from "../qdn/publish/pubish";
-import { getPermission, isRunningGateway, setPermission } from "../qortalRequests";
+import {
+ getPermission,
+ isRunningGateway,
+ setPermission,
+} from "../qortalRequests";
import TradeBotCreateRequest from "../transactions/TradeBotCreateRequest";
import DeleteTradeOffer from "../transactions/TradeBotDeleteRequest";
import signTradeBotTransaction from "../transactions/signTradeBotTransaction";
import { createTransaction } from "../transactions/transactions";
import { mimeToExtensionMap } from "../utils/memeTypes";
+import utils from "../utils/utils";
const sellerForeignFee = {
- 'LITECOIN': {
- value: '~0.00005',
- ticker: 'LTC'
- }
-}
+ LITECOIN: {
+ value: "~0.00005",
+ ticker: "LTC",
+ },
+};
-const btcFeePerByte = 0.00000100
-const ltcFeePerByte = 0.00000030
-const dogeFeePerByte = 0.00001000
-const dgbFeePerByte = 0.00000010
-const rvnFeePerByte = 0.00001125
+const btcFeePerByte = 0.000001;
+const ltcFeePerByte = 0.0000003;
+const dogeFeePerByte = 0.00001;
+const dgbFeePerByte = 0.0000001;
+const rvnFeePerByte = 0.00001125;
function roundUpToDecimals(number, decimals = 8) {
const factor = Math.pow(10, decimals); // Create a factor based on the number of decimals
return Math.ceil(+number * factor) / factor;
}
-const _createPoll = async ({pollName, pollDescription, options}, isFromExtension) => {
+const _createPoll = async (
+ { pollName, pollDescription, options },
+ isFromExtension
+) => {
const fee = await getFee("CREATE_POLL");
- const resPermission = await getUserPermission({
- text1: "You are requesting to create the poll below:",
- text2: `Poll: ${pollName}`,
- text3: `Description: ${pollDescription}`,
- text4: `Options: ${options?.join(", ")}`,
- fee: fee.fee,
- }, isFromExtension);
+ const resPermission = await getUserPermission(
+ {
+ text1: "You are requesting to create the poll below:",
+ text2: `Poll: ${pollName}`,
+ text3: `Description: ${pollDescription}`,
+ text4: `Options: ${options?.join(", ")}`,
+ fee: fee.fee,
+ },
+ isFromExtension
+ );
const { accepted } = resPermission;
if (accepted) {
@@ -90,7 +102,9 @@ const _createPoll = async ({pollName, pollDescription, options}, isFromExtension
const signedBytes = Base58.encode(tx.signedBytes);
const res = await processTransactionVersion2(signedBytes);
if (!res?.signature)
- throw new Error(res?.message || "Transaction was not able to be processed");
+ throw new Error(
+ res?.message || "Transaction was not able to be processed"
+ );
return res;
} else {
throw new Error("User declined request");
@@ -98,22 +112,20 @@ const _createPoll = async ({pollName, pollDescription, options}, isFromExtension
};
const _deployAt = async (
- {name,
- description,
- tags,
- creationBytes,
- amount,
- assetId,
- atType}, isFromExtension
+ { name, description, tags, creationBytes, amount, assetId, atType },
+ isFromExtension
) => {
const fee = await getFee("DEPLOY_AT");
- const resPermission = await getUserPermission({
- text1: "Would you like to deploy this AT?",
- text2: `Name: ${name}`,
- text3: `Description: ${description}`,
- fee: fee.fee,
- }, isFromExtension);
+ const resPermission = await getUserPermission(
+ {
+ text1: "Would you like to deploy this AT?",
+ text2: `Name: ${name}`,
+ text3: `Description: ${description}`,
+ fee: fee.fee,
+ },
+ isFromExtension
+ );
const { accepted } = resPermission;
@@ -155,15 +167,21 @@ const _deployAt = async (
}
};
-const _voteOnPoll = async ({pollName, optionIndex, optionName}, isFromExtension) => {
+const _voteOnPoll = async (
+ { pollName, optionIndex, optionName },
+ isFromExtension
+) => {
const fee = await getFee("VOTE_ON_POLL");
- const resPermission = await getUserPermission({
- text1: "You are being requested to vote on the poll below:",
- text2: `Poll: ${pollName}`,
- text3: `Option: ${optionName}`,
- fee: fee.fee,
- }, isFromExtension);
+ const resPermission = await getUserPermission(
+ {
+ text1: "You are being requested to vote on the poll below:",
+ text2: `Poll: ${pollName}`,
+ text3: `Option: ${optionName}`,
+ fee: fee.fee,
+ },
+ isFromExtension
+ );
const { accepted } = resPermission;
if (accepted) {
@@ -189,7 +207,9 @@ const _voteOnPoll = async ({pollName, optionIndex, optionName}, isFromExtension)
const signedBytes = Base58.encode(tx.signedBytes);
const res = await processTransactionVersion2(signedBytes);
if (!res?.signature)
- throw new Error(res?.message || "Transaction was not able to be processed");
+ throw new Error(
+ res?.message || "Transaction was not able to be processed"
+ );
return res;
} else {
throw new Error("User declined request");
@@ -202,7 +222,10 @@ const fileRequestResolvers = new Map();
const handleFileMessage = (event) => {
const { action, requestId, result, error } = event.data;
- if (action === "getFileFromIndexedDBResponse" && fileRequestResolvers.has(requestId)) {
+ if (
+ action === "getFileFromIndexedDBResponse" &&
+ fileRequestResolvers.has(requestId)
+ ) {
const { resolve, reject } = fileRequestResolvers.get(requestId);
fileRequestResolvers.delete(requestId); // Clean up after resolving
@@ -239,22 +262,23 @@ function getFileFromContentScript(fileId) {
});
}
-
// function sendToSaveFilePicker(data) {
// window.postMessage({
// action: "SHOW_SAVE_FILE_PICKER",
// payload: data,
-// }, "*");
+// }, "*");
// }
-
const responseResolvers = new Map();
const handleMessage = (event) => {
const { action, requestId, result } = event.data;
// Check if this is the expected response action and if we have a stored resolver
- if (action === "QORTAL_REQUEST_PERMISSION_RESPONSE" && responseResolvers.has(requestId)) {
+ if (
+ action === "QORTAL_REQUEST_PERMISSION_RESPONSE" &&
+ responseResolvers.has(requestId)
+ ) {
// Resolve the stored promise with the result
responseResolvers.get(requestId)(result || false);
responseResolvers.delete(requestId); // Clean up after resolving
@@ -263,8 +287,6 @@ const handleMessage = (event) => {
window.addEventListener("message", handleMessage);
-
-
async function getUserPermission(payload, isFromExtension) {
return new Promise((resolve) => {
const requestId = `qortalRequest_${Date.now()}`;
@@ -273,7 +295,12 @@ async function getUserPermission(payload, isFromExtension) {
// Send the request message
window.postMessage(
- { action: "QORTAL_REQUEST_PERMISSION", payload, requestId, isFromExtension },
+ {
+ action: "QORTAL_REQUEST_PERMISSION",
+ payload,
+ requestId,
+ isFromExtension,
+ },
targetOrigin
);
@@ -287,42 +314,43 @@ async function getUserPermission(payload, isFromExtension) {
});
}
-
-export const getUserAccount = async ({isFromExtension, appInfo}) => {
+export const getUserAccount = async ({ isFromExtension, appInfo }) => {
try {
- const value = (await getPermission(`qAPPAutoAuth-${appInfo?.name}`)) || false;
+ const value =
+ (await getPermission(`qAPPAutoAuth-${appInfo?.name}`)) || false;
let skip = false;
if (value) {
skip = true;
}
- let resPermission
- if(!skip){
- resPermission = await getUserPermission({
- text1: "Do you give this application permission to authenticate?",
- checkbox1: {
- value: false,
- label: "Always authenticate automatically",
- },
- }, isFromExtension);
- }
+ let resPermission;
+ if (!skip) {
+ resPermission = await getUserPermission(
+ {
+ text1: "Do you give this application permission to authenticate?",
+ checkbox1: {
+ value: false,
+ label: "Always authenticate automatically",
+ },
+ },
+ isFromExtension
+ );
+ }
- const { accepted = false, checkbox1 = false } = resPermission || {};
- if(resPermission){
- setPermission(`qAPPAutoAuth-${appInfo?.name}`, checkbox1);
- }
- if (accepted || skip) {
-
- const wallet = await getSaveWallet();
- const address = wallet.address0;
- const publicKey = wallet.publicKey;
- return {
- address,
- publicKey,
- };
- } else {
- throw new Error("User declined request");
-
- }
+ const { accepted = false, checkbox1 = false } = resPermission || {};
+ if (resPermission) {
+ setPermission(`qAPPAutoAuth-${appInfo?.name}`, checkbox1);
+ }
+ if (accepted || skip) {
+ const wallet = await getSaveWallet();
+ const address = wallet.address0;
+ const publicKey = wallet.publicKey;
+ return {
+ address,
+ publicKey,
+ };
+ } else {
+ throw new Error("User declined request");
+ }
} catch (error) {
throw new Error("Unable to fetch user account");
}
@@ -396,9 +424,9 @@ export const decryptData = async (data) => {
};
export const getListItems = async (data, isFromExtension) => {
- const isGateway = await isRunningGateway()
- if(isGateway){
- throw new Error('This action cannot be done through a gateway')
+ const isGateway = await isRunningGateway();
+ if (isGateway) {
+ throw new Error("This action cannot be done through a gateway");
}
const requiredFields = ["list_name"];
const missingFields: string[] = [];
@@ -422,15 +450,18 @@ export const getListItems = async (data, isFromExtension) => {
let acceptedVar;
let checkbox1Var;
if (!skip) {
- resPermission = await getUserPermission({
- text1: "Do you give this application permission to",
- text2: "Access the list",
- highlightedText: data.list_name,
- checkbox1: {
- value: value,
- label: "Always allow lists to be retrieved automatically",
+ resPermission = await getUserPermission(
+ {
+ text1: "Do you give this application permission to",
+ text2: "Access the list",
+ highlightedText: data.list_name,
+ checkbox1: {
+ value: value,
+ label: "Always allow lists to be retrieved automatically",
+ },
},
- }, isFromExtension);
+ isFromExtension
+ );
const { accepted, checkbox1 } = resPermission;
acceptedVar = accepted;
checkbox1Var = checkbox1;
@@ -450,9 +481,9 @@ export const getListItems = async (data, isFromExtension) => {
};
export const addListItems = async (data, isFromExtension) => {
- const isGateway = await isRunningGateway()
- if(isGateway){
- throw new Error('This action cannot be done through a gateway')
+ const isGateway = await isRunningGateway();
+ if (isGateway) {
+ throw new Error("This action cannot be done through a gateway");
}
const requiredFields = ["list_name", "items"];
const missingFields: string[] = [];
@@ -470,11 +501,14 @@ export const addListItems = async (data, isFromExtension) => {
const items = data.items;
const list_name = data.list_name;
- const resPermission = await getUserPermission({
- text1: "Do you give this application permission to",
- text2: `Add the following to the list ${list_name}:`,
- highlightedText: items.join(", "),
- }, isFromExtension);
+ const resPermission = await getUserPermission(
+ {
+ text1: "Do you give this application permission to",
+ text2: `Add the following to the list ${list_name}:`,
+ highlightedText: items.join(", "),
+ },
+ isFromExtension
+ );
const { accepted } = resPermission;
if (accepted) {
@@ -505,9 +539,9 @@ export const addListItems = async (data, isFromExtension) => {
};
export const deleteListItems = async (data, isFromExtension) => {
- const isGateway = await isRunningGateway()
- if(isGateway){
- throw new Error('This action cannot be done through a gateway')
+ const isGateway = await isRunningGateway();
+ if (isGateway) {
+ throw new Error("This action cannot be done through a gateway");
}
const requiredFields = ["list_name", "item"];
const missingFields: string[] = [];
@@ -525,11 +559,14 @@ export const deleteListItems = async (data, isFromExtension) => {
const item = data.item;
const list_name = data.list_name;
- const resPermission = await getUserPermission({
- text1: "Do you give this application permission to",
- text2: `Remove the following from the list ${list_name}:`,
- highlightedText: item,
- }, isFromExtension);
+ const resPermission = await getUserPermission(
+ {
+ text1: "Do you give this application permission to",
+ text2: `Remove the following from the list ${list_name}:`,
+ highlightedText: item,
+ },
+ isFromExtension
+ );
const { accepted } = resPermission;
if (accepted) {
@@ -559,7 +596,11 @@ export const deleteListItems = async (data, isFromExtension) => {
}
};
-export const publishQDNResource = async (data: any, sender, isFromExtension) => {
+export const publishQDNResource = async (
+ data: any,
+ sender,
+ isFromExtension
+) => {
const requiredFields = ["service"];
const missingFields: string[] = [];
requiredFields.forEach((field) => {
@@ -608,15 +649,15 @@ export const publishQDNResource = async (data: any, sender, isFromExtension) =>
}
if (data.encrypt) {
try {
- const resKeyPair = await getKeyPair()
- const parsedData = resKeyPair
- const privateKey = parsedData.privateKey
- const userPublicKey = parsedData.publicKey
+ const resKeyPair = await getKeyPair();
+ const parsedData = resKeyPair;
+ const privateKey = parsedData.privateKey;
+ const userPublicKey = parsedData.publicKey;
const encryptDataResponse = encryptDataGroup({
data64,
publicKeys: data.publicKeys,
privateKey,
- userPublicKey
+ userPublicKey,
});
if (encryptDataResponse) {
data64 = encryptDataResponse;
@@ -630,13 +671,16 @@ export const publishQDNResource = async (data: any, sender, isFromExtension) =>
const fee = await getFee("ARBITRARY");
- const resPermission = await getUserPermission({
- text1: "Do you give this application permission to publish to QDN?",
- text2: `service: ${service}`,
- text3: `identifier: ${identifier || null}`,
- highlightedText: `isEncrypted: ${!!data.encrypt}`,
- fee: fee.fee,
- }, isFromExtension);
+ const resPermission = await getUserPermission(
+ {
+ text1: "Do you give this application permission to publish to QDN?",
+ text2: `service: ${service}`,
+ text3: `identifier: ${identifier || null}`,
+ highlightedText: `isEncrypted: ${!!data.encrypt}`,
+ fee: fee.fee,
+ },
+ isFromExtension
+ );
const { accepted } = resPermission;
if (accepted) {
if (data.fileId && !data.encrypt) {
@@ -671,7 +715,11 @@ export const publishQDNResource = async (data: any, sender, isFromExtension) =>
}
};
-export const publishMultipleQDNResources = async (data: any, sender, isFromExtension) => {
+export const publishMultipleQDNResources = async (
+ data: any,
+ sender,
+ isFromExtension
+) => {
const requiredFields = ["resources"];
const missingFields: string[] = [];
let feeAmount = null;
@@ -702,9 +750,10 @@ export const publishMultipleQDNResources = async (data: any, sender, isFromExten
const fee = await getFee("ARBITRARY");
const registeredName = await getNameInfo();
const name = registeredName;
- const resPermission = await getUserPermission({
- text1: "Do you give this application permission to publish to QDN?",
- html: `
+ const resPermission = await getUserPermission(
+ {
+ text1: "Do you give this application permission to publish to QDN?",
+ html: `