added qortalRequest

This commit is contained in:
PhilReact 2025-02-01 12:00:43 +02:00
parent 513fd0375d
commit 07f182856a
4 changed files with 72 additions and 13 deletions

View File

@ -2340,7 +2340,7 @@ export async function leaveGroup({ groupId }) {
const res = await processTransactionVersion2(signedBytes);
if (!res?.signature)
throw new Error("Transaction was not able to be processed");
throw new Error(res?.message || "Transaction was not able to be processed");
return res;
}
@ -2396,7 +2396,7 @@ async function cancelInvitationToGroup({ groupId, qortalAddress }) {
const res = await processTransactionVersion2(signedBytes);
if (!res?.signature)
throw new Error("Transaction was not able to be processed");
throw new Error(res?.message || "Transaction was not able to be processed");
return res;
}
@ -2423,7 +2423,7 @@ export async function cancelBan({ groupId, qortalAddress }) {
const res = await processTransactionVersion2(signedBytes);
if (!res?.signature)
throw new Error("Transaction was not able to be processed");
throw new Error(res?.message || "Transaction was not able to be processed");
return res;
}
export async function registerName({ name, description = "" }) {
@ -2481,7 +2481,7 @@ export async function updateName({ newName, oldName, description }) {
return res;
}
async function makeAdmin({ groupId, qortalAddress }) {
export async function makeAdmin({ groupId, qortalAddress }) {
const lastReference = await getLastRef();
const resKeyPair = await getKeyPair();
const parsedData = JSON.parse(resKeyPair);
@ -2504,11 +2504,11 @@ async function makeAdmin({ groupId, qortalAddress }) {
const res = await processTransactionVersion2(signedBytes);
if (!res?.signature)
throw new Error("Transaction was not able to be processed");
throw new Error(res?.message || "Transaction was not able to be processed");
return res;
}
async function removeAdmin({ groupId, qortalAddress }) {
export async function removeAdmin({ groupId, qortalAddress }) {
const lastReference = await getLastRef();
const resKeyPair = await getKeyPair();
const parsedData = JSON.parse(resKeyPair);
@ -2531,7 +2531,7 @@ async function removeAdmin({ groupId, qortalAddress }) {
const res = await processTransactionVersion2(signedBytes);
if (!res?.signature)
throw new Error("Transaction was not able to be processed");
throw new Error(res?.message || "Transaction was not able to be processed");
return res;
}
@ -2565,7 +2565,7 @@ export async function banFromGroup({
const res = await processTransactionVersion2(signedBytes);
if (!res?.signature)
throw new Error("Transaction was not able to be processed");
throw new Error(res?.message || "Transaction was not able to be processed");
return res;
}
@ -2593,7 +2593,7 @@ export async function kickFromGroup({ groupId, qortalAddress, rBanReason = "" })
const res = await processTransactionVersion2(signedBytes);
if (!res?.signature)
throw new Error("Transaction was not able to be processed");
throw new Error(res?.message || "Transaction was not able to be processed");
return res;
}

View File

@ -243,7 +243,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', 'SIGN_TRANSACTION', 'DECRYPT_QORTAL_GROUP_DATA', 'DELETE_HOSTED_DATA', 'GET_HOSTED_DATA', 'DECRYPT_DATA_WITH_SHARING_KEY', 'SHOW_ACTIONS', 'REGISTER_NAME', 'UPDATE_NAME', 'LEAVE_GROUP', 'INVITE_TO_GROUP', 'KICK_FROM_GROUP', 'BAN_FROM_GROUP', 'CANCEL_GROUP_BAN'
'CREATE_TRADE_SELL_ORDER', 'CANCEL_TRADE_SELL_ORDER', 'IS_USING_GATEWAY', 'ADMIN_ACTION', 'SIGN_TRANSACTION', 'DECRYPT_QORTAL_GROUP_DATA', 'DELETE_HOSTED_DATA', 'GET_HOSTED_DATA', 'DECRYPT_DATA_WITH_SHARING_KEY', 'SHOW_ACTIONS', 'REGISTER_NAME', 'UPDATE_NAME', 'LEAVE_GROUP', 'INVITE_TO_GROUP', 'KICK_FROM_GROUP', 'BAN_FROM_GROUP', 'CANCEL_GROUP_BAN', 'ADD_GROUP_ADMIN'
];

View File

@ -1,5 +1,5 @@
import { banFromGroup, gateways, getApiKeyFromStorage } from "./background";
import { addForeignServer, addListItems, adminAction, banFromGroupRequest, cancelGroupBanRequest, cancelSellOrder, createBuyOrder, createPoll, createSellOrder, decryptData, decryptDataWithSharingKey, decryptQortalGroupData, deleteHostedData, deleteListItems, deployAt, encryptData, encryptDataWithSharingKey, encryptQortalGroupData, getCrossChainServerInfo, getDaySummary, getForeignFee, getHostedData, getListItems, getServerConnectionHistory, getTxActivitySummary, getUserAccount, getUserWallet, getUserWalletInfo, getWalletBalance, inviteToGroupRequest, joinGroup, kickFromGroupRequest, leaveGroupRequest, publishMultipleQDNResources, publishQDNResource, registerNameRequest, removeForeignServer, saveFile, sendChatMessage, sendCoin, setCurrentForeignServer, signTransaction, updateForeignFee, updateNameRequest, voteOnPoll } from "./qortalRequests/get";
import { addForeignServer, addGroupAdminRequest, addListItems, adminAction, banFromGroupRequest, cancelGroupBanRequest, cancelSellOrder, createBuyOrder, createPoll, createSellOrder, decryptData, decryptDataWithSharingKey, decryptQortalGroupData, deleteHostedData, deleteListItems, deployAt, encryptData, encryptDataWithSharingKey, encryptQortalGroupData, getCrossChainServerInfo, getDaySummary, getForeignFee, getHostedData, getListItems, getServerConnectionHistory, getTxActivitySummary, getUserAccount, getUserWallet, getUserWalletInfo, getWalletBalance, inviteToGroupRequest, joinGroup, kickFromGroupRequest, leaveGroupRequest, publishMultipleQDNResources, publishQDNResource, registerNameRequest, removeForeignServer, saveFile, sendChatMessage, sendCoin, setCurrentForeignServer, signTransaction, updateForeignFee, updateNameRequest, voteOnPoll } from "./qortalRequests/get";
const listOfAllQortalRequests = [
'GET_USER_ACCOUNT', 'DECRYPT_DATA', 'SEND_COIN', 'GET_LIST_ITEMS',
@ -696,7 +696,18 @@ chrome?.runtime?.onMessage.addListener((request, sender, sendResponse) => {
});
break;
}
case "ADD_GROUP_ADMIN" : {
const data = request.payload;
addGroupAdminRequest(data, isFromExtension)
.then((res) => {
sendResponse(res);
})
.catch((error) => {
sendResponse({ error: error.message });
});
break;
}
}
}
return true;

View File

@ -24,7 +24,8 @@ import {
inviteToGroup,
banFromGroup,
kickFromGroup,
cancelBan
cancelBan,
makeAdmin
} from "../background";
import { decryptGroupEncryption, getNameInfo, uint8ArrayToObject } from "../backgroundFunctions/encryption";
import { QORT_DECIMALS } from "../constants/constants";
@ -4132,6 +4133,53 @@ export const cancelGroupBanRequest = async (data, isFromExtension) => {
})
return response
} else {
throw new Error("User declined request");
}
};
export const addGroupAdminRequest = async (data, isFromExtension) => {
const requiredFields = ["groupId", "qortalAddress"];
const missingFields: string[] = [];
requiredFields.forEach((field) => {
if (!data[field]) {
missingFields.push(field);
}
});
const groupId = data.groupId
const qortalAddress = data?.qortalAddress
let groupInfo = null;
try {
const url = await createEndpoint(`/groups/${groupId}`);
const response = await fetch(url);
if (!response.ok) throw new Error("Failed to fetch group");
groupInfo = await response.json();
} catch (error) {
const errorMsg = (error && error.message) || "Group not found";
throw new Error(errorMsg);
}
const displayInvitee = await getNameInfoForOthers(qortalAddress)
const fee = await getFee("ADD_GROUP_ADMIN");
const resPermission = await getUserPermission(
{
text1: `Do you give this application permission to add user ${displayInvitee || qortalAddress} as an admin?`,
highlightedText: `Group: ${groupInfo.groupName}`,
fee: fee.fee,
},
isFromExtension
);
const { accepted } = resPermission;
if (accepted) {
const response = await makeAdmin({
groupId,
qortalAddress,
})
return response
} else {
throw new Error("User declined request");
}