added qortalRequest sign tx

This commit is contained in:
PhilReact 2024-11-19 05:19:31 +02:00
parent 14214ba6f0
commit e8b2196b01
7 changed files with 1741 additions and 1479 deletions

12
package-lock.json generated
View File

@ -69,6 +69,7 @@
"react-frame-component": "^5.2.7", "react-frame-component": "^5.2.7",
"react-infinite-scroller": "^1.2.6", "react-infinite-scroller": "^1.2.6",
"react-intersection-observer": "^9.13.0", "react-intersection-observer": "^9.13.0",
"react-json-view-lite": "^2.0.1",
"react-qr-code": "^2.0.15", "react-qr-code": "^2.0.15",
"react-quill": "^2.0.0", "react-quill": "^2.0.0",
"react-redux": "^9.1.2", "react-redux": "^9.1.2",
@ -14416,6 +14417,17 @@
"resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz",
"integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==" "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": { "node_modules/react-lifecycles-compat": {
"version": "3.0.4", "version": "3.0.4",
"resolved": "https://registry.npmjs.org/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz", "resolved": "https://registry.npmjs.org/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz",

View File

@ -73,6 +73,7 @@
"react-frame-component": "^5.2.7", "react-frame-component": "^5.2.7",
"react-infinite-scroller": "^1.2.6", "react-infinite-scroller": "^1.2.6",
"react-intersection-observer": "^9.13.0", "react-intersection-observer": "^9.13.0",
"react-json-view-lite": "^2.0.1",
"react-qr-code": "^2.0.15", "react-qr-code": "^2.0.15",
"react-quill": "^2.0.0", "react-quill": "^2.0.0",
"react-redux": "^9.1.2", "react-redux": "^9.1.2",

View File

@ -25,6 +25,8 @@ import {
Tooltip, Tooltip,
Typography, Typography,
} from "@mui/material"; } 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 { decryptStoredWallet } from "./utils/decryptWallet";
import { CountdownCircleTimer } from "react-countdown-circle-timer"; import { CountdownCircleTimer } from "react-countdown-circle-timer";
import Logo1 from "./assets/svgs/Logo1.svg"; import Logo1 from "./assets/svgs/Logo1.svg";
@ -113,12 +115,14 @@ import {
} from "./atoms/global"; } from "./atoms/global";
import { useAppFullScreen } from "./useAppFullscreen"; import { useAppFullScreen } from "./useAppFullscreen";
import { NotAuthenticated } from "./ExtStates/NotAuthenticated"; 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 { fileToBase64 } from "./utils/fileReading";
import { handleGetFileFromIndexedDB } from "./utils/indexedDB"; import { handleGetFileFromIndexedDB } from "./utils/indexedDB";
import { CoreSyncStatus } from "./components/CoreSyncStatus"; import { CoreSyncStatus } from "./components/CoreSyncStatus";
type extStates = type extStates =
| "not-authenticated" | "not-authenticated"
| "authenticated" | "authenticated"
@ -372,16 +376,17 @@ function App() {
useRetrieveDataLocalStorage(); useRetrieveDataLocalStorage();
useQortalGetSaveSettings(userInfo?.name); useQortalGetSaveSettings(userInfo?.name);
const [fullScreen, setFullScreen] = useRecoilState(fullScreenAtom); const [fullScreen, setFullScreen] = useRecoilState(fullScreenAtom);
const [isEnabledDevMode, setIsEnabledDevMode] = useRecoilState(enabledDevModeAtom) const [isEnabledDevMode, setIsEnabledDevMode] =
useRecoilState(enabledDevModeAtom);
const { toggleFullScreen } = useAppFullScreen(setFullScreen); const { toggleFullScreen } = useAppFullScreen(setFullScreen);
useEffect(() => { useEffect(() => {
const isDevModeFromStorage = localStorage.getItem('isEnabledDevMode'); const isDevModeFromStorage = localStorage.getItem("isEnabledDevMode");
if (isDevModeFromStorage) { if (isDevModeFromStorage) {
setIsEnabledDevMode(JSON.parse(isDevModeFromStorage)) setIsEnabledDevMode(JSON.parse(isDevModeFromStorage));
} }
}, []) }, []);
useEffect(() => { useEffect(() => {
// Attach a global event listener for double-click // Attach a global event listener for double-click
@ -575,7 +580,6 @@ function App() {
}; };
}; };
const getBalanceFunc = () => { const getBalanceFunc = () => {
setQortBalanceLoading(true); setQortBalanceLoading(true);
window window
@ -652,7 +656,8 @@ function App() {
if (message.action === "QORTAL_REQUEST_PERMISSION") { if (message.action === "QORTAL_REQUEST_PERMISSION") {
try { try {
if (message?.payload?.checkbox1) { if (message?.payload?.checkbox1) {
qortalRequestCheckbox1Ref.current = message?.payload?.checkbox1?.value || false qortalRequestCheckbox1Ref.current =
message?.payload?.checkbox1?.value || false;
} }
await showQortalRequestExtension(message?.payload); await showQortalRequestExtension(message?.payload);
@ -695,7 +700,6 @@ function App() {
} }
}; };
useEffect(() => { useEffect(() => {
// Handler function for incoming messages // Handler function for incoming messages
const messageHandler = (event) => { const messageHandler = (event) => {
@ -717,15 +721,11 @@ function App() {
executeEvent("openGroupMessage", { executeEvent("openGroupMessage", {
from: message.payload.from, from: message.payload.from,
}); });
} else if ( } else if (message.action === "NOTIFICATION_OPEN_ANNOUNCEMENT_GROUP") {
message.action === "NOTIFICATION_OPEN_ANNOUNCEMENT_GROUP"
) {
executeEvent("openGroupAnnouncement", { executeEvent("openGroupAnnouncement", {
from: message.payload.from, from: message.payload.from,
}); });
} else if ( } else if (message.action === "NOTIFICATION_OPEN_THREAD_NEW_POST") {
message.action === "NOTIFICATION_OPEN_THREAD_NEW_POST"
) {
executeEvent("openThreadNewPost", { executeEvent("openThreadNewPost", {
data: message.payload.data, data: message.payload.data,
}); });
@ -734,8 +734,7 @@ function App() {
message?.isFromExtension message?.isFromExtension
) { ) {
qortalRequestPermissonFromExtension(message, event); qortalRequestPermissonFromExtension(message, event);
} } else if (message?.action === "getFileFromIndexedDB") {
else if(message?.action === 'getFileFromIndexedDB'){
handleGetFileFromIndexedDB(event); handleGetFileFromIndexedDB(event);
} }
}; };
@ -782,7 +781,6 @@ function App() {
return; return;
if (response?.hasKeyPair) { if (response?.hasKeyPair) {
setExtstate("authenticated"); setExtstate("authenticated");
} else { } else {
setExtstate("wallet-dropped"); setExtstate("wallet-dropped");
} }
@ -869,7 +867,6 @@ function App() {
walletToBeDownloaded.wallet, walletToBeDownloaded.wallet,
walletToBeDownloaded.qortAddress walletToBeDownloaded.qortAddress
); );
} catch (error: any) { } catch (error: any) {
setWalletToBeDownloadedError(error?.message); setWalletToBeDownloadedError(error?.message);
} finally { } finally {
@ -1029,10 +1026,14 @@ function App() {
}, 250); }, 250);
}); });
window window
.sendMessage("decryptWallet", { .sendMessage(
"decryptWallet",
{
password: authenticatePassword, password: authenticatePassword,
wallet: rawWallet, wallet: rawWallet,
}, 120000) },
120000
)
.then((response) => { .then((response) => {
if (response && !response.error) { if (response && !response.error) {
setAuthenticatePassword(""); setAuthenticatePassword("");
@ -1078,9 +1079,6 @@ function App() {
} }
}; };
useEffect(() => { useEffect(() => {
if (!isMainWindow) return; if (!isMainWindow) return;
// Handler for when the window gains focus // Handler for when the window gains focus
@ -1220,7 +1218,7 @@ function App() {
width: isMobile ? "100vw" : "auto", width: isMobile ? "100vw" : "auto",
display: "flex", display: "flex",
backgroundColor: "var(--bg-2)", backgroundColor: "var(--bg-2)",
justifyContent: 'flex-end' justifyContent: "flex-end",
}} }}
> >
{isMobile && ( {isMobile && (
@ -1242,12 +1240,14 @@ function App() {
/> />
</Box> </Box>
)} )}
{desktopViewMode !== "apps" && desktopViewMode !== "dev" && desktopViewMode !== "chat" && ( {desktopViewMode !== "apps" &&
desktopViewMode !== "dev" &&
desktopViewMode !== "chat" && (
<AuthenticatedContainerInnerLeft <AuthenticatedContainerInnerLeft
sx={{ sx={{
overflowY: isMobile && "auto", overflowY: isMobile && "auto",
padding: '0px 20px', padding: "0px 20px",
minWidth: '225px' minWidth: "225px",
}} }}
> >
<Spacer height="48px" /> <Spacer height="48px" />
@ -1394,7 +1394,9 @@ function App() {
textDecoration: "underline", textDecoration: "underline",
}} }}
onClick={async () => { onClick={async () => {
executeEvent("addTab", { data: { service: 'APP', name: 'q-trade' } }); executeEvent("addTab", {
data: { service: "APP", name: "q-trade" },
});
executeEvent("open-apps-mode", {}); executeEvent("open-apps-mode", {});
}} }}
> >
@ -1403,19 +1405,22 @@ function App() {
</AuthenticatedContainerInnerLeft> </AuthenticatedContainerInnerLeft>
)} )}
<AuthenticatedContainerInnerRight
<AuthenticatedContainerInnerRight> sx={{
height: "100%",
justifyContent: "space-between",
}}
>
<Box
sx={{
width: "100%",
display: "flex",
flexDirection: "column",
alignItems: 'center'
}}
>
<Spacer height="20px" /> <Spacer height="20px" />
<img
onClick={() => {
setExtstate("download-wallet");
setIsOpenDrawerProfile(false);
}}
src={Download}
style={{
cursor: "pointer",
}}
/>
{!isMobile && ( {!isMobile && (
<> <>
<Spacer height="20px" /> <Spacer height="20px" />
@ -1427,6 +1432,8 @@ function App() {
}} }}
style={{ style={{
cursor: "pointer", cursor: "pointer",
width: '20px',
height: 'auto'
}} }}
/> />
</> </>
@ -1473,6 +1480,28 @@ function App() {
)} )}
<Spacer height="20px" /> <Spacer height="20px" />
<CoreSyncStatus /> <CoreSyncStatus />
</Box>
<Box
sx={{
width: "100%",
display: "flex",
flexDirection: "column",
alignItems: 'center'
}}
>
<img
onClick={() => {
setExtstate("download-wallet");
setIsOpenDrawerProfile(false);
}}
src={Download}
style={{
cursor: "pointer",
width: '20px'
}}
/>
<Spacer height="40px" />
</Box>
</AuthenticatedContainerInnerRight> </AuthenticatedContainerInnerRight>
</AuthenticatedContainer> </AuthenticatedContainer>
); );
@ -1519,7 +1548,7 @@ function App() {
openSnackGlobal: openSnack, openSnackGlobal: openSnack,
setOpenSnackGlobal: setOpenSnack, setOpenSnackGlobal: setOpenSnack,
infoSnackCustom: infoSnack, infoSnackCustom: infoSnack,
setInfoSnackCustom: setInfoSnack setInfoSnackCustom: setInfoSnack,
}} }}
> >
<Box <Box
@ -2174,7 +2203,7 @@ function App() {
onClick={() => { onClick={() => {
setRawWallet(null); setRawWallet(null);
setExtstate("not-authenticated"); setExtstate("not-authenticated");
logoutFunc() logoutFunc();
}} }}
src={Return} src={Return}
/> />
@ -2308,12 +2337,14 @@ function App() {
{walletToBeDownloaded && ( {walletToBeDownloaded && (
<> <>
<CustomButton onClick={async ()=> { <CustomButton
await saveFileToDiskFunc() onClick={async () => {
await saveFileToDiskFunc();
await showInfo({ await showInfo({
message: `Keep your wallet file secure.`, message: `Keep your wallet file secure.`,
}) });
}}> }}
>
Download wallet Download wallet
</CustomButton> </CustomButton>
</> </>
@ -2417,7 +2448,7 @@ await showInfo({
returnToMain(); returnToMain();
await showInfo({ await showInfo({
message: `Keep your wallet file secure.`, message: `Keep your wallet file secure.`,
}) });
}} }}
> >
Backup Account Backup Account
@ -2567,10 +2598,8 @@ await showInfo({
<DialogContentText id="alert-dialog-description"> <DialogContentText id="alert-dialog-description">
{messageInfo.message} {messageInfo.message}
</DialogContentText> </DialogContentText>
</DialogContent> </DialogContent>
<DialogActions> <DialogActions>
<Button variant="contained" onClick={onOkInfo} autoFocus> <Button variant="contained" onClick={onOkInfo} autoFocus>
Close Close
</Button> </Button>
@ -2734,6 +2763,16 @@ await showInfo({
{messageQortalRequestExtension?.highlightedText} {messageQortalRequestExtension?.highlightedText}
</TextP> </TextP>
{messageQortalRequestExtension?.json && (
<>
<Spacer height="15px" />
<JsonView data={messageQortalRequestExtension?.json} shouldExpandNode={allExpanded} style={darkStyles} />
<Spacer height="15px" />
</>
)}
{messageQortalRequestExtension?.fee && ( {messageQortalRequestExtension?.fee && (
<> <>
<Spacer height="15px" /> <Spacer height="15px" />

View File

@ -182,7 +182,7 @@ const UIQortalRequests = [
'GET_WALLET_BALANCE', 'GET_USER_WALLET_INFO', 'GET_CROSSCHAIN_SERVER_INFO', 'GET_WALLET_BALANCE', 'GET_USER_WALLET_INFO', 'GET_CROSSCHAIN_SERVER_INFO',
'GET_TX_ACTIVITY_SUMMARY', 'GET_FOREIGN_FEE', 'UPDATE_FOREIGN_FEE', 'GET_TX_ACTIVITY_SUMMARY', 'GET_FOREIGN_FEE', 'UPDATE_FOREIGN_FEE',
'GET_SERVER_CONNECTION_HISTORY', 'SET_CURRENT_FOREIGN_SERVER', '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'
]; ];

View File

@ -113,6 +113,7 @@ export const publishData = async ({
transactionBytesBase58 transactionBytesBase58
) )
if (convertedBytesBase58.error) { if (convertedBytesBase58.error) {
throw new Error('Error when signing') throw new Error('Error when signing')
} }

View File

@ -1,5 +1,5 @@
import { gateways, getApiKeyFromStorage } from "./background"; 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"; import { getData, storeData } from "./utils/chromeStorage";
@ -691,6 +691,26 @@ export const isRunningGateway = async ()=> {
} }
break; 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: default:
break; break;
} }

File diff suppressed because it is too large Load Diff