diff --git a/src/App.tsx b/src/App.tsx
index 5a3681a..1a151ea 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -1293,6 +1293,24 @@ function App() {
};
}, []);
+ const openGlobalSnackBarFunc = (e) => {
+ const message = e.detail?.message;
+ const type = e.detail?.type;
+ setOpenSnack(true);
+ setInfoSnack({
+ type,
+ message
+ });
+ };
+
+ useEffect(() => {
+ subscribeToEvent("openGlobalSnackBar", openGlobalSnackBarFunc);
+
+ return () => {
+ unsubscribeFromEvent("openGlobalSnackBar", openGlobalSnackBarFunc);
+ };
+ }, []);
+
useEffect(()=> {
checkForUpdate()
}, [])
diff --git a/src/components/Apps/useQortalMessageListener.tsx b/src/components/Apps/useQortalMessageListener.tsx
index be82cf0..4c647e3 100644
--- a/src/components/Apps/useQortalMessageListener.tsx
+++ b/src/components/Apps/useQortalMessageListener.tsx
@@ -184,7 +184,7 @@ const UIQortalRequests = [
'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', 'OPEN_NEW_TAB'
+ 'CREATE_TRADE_SELL_ORDER', 'CANCEL_TRADE_SELL_ORDER', 'IS_USING_GATEWAY', 'ADMIN_ACTION', 'OPEN_NEW_TAB', 'CREATE_AND_COPY_EMBED_LINK'
];
diff --git a/src/components/Embeds/Embed.tsx b/src/components/Embeds/Embed.tsx
index 4a1bbfe..4fef82e 100644
--- a/src/components/Embeds/Embed.tsx
+++ b/src/components/Embeds/Embed.tsx
@@ -22,6 +22,7 @@ import OpenInNewIcon from "@mui/icons-material/OpenInNew";
import { extractComponents } from "../Chat/MessageDisplay";
import { executeEvent } from "../../utils/events";
import { CustomLoader } from "../../common/CustomLoader";
+import PollIcon from '@mui/icons-material/Poll';
function decodeHTMLEntities(str) {
const txt = document.createElement("textarea");
@@ -49,10 +50,10 @@ const parseQortalLink = (link) => {
const [key, value] = pair.split("=");
if (key && value) {
const decodedKey = decodeURIComponent(key.trim());
- const decodedValue = decodeURIComponent(value.trim()).replace(
+ const decodedValue = value.trim().replace(
/<\/?[^>]+(>|$)/g,
- ""
- ); // Remove any HTML tags
+ "" // Remove any HTML tags
+ );
params[decodedKey] = decodedValue;
}
});
@@ -112,10 +113,10 @@ export const Embed = ({ embedLink }) => {
const pollRes = await getPoll(parsedData.name);
setPoll(pollRes);
if (parsedData?.ref) {
- const res = extractComponents(parsedData.ref);
- const { service, name, identifier, path } = res;
+ const res = extractComponents(decodeURIComponent(parsedData.ref));
+
- if (service && name) {
+ if (res?.service && res?.name) {
setExternal(res);
}
}
@@ -201,7 +202,7 @@ export const PollCard = ({
const fee = await getFee("VOTE_ON_POLL");
await show({
- message: `Do you accept this VOTE_ON_POLL transaction?`,
+ message: `Do you accept this VOTE_ON_POLL transaction? POLLS are public!`,
publishFee: fee.fee + " QORT",
});
setIsLoadingSubmit(true);
@@ -273,7 +274,18 @@ export const PollCard = ({
padding: "16px 16px 0px 16px",
}}
>
+
+
POLL embed
+
diff --git a/src/qortalRequests.ts b/src/qortalRequests.ts
index 01389f0..b838aa8 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, decryptData, deleteListItems, deployAt, encryptData, getCrossChainServerInfo, getDaySummary, getForeignFee, getListItems, getServerConnectionHistory, getTxActivitySummary, getUserAccount, getUserWallet, getUserWalletInfo, getWalletBalance, joinGroup, openNewTab, publishMultipleQDNResources, publishQDNResource, removeForeignServer, saveFile, sendChatMessage, sendCoin, setCurrentForeignServer, updateForeignFee, voteOnPoll } from "./qortalRequests/get";
+import { addForeignServer, addListItems, adminAction, cancelSellOrder, createAndCopyEmbedLink, createBuyOrder, createPoll, decryptData, deleteListItems, deployAt, encryptData, getCrossChainServerInfo, getDaySummary, getForeignFee, getListItems, getServerConnectionHistory, getTxActivitySummary, getUserAccount, getUserWallet, getUserWalletInfo, getWalletBalance, joinGroup, openNewTab, publishMultipleQDNResources, publishQDNResource, removeForeignServer, saveFile, sendChatMessage, sendCoin, setCurrentForeignServer, updateForeignFee, voteOnPoll } from "./qortalRequests/get";
import { getData, storeData } from "./utils/chromeStorage";
@@ -694,6 +694,25 @@ export const isRunningGateway = async ()=> {
}
break;
}
+ case "CREATE_AND_COPY_EMBED_LINK": {
+ try {
+ const res = await createAndCopyEmbedLink(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 e81e05d..83e0950 100644
--- a/src/qortalRequests/get.ts
+++ b/src/qortalRequests/get.ts
@@ -2880,4 +2880,56 @@ export const openNewTab = async (data, isFromExtension) => {
+};
+
+const encode = (value) => encodeURIComponent(value.trim()); // Helper to encode values
+
+export const createAndCopyEmbedLink = async (data, isFromExtension) => {
+ const requiredFields = [
+ "type",
+ "name"
+ ];
+ const missingFields: string[] = [];
+ requiredFields.forEach((field) => {
+ if (!data[field]) {
+ missingFields.push(field);
+ }
+ });
+ if (missingFields.length > 0) {
+ const missingFieldsString = missingFields.join(", ");
+ const errorMsg = `Missing fields: ${missingFieldsString}`;
+ throw new Error(errorMsg);
+ }
+
+
+ switch (data.type) {
+ case "POLL": {
+ const queryParams = [
+ `name=${encode(data.name)}`,
+ data.ref ? `ref=${encode(data.ref)}` : null, // Add only if ref exists
+ ]
+ .filter(Boolean) // Remove null values
+ .join("&"); // Join with `&`
+ const link = `qortal://use-embed/POLL?${queryParams}`
+ navigator.clipboard.writeText(link)
+ .then(() => {
+ executeEvent('openGlobalSnackBar', {
+ message: 'Copied link to clipboard',
+ type: 'info'
+ })
+ //success
+ })
+ .catch((error) => {
+ executeEvent('openGlobalSnackBar', {
+ message: 'Failed to copy to clipboard',
+ type: 'error'
+ })
+ // error
+ });
+ return link;
+ }
+ default:
+ throw new Error('Invalid type')
+ }
+
};
\ No newline at end of file