From 694ace2190becbf0e6111c1a05a29d56326d766b Mon Sep 17 00:00:00 2001 From: PhilReact Date: Sun, 16 Mar 2025 22:42:55 +0200 Subject: [PATCH] fixes and added qortal request --- src/ExtStates/NotAuthenticated.tsx | 154 +++++++++++++++++- src/components/Apps/AppViewerContainer.tsx | 3 +- src/components/Apps/Apps.tsx | 3 +- .../Apps/useQortalMessageListener.tsx | 5 +- src/qortalRequests.ts | 22 ++- src/qortalRequests/get.ts | 30 ++++ 6 files changed, 203 insertions(+), 14 deletions(-) diff --git a/src/ExtStates/NotAuthenticated.tsx b/src/ExtStates/NotAuthenticated.tsx index a0f160d..f37612c 100644 --- a/src/ExtStates/NotAuthenticated.tsx +++ b/src/ExtStates/NotAuthenticated.tsx @@ -14,6 +14,7 @@ import { Input, styled, Switch, + TextField, Typography, } from "@mui/material"; import Logo1 from "../assets/svgs/Logo1.svg"; @@ -71,12 +72,14 @@ export const NotAuthenticated = ({ const [customNodeToSaveIndex, setCustomNodeToSaveIndex] = React.useState(null); const { showTutorial, hasSeenGettingStarted } = useContext(GlobalContext); - + const [showSelectApiKey, setShowSelectApiKey] = useState(false) + const [enteredApiKey, setEnteredApiKey] = useState('') const importedApiKeyRef = useRef(null); const currentNodeRef = useRef(null); const hasLocalNodeRef = useRef(null); const isLocal = cleanUrl(currentNode?.url) === "127.0.0.1:12391"; const handleFileChangeApiKey = (event) => { + setShowSelectApiKey(false) const file = event.target.files[0]; // Get the selected file if (file) { const reader = new FileReader(); @@ -241,6 +244,57 @@ export const NotAuthenticated = ({ apikey: importedApiKeyRef.current || key?.apikey, url: currentNodeRef.current?.url, }; + if(!payload?.apikey){ + try { + const generateUrl = "http://127.0.0.1:12391/admin/apikey/generate"; + const generateRes = await fetch(generateUrl, { + method: "POST", + }) + let res; + try { + res = await generateRes.clone().json(); + } catch (e) { + res = await generateRes.text(); + } + if (res != null && !res.error && res.length >= 8) { + payload = { + apikey: res, + url: currentNodeRef.current?.url, + }; + + setImportedApiKey(res); // Store the file content in the state + + setCustomNodes((prev)=> { + const copyPrev = [...prev] + const findLocalIndex = copyPrev?.findIndex((item)=> item?.url === 'http://127.0.0.1:12391') + if(findLocalIndex === -1){ + copyPrev.unshift({ + url: "http://127.0.0.1:12391", + apikey: res + }) + } else { + copyPrev[findLocalIndex] = { + url: "http://127.0.0.1:12391", + apikey: res + } + } + window + .sendMessage("setCustomNodes", copyPrev) + .catch((error) => { + console.error( + "Failed to set custom nodes:", + error.message || "An error occurred" + ); + }); + return copyPrev + }) + + + } + } catch (error) { + console.error(error) + } + } } else if (currentNodeRef.current) { payload = currentNodeRef.current; } @@ -540,14 +594,8 @@ export const NotAuthenticated = ({ {currentNode?.url === "http://127.0.0.1:12391" && ( <> - + {showSelectApiKey && ( + + {"Enter apikey"} + + + setEnteredApiKey(e.target.value)}/> + + + + + + + + + + + + + )} {show && ( } style={{ - display: (!isSelected || hide) && 'none', + position: (!isSelected || hide) && 'absolute', + left: (!isSelected || hide) && '10000000px', height: customHeight ? customHeight : !isMobile ? '100vh' : `calc(${rootHeight} - 60px - 45px)`, border: 'none', width: '100%', diff --git a/src/components/Apps/Apps.tsx b/src/components/Apps/Apps.tsx index 4a7becb..4df49ee 100644 --- a/src/components/Apps/Apps.tsx +++ b/src/components/Apps/Apps.tsx @@ -292,7 +292,8 @@ export const Apps = ({ mode, setMode, show , myName}) => { return ( {mode !== "viewer" && !selectedTab && } diff --git a/src/components/Apps/useQortalMessageListener.tsx b/src/components/Apps/useQortalMessageListener.tsx index 672b1ae..4e8258b 100644 --- a/src/components/Apps/useQortalMessageListener.tsx +++ b/src/components/Apps/useQortalMessageListener.tsx @@ -253,7 +253,8 @@ export function openIndexedDB() { 'CREATE_GROUP', 'GET_USER_WALLET_TRANSACTIONS', 'GET_NODE_INFO', - 'GET_NODE_STATUS' + 'GET_NODE_STATUS', + 'GET_ARRR_SYNC_STATUS' ] @@ -267,7 +268,7 @@ const UIQortalRequests = [ '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_PUBLIC_NODE', 'SIGN_TRANSACTION', 'ADMIN_ACTION', 'OPEN_NEW_TAB', 'CREATE_AND_COPY_EMBED_LINK', 'DECRYPT_QORTAL_GROUP_DATA', 'DECRYPT_DATA_WITH_SHARING_KEY', 'DELETE_HOSTED_DATA', 'GET_HOSTED_DATA', 'SHOW_ACTIONS', 'REGISTER_NAME', 'UPDATE_NAME', 'LEAVE_GROUP', 'INVITE_TO_GROUP', 'KICK_FROM_GROUP', 'BAN_FROM_GROUP', 'CANCEL_GROUP_BAN', 'ADD_GROUP_ADMIN', 'REMOVE_GROUP_ADMIN','DECRYPT_AESGCM', 'CANCEL_GROUP_INVITE', 'CREATE_GROUP', 'GET_USER_WALLET_TRANSACTIONS', 'GET_NODE_INFO', - 'GET_NODE_STATUS' + 'GET_NODE_STATUS', 'GET_ARRR_SYNC_STATUS' ]; diff --git a/src/qortalRequests.ts b/src/qortalRequests.ts index ba5d476..1e5ec2c 100644 --- a/src/qortalRequests.ts +++ b/src/qortalRequests.ts @@ -1,6 +1,6 @@ import { gateways, getApiKeyFromStorage } from "./background"; import { listOfAllQortalRequests } from "./components/Apps/useQortalMessageListener"; -import { addForeignServer, addGroupAdminRequest, addListItems, adminAction, banFromGroupRequest, cancelGroupBanRequest, cancelGroupInviteRequest, cancelSellOrder, createAndCopyEmbedLink, createBuyOrder, createGroupRequest, createPoll, decryptAESGCMRequest, decryptData, decryptDataWithSharingKey, decryptQortalGroupData, deleteHostedData, deleteListItems, deployAt, encryptData, encryptDataWithSharingKey, encryptQortalGroupData, getCrossChainServerInfo, getDaySummary, getForeignFee, getHostedData, getListItems, getNodeInfo, getNodeStatus, getServerConnectionHistory, getTxActivitySummary, getUserAccount, getUserWallet, getUserWalletInfo, getUserWalletTransactions, getWalletBalance, inviteToGroupRequest, joinGroup, kickFromGroupRequest, leaveGroupRequest, openNewTab, publishMultipleQDNResources, publishQDNResource, registerNameRequest, removeForeignServer, removeGroupAdminRequest, saveFile, sendChatMessage, sendCoin, setCurrentForeignServer, signTransaction, updateForeignFee, updateNameRequest, voteOnPoll } from "./qortalRequests/get"; +import { addForeignServer, addGroupAdminRequest, addListItems, adminAction, banFromGroupRequest, cancelGroupBanRequest, cancelGroupInviteRequest, cancelSellOrder, createAndCopyEmbedLink, createBuyOrder, createGroupRequest, createPoll, decryptAESGCMRequest, decryptData, decryptDataWithSharingKey, decryptQortalGroupData, deleteHostedData, deleteListItems, deployAt, encryptData, encryptDataWithSharingKey, encryptQortalGroupData, getArrrSyncStatus, getCrossChainServerInfo, getDaySummary, getForeignFee, getHostedData, getListItems, getNodeInfo, getNodeStatus, getServerConnectionHistory, getTxActivitySummary, getUserAccount, getUserWallet, getUserWalletInfo, getUserWalletTransactions, getWalletBalance, inviteToGroupRequest, joinGroup, kickFromGroupRequest, leaveGroupRequest, openNewTab, publishMultipleQDNResources, publishQDNResource, registerNameRequest, removeForeignServer, removeGroupAdminRequest, saveFile, sendChatMessage, sendCoin, setCurrentForeignServer, signTransaction, updateForeignFee, updateNameRequest, voteOnPoll } from "./qortalRequests/get"; import { getData, storeData } from "./utils/chromeStorage"; @@ -1162,6 +1162,26 @@ export const isRunningGateway = async ()=> { } break; } + + case "GET_ARRR_SYNC_STATUS": { + try { + const res = await getArrrSyncStatus(request.payload); + 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 2cadaaa..6e1f709 100644 --- a/src/qortalRequests/get.ts +++ b/src/qortalRequests/get.ts @@ -4481,4 +4481,34 @@ export const getNodeStatus = async () => { } catch (error) { throw new Error(error?.message || "Error in retrieving node status"); } +}; + +export const getArrrSyncStatus = async () => { + const resKeyPair = await getKeyPair(); + const parsedData = resKeyPair; + const arrrSeed = parsedData.arrrSeed58; + const url = `/crosschain/arrr/syncstatus`; // Simplified endpoint URL + + try { + const endpoint = await createEndpoint(url); // Assuming createEndpoint is available for constructing the full URL + const response = await fetch(endpoint, { + method: "POST", + headers: { + Accept: "*/*", + }, + body: arrrSeed + }); + + let res; + + try { + res = await response.clone().json(); + } catch (e) { + res = await response.text(); + } + + return res; // Return the full response + } catch (error) { + throw new Error(error?.message || "Error in retrieving arrr sync status"); + } }; \ No newline at end of file