add permissions

This commit is contained in:
PhilReact 2025-05-03 23:19:36 +03:00
parent b1af797ad3
commit a7a4cb18da
2 changed files with 160 additions and 109 deletions

View File

@ -755,7 +755,7 @@ function setupMessageListenerQortalRequest() {
case 'UPDATE_FOREIGN_FEE': { case 'UPDATE_FOREIGN_FEE': {
try { try {
const res = await updateForeignFee(request.payload); const res = await updateForeignFee(request.payload, isFromExtension);
event.source.postMessage( event.source.postMessage(
{ {
requestId: request.requestId, requestId: request.requestId,
@ -807,7 +807,10 @@ function setupMessageListenerQortalRequest() {
case 'SET_CURRENT_FOREIGN_SERVER': { case 'SET_CURRENT_FOREIGN_SERVER': {
try { try {
const res = await setCurrentForeignServer(request.payload); const res = await setCurrentForeignServer(
request.payload,
isFromExtension
);
event.source.postMessage( event.source.postMessage(
{ {
requestId: request.requestId, requestId: request.requestId,
@ -833,7 +836,7 @@ function setupMessageListenerQortalRequest() {
case 'ADD_FOREIGN_SERVER': { case 'ADD_FOREIGN_SERVER': {
try { try {
const res = await addForeignServer(request.payload); const res = await addForeignServer(request.payload, isFromExtension);
event.source.postMessage( event.source.postMessage(
{ {
requestId: request.requestId, requestId: request.requestId,
@ -859,7 +862,10 @@ function setupMessageListenerQortalRequest() {
case 'REMOVE_FOREIGN_SERVER': { case 'REMOVE_FOREIGN_SERVER': {
try { try {
const res = await removeForeignServer(request.payload); const res = await removeForeignServer(
request.payload,
isFromExtension
);
event.source.postMessage( event.source.postMessage(
{ {
requestId: request.requestId, requestId: request.requestId,

View File

@ -2655,7 +2655,7 @@ export const getForeignFee = async (data) => {
} }
}; };
export const updateForeignFee = async (data) => { export const updateForeignFee = async (data, isFromExtension) => {
const isGateway = await isRunningGateway(); const isGateway = await isRunningGateway();
if (isGateway) { if (isGateway) {
throw new Error('This action cannot be done through a public node'); throw new Error('This action cannot be done through a public node');
@ -2676,9 +2676,24 @@ export const updateForeignFee = async (data) => {
} }
const { coin, type, value } = data; const { coin, type, value } = data;
const resPermission = await getUserPermission(
{
text1: `Do you give this application to update foreign fees on your node?`,
text2: `type: ${type === 'feerequired' ? 'unlocking' : 'locking'}`,
text3: `value: ${value}`,
highlightedText: `Coin: ${coin}`,
},
isFromExtension
);
const { accepted } = resPermission;
if (!accepted) {
throw new Error('User declined request');
}
const url = `/crosschain/${coin.toLowerCase()}/update${type}`; const url = `/crosschain/${coin.toLowerCase()}/update${type}`;
const valueStringified = JSON.stringify(+value); const valueStringified = JSON.stringify(+value);
try {
const endpoint = await createEndpoint(url); const endpoint = await createEndpoint(url);
const response = await fetch(endpoint, { const response = await fetch(endpoint, {
method: 'POST', method: 'POST',
@ -2700,9 +2715,6 @@ export const updateForeignFee = async (data) => {
throw new Error(res.message); throw new Error(res.message);
} }
return res; // Return full response here return res; // Return full response here
} catch (error) {
throw new Error(error?.message || 'Error in update foreign fee');
}
}; };
export const getServerConnectionHistory = async (data) => { export const getServerConnectionHistory = async (data) => {
@ -2755,7 +2767,7 @@ export const getServerConnectionHistory = async (data) => {
} }
}; };
export const setCurrentForeignServer = async (data) => { export const setCurrentForeignServer = async (data, isFromExtension) => {
const isGateway = await isRunningGateway(); const isGateway = await isRunningGateway();
if (isGateway) { if (isGateway) {
throw new Error('This action cannot be done through a public node'); throw new Error('This action cannot be done through a public node');
@ -2777,6 +2789,21 @@ export const setCurrentForeignServer = async (data) => {
} }
const { coin, host, port, type } = data; const { coin, host, port, type } = data;
const resPermission = await getUserPermission(
{
text1: `Do you give this application to set the current server?`,
text2: `type: ${type}`,
text3: `host: ${host}`,
highlightedText: `Coin: ${coin}`,
},
isFromExtension
);
const { accepted } = resPermission;
if (!accepted) {
throw new Error('User declined request');
}
const body = { const body = {
hostName: host, hostName: host,
port: port, port: port,
@ -2785,7 +2812,6 @@ export const setCurrentForeignServer = async (data) => {
const url = `/crosschain/${coin.toLowerCase()}/setcurrentserver`; const url = `/crosschain/${coin.toLowerCase()}/setcurrentserver`;
try {
const endpoint = await createEndpoint(url); // Assuming createEndpoint is available const endpoint = await createEndpoint(url); // Assuming createEndpoint is available
const response = await fetch(endpoint, { const response = await fetch(endpoint, {
method: 'POST', method: 'POST',
@ -2810,12 +2836,9 @@ export const setCurrentForeignServer = async (data) => {
} }
return res; // Return the full response return res; // Return the full response
} catch (error) {
throw new Error(error?.message || 'Error in set current server');
}
}; };
export const addForeignServer = async (data) => { export const addForeignServer = async (data, isFromExtension) => {
const isGateway = await isRunningGateway(); const isGateway = await isRunningGateway();
if (isGateway) { if (isGateway) {
throw new Error('This action cannot be done through a public node'); throw new Error('This action cannot be done through a public node');
@ -2837,6 +2860,21 @@ export const addForeignServer = async (data) => {
} }
const { coin, host, port, type } = data; const { coin, host, port, type } = data;
const resPermission = await getUserPermission(
{
text1: `Do you give this application to add a server?`,
text2: `type: ${type}`,
text3: `host: ${host}`,
highlightedText: `Coin: ${coin}`,
},
isFromExtension
);
const { accepted } = resPermission;
if (!accepted) {
throw new Error('User declined request');
}
const body = { const body = {
hostName: host, hostName: host,
port: port, port: port,
@ -2845,7 +2883,6 @@ export const addForeignServer = async (data) => {
const url = `/crosschain/${coin.toLowerCase()}/addserver`; const url = `/crosschain/${coin.toLowerCase()}/addserver`;
try {
const endpoint = await createEndpoint(url); // Assuming createEndpoint is available const endpoint = await createEndpoint(url); // Assuming createEndpoint is available
const response = await fetch(endpoint, { const response = await fetch(endpoint, {
method: 'POST', method: 'POST',
@ -2870,12 +2907,9 @@ export const addForeignServer = async (data) => {
} }
return res; // Return the full response return res; // Return the full response
} catch (error) {
throw new Error(error.message || 'Error in adding server');
}
}; };
export const removeForeignServer = async (data) => { export const removeForeignServer = async (data, isFromExtension) => {
const isGateway = await isRunningGateway(); const isGateway = await isRunningGateway();
if (isGateway) { if (isGateway) {
throw new Error('This action cannot be done through a public node'); throw new Error('This action cannot be done through a public node');
@ -2897,6 +2931,21 @@ export const removeForeignServer = async (data) => {
} }
const { coin, host, port, type } = data; const { coin, host, port, type } = data;
const resPermission = await getUserPermission(
{
text1: `Do you give this application to remove a server?`,
text2: `type: ${type}`,
text3: `host: ${host}`,
highlightedText: `Coin: ${coin}`,
},
isFromExtension
);
const { accepted } = resPermission;
if (!accepted) {
throw new Error('User declined request');
}
const body = { const body = {
hostName: host, hostName: host,
port: port, port: port,
@ -2905,7 +2954,6 @@ export const removeForeignServer = async (data) => {
const url = `/crosschain/${coin.toLowerCase()}/removeserver`; const url = `/crosschain/${coin.toLowerCase()}/removeserver`;
try {
const endpoint = await createEndpoint(url); // Assuming createEndpoint is available const endpoint = await createEndpoint(url); // Assuming createEndpoint is available
const response = await fetch(endpoint, { const response = await fetch(endpoint, {
method: 'POST', method: 'POST',
@ -2930,9 +2978,6 @@ export const removeForeignServer = async (data) => {
} }
return res; // Return the full response return res; // Return the full response
} catch (error) {
throw new Error(error?.message || 'Error in removing server');
}
}; };
export const getDaySummary = async () => { export const getDaySummary = async () => {