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 "";
|
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) {
|
async function getAddressInfo(address) {
|
||||||
const validApi = await getBaseApi();
|
const validApi = await getBaseApi();
|
||||||
const response = await fetch(validApi + "/addresses/" + address);
|
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 wallet = await getSaveWallet();
|
||||||
const address = wallet.address0;
|
const address = wallet.address0;
|
||||||
const lastReference = await getLastRef();
|
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");
|
if (!res?.signature) throw new Error(res?.message || "Transaction was not able to be processed");
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
async function inviteToGroup({ groupId, qortalAddress, inviteTime }) {
|
export async function inviteToGroup({ groupId, qortalAddress, inviteTime }) {
|
||||||
const address = await getNameOrAddress(qortalAddress);
|
const address = await getNameOrAddress(qortalAddress);
|
||||||
if (!address) throw new Error("Cannot find user");
|
if (!address) throw new Error("Cannot find user");
|
||||||
const lastReference = await getLastRef();
|
const lastReference = await getLastRef();
|
||||||
|
@ -243,7 +243,7 @@ const UIQortalRequests = [
|
|||||||
'GET_TX_ACTIVITY_SUMMARY', 'GET_FOREIGN_FEE', 'UPDATE_FOREIGN_FEE',
|
'GET_TX_ACTIVITY_SUMMARY', 'GET_FOREIGN_FEE', 'UPDATE_FOREIGN_FEE',
|
||||||
'GET_SERVER_CONNECTION_HISTORY', 'SET_CURRENT_FOREIGN_SERVER',
|
'GET_SERVER_CONNECTION_HISTORY', 'SET_CURRENT_FOREIGN_SERVER',
|
||||||
'ADD_FOREIGN_SERVER', 'REMOVE_FOREIGN_SERVER', 'GET_DAY_SUMMARY', 'CREATE_TRADE_BUY_ORDER',
|
'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 { 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 = [
|
const listOfAllQortalRequests = [
|
||||||
'GET_USER_ACCOUNT', 'DECRYPT_DATA', 'SEND_COIN', 'GET_LIST_ITEMS',
|
'GET_USER_ACCOUNT', 'DECRYPT_DATA', 'SEND_COIN', 'GET_LIST_ITEMS',
|
||||||
@ -647,6 +647,33 @@ chrome?.runtime?.onMessage.addListener((request, sender, sendResponse) => {
|
|||||||
});
|
});
|
||||||
break;
|
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;
|
return true;
|
||||||
|
@ -18,7 +18,10 @@ import {
|
|||||||
getBaseApi,
|
getBaseApi,
|
||||||
getArbitraryEndpoint,
|
getArbitraryEndpoint,
|
||||||
updateName,
|
updateName,
|
||||||
registerName
|
registerName,
|
||||||
|
getNameInfoForOthers,
|
||||||
|
leaveGroup,
|
||||||
|
inviteToGroup
|
||||||
} from "../background";
|
} from "../background";
|
||||||
import { decryptGroupEncryption, getNameInfo, uint8ArrayToObject } from "../backgroundFunctions/encryption";
|
import { decryptGroupEncryption, getNameInfo, uint8ArrayToObject } from "../backgroundFunctions/encryption";
|
||||||
import { QORT_DECIMALS } from "../constants/constants";
|
import { QORT_DECIMALS } from "../constants/constants";
|
||||||
@ -3842,11 +3845,13 @@ export const registerNameRequest = async (data, isFromExtension) => {
|
|||||||
missingFields.push(field);
|
missingFields.push(field);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
const fee = await getFee("REGISTER_NAME");
|
||||||
const resPermission = await getUserPermission(
|
const resPermission = await getUserPermission(
|
||||||
{
|
{
|
||||||
text1: `Do you give this application permission to register this name?`,
|
text1: `Do you give this application permission to register this name?`,
|
||||||
highlightedText: data.name,
|
highlightedText: data.name,
|
||||||
text2: data?.description
|
text2: data?.description,
|
||||||
|
fee: fee.fee
|
||||||
},
|
},
|
||||||
isFromExtension
|
isFromExtension
|
||||||
);
|
);
|
||||||
@ -3873,11 +3878,13 @@ export const updateNameRequest = async (data, isFromExtension) => {
|
|||||||
const oldName = data.oldName
|
const oldName = data.oldName
|
||||||
const newName = data.newName
|
const newName = data.newName
|
||||||
const description = data?.description
|
const description = data?.description
|
||||||
|
const fee = await getFee("UPDATE_NAME");
|
||||||
const resPermission = await getUserPermission(
|
const resPermission = await getUserPermission(
|
||||||
{
|
{
|
||||||
text1: `Do you give this application permission to register this name?`,
|
text1: `Do you give this application permission to register this name?`,
|
||||||
highlightedText: data.newName,
|
highlightedText: data.newName,
|
||||||
text2: data?.description
|
text2: data?.description,
|
||||||
|
fee: fee.fee,
|
||||||
},
|
},
|
||||||
isFromExtension
|
isFromExtension
|
||||||
);
|
);
|
||||||
@ -3886,6 +3893,95 @@ export const updateNameRequest = async (data, isFromExtension) => {
|
|||||||
const response = await updateName({ oldName, newName, description });
|
const response = await updateName({ oldName, newName, description });
|
||||||
return response
|
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 {
|
} else {
|
||||||
throw new Error("User declined request");
|
throw new Error("User declined request");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user