mirror of
https://github.com/Qortal/Qortal-Hub.git
synced 2025-04-24 20:07:51 +00:00
cases
This commit is contained in:
parent
a439b37007
commit
264a7569e2
25
src/App.tsx
25
src/App.tsx
@ -1264,21 +1264,16 @@ function App() {
|
||||
});
|
||||
setIsLoadingRegisterName(true);
|
||||
new Promise((res, rej) => {
|
||||
chrome?.runtime?.sendMessage(
|
||||
{
|
||||
action: "registerName",
|
||||
payload: {
|
||||
window.sendMessage("registerName", {
|
||||
name: registerNameValue,
|
||||
},
|
||||
},
|
||||
(response) => {
|
||||
})
|
||||
.then((response) => {
|
||||
if (!response?.error) {
|
||||
res(response);
|
||||
setIsLoadingRegisterName(false);
|
||||
setInfoSnack({
|
||||
type: "success",
|
||||
message:
|
||||
"Successfully registered. It may take a couple of minutes for the changes to propagate",
|
||||
message: "Successfully registered. It may take a couple of minutes for the changes to propagate",
|
||||
});
|
||||
setOpenRegisterName(false);
|
||||
setRegisterNameValue("");
|
||||
@ -1301,8 +1296,16 @@ function App() {
|
||||
});
|
||||
setOpenSnack(true);
|
||||
rej(response.error);
|
||||
}
|
||||
);
|
||||
})
|
||||
.catch((error) => {
|
||||
setInfoSnack({
|
||||
type: "error",
|
||||
message: error.message || "An error occurred",
|
||||
});
|
||||
setOpenSnack(true);
|
||||
rej(error);
|
||||
});
|
||||
|
||||
});
|
||||
} catch (error) {
|
||||
if (error?.message) {
|
||||
|
@ -1,6 +1,8 @@
|
||||
import {
|
||||
addDataPublishes,
|
||||
addUserSettings,
|
||||
banFromGroup,
|
||||
cancelBan,
|
||||
cancelInvitationToGroup,
|
||||
createGroup,
|
||||
decryptWallet,
|
||||
@ -12,10 +14,13 @@ import {
|
||||
getNameInfo,
|
||||
getTempPublish,
|
||||
getUserInfo,
|
||||
getUserSettings,
|
||||
inviteToGroup,
|
||||
joinGroup,
|
||||
kickFromGroup,
|
||||
leaveGroup,
|
||||
makeAdmin,
|
||||
registerName,
|
||||
saveTempPublish,
|
||||
sendCoin,
|
||||
walletVersion,
|
||||
@ -549,3 +554,137 @@ export async function balanceCase(request, event) {
|
||||
);
|
||||
}
|
||||
}
|
||||
export async function addUserSettingsCase(request, event) {
|
||||
try {
|
||||
const { keyValue } = request.payload;
|
||||
const response = await addUserSettings({keyValue});
|
||||
|
||||
event.source.postMessage(
|
||||
{
|
||||
requestId: request.requestId,
|
||||
action: "addUserSettings",
|
||||
payload: response,
|
||||
type: "backgroundMessageResponse",
|
||||
},
|
||||
event.origin
|
||||
);
|
||||
} catch (error) {
|
||||
event.source.postMessage(
|
||||
{
|
||||
requestId: request.requestId,
|
||||
action: "addUserSettings",
|
||||
error: error?.message,
|
||||
type: "backgroundMessageResponse",
|
||||
},
|
||||
event.origin
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function getUserSettingsCase(request, event) {
|
||||
try {
|
||||
const { key } = request.payload;
|
||||
const response = await getUserSettings({key});
|
||||
|
||||
event.source.postMessage(
|
||||
{
|
||||
requestId: request.requestId,
|
||||
action: "getUserSettings",
|
||||
payload: response,
|
||||
type: "backgroundMessageResponse",
|
||||
},
|
||||
event.origin
|
||||
);
|
||||
} catch (error) {
|
||||
event.source.postMessage(
|
||||
{
|
||||
requestId: request.requestId,
|
||||
action: "getUserSettings",
|
||||
error: error?.message,
|
||||
type: "backgroundMessageResponse",
|
||||
},
|
||||
event.origin
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function cancelBanCase(request, event) {
|
||||
try {
|
||||
const { groupId, qortalAddress } = request.payload;
|
||||
const response = await cancelBan({groupId, qortalAddress});
|
||||
|
||||
event.source.postMessage(
|
||||
{
|
||||
requestId: request.requestId,
|
||||
action: "cancelBan",
|
||||
payload: response,
|
||||
type: "backgroundMessageResponse",
|
||||
},
|
||||
event.origin
|
||||
);
|
||||
} catch (error) {
|
||||
event.source.postMessage(
|
||||
{
|
||||
requestId: request.requestId,
|
||||
action: "cancelBan",
|
||||
error: error?.message,
|
||||
type: "backgroundMessageResponse",
|
||||
},
|
||||
event.origin
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function registerNameCase(request, event) {
|
||||
try {
|
||||
const { name } = request.payload;
|
||||
const response = await registerName({name});
|
||||
|
||||
event.source.postMessage(
|
||||
{
|
||||
requestId: request.requestId,
|
||||
action: "registerName",
|
||||
payload: response,
|
||||
type: "backgroundMessageResponse",
|
||||
},
|
||||
event.origin
|
||||
);
|
||||
} catch (error) {
|
||||
event.source.postMessage(
|
||||
{
|
||||
requestId: request.requestId,
|
||||
action: "registerName",
|
||||
error: error?.message,
|
||||
type: "backgroundMessageResponse",
|
||||
},
|
||||
event.origin
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function makeAdminCase(request, event) {
|
||||
try {
|
||||
const { groupId, qortalAddress } = request.payload;
|
||||
const response = await makeAdmin({groupId, qortalAddress});
|
||||
|
||||
event.source.postMessage(
|
||||
{
|
||||
requestId: request.requestId,
|
||||
action: "makeAdmin",
|
||||
payload: response,
|
||||
type: "backgroundMessageResponse",
|
||||
},
|
||||
event.origin
|
||||
);
|
||||
} catch (error) {
|
||||
event.source.postMessage(
|
||||
{
|
||||
requestId: request.requestId,
|
||||
action: "makeAdmin",
|
||||
error: error?.message,
|
||||
type: "backgroundMessageResponse",
|
||||
},
|
||||
event.origin
|
||||
);
|
||||
}
|
||||
}
|
@ -30,20 +30,25 @@ import { TradeBotRespondMultipleRequest } from "./transactions/TradeBotRespondMu
|
||||
import { RESOURCE_TYPE_NUMBER_GROUP_CHAT_REACTIONS } from "./constants/resourceTypes";
|
||||
import {
|
||||
addDataPublishesCase,
|
||||
addUserSettingsCase,
|
||||
balanceCase,
|
||||
banFromGroupCase,
|
||||
cancelBanCase,
|
||||
cancelInvitationToGroupCase,
|
||||
createGroupCase,
|
||||
decryptWalletCase,
|
||||
getDataPublishesCase,
|
||||
getTempPublishCase,
|
||||
getUserSettingsCase,
|
||||
getWalletInfoCase,
|
||||
inviteToGroupCase,
|
||||
joinGroupCase,
|
||||
kickFromGroupCase,
|
||||
leaveGroupCase,
|
||||
ltcBalanceCase,
|
||||
makeAdminCase,
|
||||
nameCase,
|
||||
registerNameCase,
|
||||
saveTempPublishCase,
|
||||
sendCoinCase,
|
||||
userInfoCase,
|
||||
@ -1341,7 +1346,7 @@ export async function addDataPublishes(newData, groupId, type) {
|
||||
}
|
||||
|
||||
// Fetch user settings based on the key
|
||||
async function getUserSettings({ key }) {
|
||||
export async function getUserSettings({ key }) {
|
||||
const wallet = await getSaveWallet();
|
||||
const address = wallet.address0;
|
||||
|
||||
@ -1362,7 +1367,7 @@ async function getUserSettings({ key }) {
|
||||
}
|
||||
|
||||
// Add or update user settings
|
||||
async function addUserSettings({ keyValue }) {
|
||||
export async function addUserSettings({ keyValue }) {
|
||||
const wallet = await getSaveWallet();
|
||||
const address = wallet.address0;
|
||||
const { key, value } = keyValue;
|
||||
@ -2105,7 +2110,7 @@ export async function cancelInvitationToGroup({ groupId, qortalAddress }) {
|
||||
return res;
|
||||
}
|
||||
|
||||
async function cancelBan({ groupId, qortalAddress }) {
|
||||
export async function cancelBan({ groupId, qortalAddress }) {
|
||||
const lastReference = await getLastRef();
|
||||
const resKeyPair = await getKeyPair();
|
||||
const parsedData = JSON.parse(resKeyPair);
|
||||
@ -2131,7 +2136,7 @@ async function cancelBan({ groupId, qortalAddress }) {
|
||||
throw new Error("Transaction was not able to be processed");
|
||||
return res;
|
||||
}
|
||||
async function registerName({ name }) {
|
||||
export async function registerName({ name }) {
|
||||
const lastReference = await getLastRef();
|
||||
const resKeyPair = await getKeyPair();
|
||||
const parsedData = JSON.parse(resKeyPair);
|
||||
@ -2157,7 +2162,7 @@ async function registerName({ name }) {
|
||||
throw new Error("Transaction was not able to be processed");
|
||||
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);
|
||||
@ -2245,7 +2250,11 @@ export async function banFromGroup({
|
||||
return res;
|
||||
}
|
||||
|
||||
export async function kickFromGroup({ groupId, qortalAddress, rBanReason = "" }) {
|
||||
export async function kickFromGroup({
|
||||
groupId,
|
||||
qortalAddress,
|
||||
rBanReason = "",
|
||||
}) {
|
||||
const lastReference = await getLastRef();
|
||||
const resKeyPair = await getKeyPair();
|
||||
const parsedData = JSON.parse(resKeyPair);
|
||||
@ -2948,6 +2957,19 @@ function setupMessageListener() {
|
||||
case "getDataPublishes":
|
||||
getDataPublishesCase(request, event);
|
||||
break;
|
||||
case "addUserSettings":
|
||||
addUserSettingsCase(request, event);
|
||||
break;
|
||||
case "cancelBan":
|
||||
cancelBanCase(request, event);
|
||||
break;
|
||||
case "registerName":
|
||||
registerNameCase(request, event);
|
||||
break;
|
||||
|
||||
case "makeAdmin":
|
||||
makeAdminCase(request, event);
|
||||
break;
|
||||
default:
|
||||
console.error("Unknown action:", request.action);
|
||||
}
|
||||
|
@ -77,17 +77,23 @@ export const ContextMenu = ({ children, groupId, getUserSettings, mutedGroups })
|
||||
} else {
|
||||
value.push(groupId)
|
||||
}
|
||||
chrome?.runtime?.sendMessage(
|
||||
{
|
||||
action: "addUserSettings",
|
||||
payload: {
|
||||
window.sendMessage("addUserSettings", {
|
||||
keyValue: {
|
||||
key: 'mutedGroups',
|
||||
value
|
||||
},
|
||||
value,
|
||||
},
|
||||
})
|
||||
.then((response) => {
|
||||
if (response?.error) {
|
||||
console.error("Error adding user settings:", response.error);
|
||||
} else {
|
||||
console.log("User settings added successfully");
|
||||
}
|
||||
);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Failed to add user settings:", error.message || "An error occurred");
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
getUserSettings()
|
||||
}, 400);
|
||||
|
@ -475,22 +475,21 @@ export const Group = ({
|
||||
const getUserSettings = async () => {
|
||||
try {
|
||||
return new Promise((res, rej) => {
|
||||
chrome?.runtime?.sendMessage(
|
||||
{
|
||||
action: "getUserSettings",
|
||||
payload: {
|
||||
window.sendMessage("getUserSettings", {
|
||||
key: "mutedGroups",
|
||||
},
|
||||
},
|
||||
(response) => {
|
||||
})
|
||||
.then((response) => {
|
||||
if (!response?.error) {
|
||||
setMutedGroups(response || []);
|
||||
res(response);
|
||||
return;
|
||||
}
|
||||
rej(response.error);
|
||||
}
|
||||
);
|
||||
})
|
||||
.catch((error) => {
|
||||
rej(error.message || "An error occurred");
|
||||
});
|
||||
|
||||
});
|
||||
} catch (error) {
|
||||
console.log("error", error);
|
||||
|
@ -74,29 +74,38 @@ export const ListOfBans = ({ groupId, setInfoSnack, setOpenSnack, show }) => {
|
||||
})
|
||||
setIsLoadingUnban(true)
|
||||
new Promise((res, rej)=> {
|
||||
chrome?.runtime?.sendMessage({ action: "cancelBan", payload: {
|
||||
window.sendMessage("cancelBan", {
|
||||
groupId,
|
||||
qortalAddress: address,
|
||||
}}, (response) => {
|
||||
|
||||
})
|
||||
.then((response) => {
|
||||
if (!response?.error) {
|
||||
res(response)
|
||||
setIsLoadingUnban(false)
|
||||
res(response);
|
||||
setIsLoadingUnban(false);
|
||||
setInfoSnack({
|
||||
type: "success",
|
||||
message: "Successfully unbanned user. It may take a couple of minutes for the changes to propagate",
|
||||
});
|
||||
handlePopoverClose();
|
||||
setOpenSnack(true);
|
||||
return
|
||||
return;
|
||||
}
|
||||
setInfoSnack({
|
||||
type: "error",
|
||||
message: response?.error,
|
||||
});
|
||||
setOpenSnack(true);
|
||||
rej(response.error)
|
||||
rej(response.error);
|
||||
})
|
||||
.catch((error) => {
|
||||
setInfoSnack({
|
||||
type: "error",
|
||||
message: error.message || "An error occurred",
|
||||
});
|
||||
setOpenSnack(true);
|
||||
rej(error);
|
||||
});
|
||||
|
||||
})
|
||||
} catch (error) {
|
||||
|
||||
|
@ -157,21 +157,15 @@ const ListOfMembers = ({
|
||||
});
|
||||
setIsLoadingMakeAdmin(true);
|
||||
await new Promise((res, rej) => {
|
||||
chrome?.runtime?.sendMessage(
|
||||
{
|
||||
action: "makeAdmin",
|
||||
payload: {
|
||||
window.sendMessage("makeAdmin", {
|
||||
groupId,
|
||||
qortalAddress: address,
|
||||
},
|
||||
},
|
||||
(response) => {
|
||||
|
||||
})
|
||||
.then((response) => {
|
||||
if (!response?.error) {
|
||||
setInfoSnack({
|
||||
type: "success",
|
||||
message:
|
||||
"Successfully made member an admin. It may take a couple of minutes for the changes to propagate",
|
||||
message: "Successfully made member an admin. It may take a couple of minutes for the changes to propagate",
|
||||
});
|
||||
setOpenSnack(true);
|
||||
handlePopoverClose();
|
||||
@ -184,8 +178,16 @@ const ListOfMembers = ({
|
||||
});
|
||||
setOpenSnack(true);
|
||||
rej(response.error);
|
||||
}
|
||||
);
|
||||
})
|
||||
.catch((error) => {
|
||||
setInfoSnack({
|
||||
type: "error",
|
||||
message: error.message || "An error occurred",
|
||||
});
|
||||
setOpenSnack(true);
|
||||
rej(error);
|
||||
});
|
||||
|
||||
});
|
||||
} catch (error) {
|
||||
} finally {
|
||||
|
@ -84,17 +84,23 @@ export const Settings = ({
|
||||
|
||||
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
setChecked(event.target.checked);
|
||||
chrome?.runtime?.sendMessage(
|
||||
{
|
||||
action: "addUserSettings",
|
||||
payload: {
|
||||
window.sendMessage("addUserSettings", {
|
||||
keyValue: {
|
||||
key: 'disable-push-notifications',
|
||||
value: event.target.checked
|
||||
},
|
||||
value: event.target.checked,
|
||||
},
|
||||
})
|
||||
.then((response) => {
|
||||
if (response?.error) {
|
||||
console.error("Error adding user settings:", response.error);
|
||||
} else {
|
||||
console.log("User settings added successfully");
|
||||
}
|
||||
);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Failed to add user settings:", error.message || "An error occurred");
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
@ -104,22 +110,21 @@ export const Settings = ({
|
||||
const getUserSettings = async () => {
|
||||
try {
|
||||
return new Promise((res, rej) => {
|
||||
chrome?.runtime?.sendMessage(
|
||||
{
|
||||
action: "getUserSettings",
|
||||
payload: {
|
||||
window.sendMessage("getUserSettings", {
|
||||
key: "disable-push-notifications",
|
||||
},
|
||||
},
|
||||
(response) => {
|
||||
})
|
||||
.then((response) => {
|
||||
if (!response?.error) {
|
||||
setChecked(response || false);
|
||||
res(response);
|
||||
return;
|
||||
}
|
||||
rej(response.error);
|
||||
}
|
||||
);
|
||||
})
|
||||
.catch((error) => {
|
||||
rej(error.message || "An error occurred");
|
||||
});
|
||||
|
||||
});
|
||||
} catch (error) {
|
||||
console.log("error", error);
|
||||
|
Loading…
x
Reference in New Issue
Block a user