mirror of
https://github.com/Qortal/chrome-extension.git
synced 2025-02-11 17:55:49 +00:00
added leave and invite to group qortalRequests
This commit is contained in:
parent
3a612760cc
commit
e69563ee39
@ -987,6 +987,16 @@ async function getNameInfo() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
export async function getNameInfoForOthers(address) {
|
||||
const validApi = await getBaseApi();
|
||||
const response = await fetch(validApi + "/names/address/" + address);
|
||||
const nameData = await response.json();
|
||||
if (nameData?.length > 0) {
|
||||
return nameData[0].name;
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
async function getAddressInfo(address) {
|
||||
const validApi = await getBaseApi();
|
||||
const response = await fetch(validApi + "/addresses/" + address);
|
||||
@ -2305,7 +2315,7 @@ export const getFee = async (txType) => {
|
||||
};
|
||||
};
|
||||
|
||||
async function leaveGroup({ groupId }) {
|
||||
export async function leaveGroup({ groupId }) {
|
||||
const wallet = await getSaveWallet();
|
||||
const address = wallet.address0;
|
||||
const lastReference = await getLastRef();
|
||||
@ -2627,7 +2637,7 @@ async function createGroup({
|
||||
if (!res?.signature) throw new Error(res?.message || "Transaction was not able to be processed");
|
||||
return res;
|
||||
}
|
||||
async function inviteToGroup({ groupId, qortalAddress, inviteTime }) {
|
||||
export async function inviteToGroup({ groupId, qortalAddress, inviteTime }) {
|
||||
const address = await getNameOrAddress(qortalAddress);
|
||||
if (!address) throw new Error("Cannot find user");
|
||||
const lastReference = await getLastRef();
|
||||
|
@ -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'
|
||||
'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'
|
||||
];
|
||||
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { gateways, getApiKeyFromStorage } from "./background";
|
||||
import { addForeignServer, addListItems, adminAction, cancelSellOrder, createBuyOrder, createPoll, createSellOrder, decryptData, decryptDataWithSharingKey, decryptQortalGroupData, deleteHostedData, deleteListItems, deployAt, encryptData, encryptDataWithSharingKey, encryptQortalGroupData, getCrossChainServerInfo, getDaySummary, getForeignFee, getHostedData, getListItems, getServerConnectionHistory, getTxActivitySummary, getUserAccount, getUserWallet, getUserWalletInfo, getWalletBalance, joinGroup, publishMultipleQDNResources, publishQDNResource, registerNameRequest, removeForeignServer, saveFile, sendChatMessage, sendCoin, setCurrentForeignServer, signTransaction, updateForeignFee, updateNameRequest, voteOnPoll } from "./qortalRequests/get";
|
||||
import { addForeignServer, addListItems, adminAction, 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, 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',
|
||||
@ -647,6 +647,33 @@ chrome?.runtime?.onMessage.addListener((request, sender, sendResponse) => {
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
case "LEAVE_GROUP" : {
|
||||
const data = request.payload;
|
||||
|
||||
leaveGroupRequest(data, isFromExtension)
|
||||
.then((res) => {
|
||||
sendResponse(res);
|
||||
})
|
||||
.catch((error) => {
|
||||
sendResponse({ error: error.message });
|
||||
});
|
||||
break;
|
||||
}
|
||||
case "INVITE_TO_GROUP" : {
|
||||
const data = request.payload;
|
||||
|
||||
inviteToGroupRequest(data, isFromExtension)
|
||||
.then((res) => {
|
||||
sendResponse(res);
|
||||
})
|
||||
.catch((error) => {
|
||||
sendResponse({ error: error.message });
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
@ -18,7 +18,10 @@ import {
|
||||
getBaseApi,
|
||||
getArbitraryEndpoint,
|
||||
updateName,
|
||||
registerName
|
||||
registerName,
|
||||
getNameInfoForOthers,
|
||||
leaveGroup,
|
||||
inviteToGroup
|
||||
} from "../background";
|
||||
import { decryptGroupEncryption, getNameInfo, uint8ArrayToObject } from "../backgroundFunctions/encryption";
|
||||
import { QORT_DECIMALS } from "../constants/constants";
|
||||
@ -3842,11 +3845,13 @@ export const registerNameRequest = async (data, isFromExtension) => {
|
||||
missingFields.push(field);
|
||||
}
|
||||
});
|
||||
const fee = await getFee("REGISTER_NAME");
|
||||
const resPermission = await getUserPermission(
|
||||
{
|
||||
text1: `Do you give this application permission to register this name?`,
|
||||
highlightedText: data.name,
|
||||
text2: data?.description
|
||||
text2: data?.description,
|
||||
fee: fee.fee
|
||||
},
|
||||
isFromExtension
|
||||
);
|
||||
@ -3873,11 +3878,13 @@ export const updateNameRequest = async (data, isFromExtension) => {
|
||||
const oldName = data.oldName
|
||||
const newName = data.newName
|
||||
const description = data?.description
|
||||
const fee = await getFee("UPDATE_NAME");
|
||||
const resPermission = await getUserPermission(
|
||||
{
|
||||
text1: `Do you give this application permission to register this name?`,
|
||||
highlightedText: data.newName,
|
||||
text2: data?.description
|
||||
text2: data?.description,
|
||||
fee: fee.fee,
|
||||
},
|
||||
isFromExtension
|
||||
);
|
||||
@ -3886,6 +3893,95 @@ export const updateNameRequest = async (data, isFromExtension) => {
|
||||
const response = await updateName({ oldName, newName, description });
|
||||
return response
|
||||
|
||||
} else {
|
||||
throw new Error("User declined request");
|
||||
}
|
||||
};
|
||||
|
||||
export const leaveGroupRequest = async (data, isFromExtension) => {
|
||||
const requiredFields = ["groupId"];
|
||||
const missingFields: string[] = [];
|
||||
requiredFields.forEach((field) => {
|
||||
if (!data[field]) {
|
||||
missingFields.push(field);
|
||||
}
|
||||
});
|
||||
const groupId = data.groupId
|
||||
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 fee = await getFee("LEAVE_GROUP");
|
||||
const resPermission = await getUserPermission(
|
||||
{
|
||||
text1: `Do you give this application permission to leave the following group?`,
|
||||
highlightedText: `${groupInfo.groupName}`,
|
||||
fee: fee.fee,
|
||||
},
|
||||
isFromExtension
|
||||
);
|
||||
const { accepted } = resPermission;
|
||||
if (accepted) {
|
||||
const response = await leaveGroup({ groupId });
|
||||
return response
|
||||
|
||||
} else {
|
||||
throw new Error("User declined request");
|
||||
}
|
||||
};
|
||||
|
||||
export const inviteToGroupRequest = async (data, isFromExtension) => {
|
||||
const requiredFields = ["groupId", "inviteTime", "inviteeAddress"];
|
||||
const missingFields: string[] = [];
|
||||
requiredFields.forEach((field) => {
|
||||
if (!data[field]) {
|
||||
missingFields.push(field);
|
||||
}
|
||||
});
|
||||
const groupId = data.groupId
|
||||
const qortalAddress = data?.inviteeAddress
|
||||
const inviteTime = data?.inviteTime
|
||||
|
||||
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("GROUP_INVITE");
|
||||
const resPermission = await getUserPermission(
|
||||
{
|
||||
text1: `Do you give this application permission to invite ${displayInvitee || qortalAddress}?`,
|
||||
highlightedText: `Group: ${groupInfo.groupName}`,
|
||||
fee: fee.fee,
|
||||
},
|
||||
isFromExtension
|
||||
);
|
||||
const { accepted } = resPermission;
|
||||
if (accepted) {
|
||||
const response = await inviteToGroup({
|
||||
groupId,
|
||||
qortalAddress,
|
||||
inviteTime,
|
||||
})
|
||||
return response
|
||||
|
||||
} else {
|
||||
throw new Error("User declined request");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user