Refactor translation and use only a parametric item

This commit is contained in:
Nicola Benaglia 2025-05-10 08:26:04 +02:00
parent 7cd3d10d67
commit 69b811b520
14 changed files with 84 additions and 36 deletions

View File

@ -32,10 +32,7 @@
"invitation_expiry": "invitation Expiry Time", "invitation_expiry": "invitation Expiry Time",
"join_requests": "join requests", "join_requests": "join requests",
"question": { "question": {
"cancel_ban": "would you like to perform a CANCEL_GROUP_BAN transaction?", "perform_transaction": "would you like to perform a {{action}} transaction?",
"create_group": "would you like to perform an CREATE_GROUP transaction?",
"group_invite": "would you like to perform a GROUP_INVITE transaction?",
"join_group": "would you like to perform an JOIN_GROUP transaction?",
"provide_thread": "please provide a thread title" "provide_thread": "please provide a thread title"
}, },
"message": { "message": {

View File

@ -31,6 +31,7 @@ import {
import { RequestQueueWithPromise } from '../../utils/queue/queue'; import { RequestQueueWithPromise } from '../../utils/queue/queue';
import { CustomizedSnackbars } from '../Snackbar/Snackbar'; import { CustomizedSnackbars } from '../Snackbar/Snackbar';
import { addDataPublishesFunc, getDataPublishesFunc } from '../Group/Group'; import { addDataPublishesFunc, getDataPublishesFunc } from '../Group/Group';
import { useTranslation } from 'react-i18next';
const uid = new ShortUniqueId({ length: 8 }); const uid = new ShortUniqueId({ length: 8 });
@ -101,6 +102,7 @@ export const decryptPublishes = async (encryptedMessages: any[], secretKey) => {
console.log(error); console.log(error);
} }
}; };
export const handleUnencryptedPublishes = (publishes) => { export const handleUnencryptedPublishes = (publishes) => {
let publishesData = []; let publishesData = [];
publishes.forEach((pub) => { publishes.forEach((pub) => {
@ -149,6 +151,7 @@ export const GroupAnnouncements = ({
editorRef.current = editorInstance; editorRef.current = editorInstance;
}; };
const [, forceUpdate] = React.useReducer((x) => x + 1, 0); const [, forceUpdate] = React.useReducer((x) => x + 1, 0);
const { t } = useTranslation(['core', 'group']);
const triggerRerender = () => { const triggerRerender = () => {
forceUpdate(); // Trigger re-render by updating the state forceUpdate(); // Trigger re-render by updating the state
@ -209,7 +212,6 @@ export const GroupAnnouncements = ({
) )
return; return;
setIsLoading(true); setIsLoading(true);
// initWebsocketMessageGroup()
hasInitializedWebsocket.current = true; hasInitializedWebsocket.current = true;
}, [secretKey, isPrivate]); }, [secretKey, isPrivate]);
@ -287,7 +289,10 @@ export const GroupAnnouncements = ({
const fee = await getFee('ARBITRARY'); const fee = await getFee('ARBITRARY');
await show({ await show({
message: 'Would you like to perform a ARBITRARY transaction?', message: t('group:question.perform_transaction', {
action: 'ARBITRARY',
postProcess: 'capitalize',
}),
publishFee: fee.fee + ' QORT', publishFee: fee.fee + ' QORT',
}); });
@ -329,7 +334,7 @@ export const GroupAnnouncements = ({
setTempData(selectedGroup); setTempData(selectedGroup);
clearEditorContent(); clearEditorContent();
} }
// send chat message // TODO send chat message
} catch (error) { } catch (error) {
if (!error) return; if (!error) return;
setInfoSnack({ setInfoSnack({

View File

@ -1,8 +1,7 @@
import React, { useContext, useEffect, useMemo, useState } from 'react'; import { useContext, useEffect, useMemo, useState } from 'react';
import { subscribeToEvent, unsubscribeFromEvent } from '../../utils/events'; import { subscribeToEvent, unsubscribeFromEvent } from '../../utils/events';
import { import {
Box, Box,
Button,
ButtonBase, ButtonBase,
CircularProgress, CircularProgress,
Dialog, Dialog,
@ -11,13 +10,14 @@ import {
Typography, Typography,
useTheme, useTheme,
} from '@mui/material'; } from '@mui/material';
import { CustomButton, CustomButtonAccept } from '../../styles/App-styles'; import { CustomButtonAccept } from '../../styles/App-styles';
import { getBaseApiReact, MyContext } from '../../App'; import { getBaseApiReact, MyContext } from '../../App';
import { getFee } from '../../background'; import { getFee } from '../../background';
import { CustomizedSnackbars } from '../Snackbar/Snackbar'; import { CustomizedSnackbars } from '../Snackbar/Snackbar';
import { FidgetSpinner } from 'react-loader-spinner'; import { FidgetSpinner } from 'react-loader-spinner';
import { useAtom, useSetAtom } from 'jotai'; import { useAtom, useSetAtom } from 'jotai';
import { memberGroupsAtom, txListAtom } from '../../atoms/global'; import { memberGroupsAtom, txListAtom } from '../../atoms/global';
import { useTranslation } from 'react-i18next';
export const JoinGroup = () => { export const JoinGroup = () => {
const { show } = useContext(MyContext); const { show } = useContext(MyContext);
@ -29,7 +29,9 @@ export const JoinGroup = () => {
const [isLoadingInfo, setIsLoadingInfo] = useState(false); const [isLoadingInfo, setIsLoadingInfo] = useState(false);
const [isOpen, setIsOpen] = useState(false); const [isOpen, setIsOpen] = useState(false);
const theme = useTheme(); const theme = useTheme();
const { t } = useTranslation(['core', 'group']);
const [isLoadingJoinGroup, setIsLoadingJoinGroup] = useState(false); const [isLoadingJoinGroup, setIsLoadingJoinGroup] = useState(false);
const handleJoinGroup = async (e) => { const handleJoinGroup = async (e) => {
setGroupInfo(null); setGroupInfo(null);
const groupId = e?.detail?.groupId; const groupId = e?.detail?.groupId;
@ -41,6 +43,7 @@ export const JoinGroup = () => {
const groupData = await response.json(); const groupData = await response.json();
setGroupInfo(groupData); setGroupInfo(groupData);
} catch (error) { } catch (error) {
console.log(error);
} finally { } finally {
setIsLoadingInfo(false); setIsLoadingInfo(false);
} }
@ -60,12 +63,16 @@ export const JoinGroup = () => {
(item) => +item?.groupId === +groupInfo?.groupId (item) => +item?.groupId === +groupInfo?.groupId
); );
}, [memberGroups, groupInfo]); }, [memberGroups, groupInfo]);
const joinGroup = async (group, isOpen) => { const joinGroup = async (group, isOpen) => {
try { try {
const groupId = group.groupId; const groupId = group.groupId;
const fee = await getFee('JOIN_GROUP'); const fee = await getFee('JOIN_GROUP');
await show({ await show({
message: 'Would you like to perform an JOIN_GROUP transaction?', message: t('group:question.perform_transaction', {
action: 'JOIN_GROUP',
postProcess: 'capitalize',
}),
publishFee: fee.fee + ' QORT', publishFee: fee.fee + ' QORT',
}); });
setIsLoadingJoinGroup(true); setIsLoadingJoinGroup(true);

View File

@ -118,7 +118,8 @@ export const AddGroup = ({ address, open, setOpen }) => {
const fee = await getFee('CREATE_GROUP'); const fee = await getFee('CREATE_GROUP');
await show({ await show({
message: t('group:question.create_group', { message: t('group:question.perform_transaction', {
action: 'CREATE_GROUP',
postProcess: 'capitalize', postProcess: 'capitalize',
}), }),
publishFee: fee.fee + ' QORT', publishFee: fee.fee + ' QORT',

View File

@ -113,7 +113,8 @@ export const AddGroupList = ({ setInfoSnack, setOpenSnack }) => {
const fee = await getFee('JOIN_GROUP'); const fee = await getFee('JOIN_GROUP');
await show({ await show({
message: t('group:question.join_group', { message: t('group:question.perform_transaction', {
action: 'JOIN_GROUP',
postProcess: 'capitalize', postProcess: 'capitalize',
}), }),
publishFee: fee.fee + ' QORT', publishFee: fee.fee + ' QORT',

View File

@ -208,12 +208,6 @@ export const NewThread = ({
} }
if (errorMsg) { if (errorMsg) {
// dispatch(
// setNotification({
// msg: errorMsg,
// alertType: "error",
// })
// );
throw new Error(errorMsg); throw new Error(errorMsg);
} }
@ -221,13 +215,18 @@ export const NewThread = ({
if (!htmlContent?.trim() || htmlContent?.trim() === '<p></p>') if (!htmlContent?.trim() || htmlContent?.trim() === '<p></p>')
throw new Error('Please provide a first message to the thread'); throw new Error('Please provide a first message to the thread');
const fee = await getFee('ARBITRARY'); const fee = await getFee('ARBITRARY');
let feeToShow = fee.fee; let feeToShow = fee.fee;
if (!isMessage) { if (!isMessage) {
feeToShow = +feeToShow * 2; feeToShow = +feeToShow * 2;
} }
await show({ await show({
message: 'Would you like to perform a ARBITRARY transaction?', message: t('group:question.perform_transaction', {
action: 'ARBITRARY',
postProcess: 'capitalize',
}),
publishFee: feeToShow + ' QORT', publishFee: feeToShow + ' QORT',
}); });
@ -516,7 +515,6 @@ export const NewThread = ({
overrideMobile overrideMobile
customEditorHeight="240px" customEditorHeight="240px"
/> />
</Box> </Box>
</InstanceListContainer> </InstanceListContainer>

View File

@ -16,7 +16,8 @@ export const InviteMember = ({ groupId, setInfoSnack, setOpenSnack, show }) => {
try { try {
const fee = await getFee('GROUP_INVITE'); const fee = await getFee('GROUP_INVITE');
await show({ await show({
message: t('group:question.group_invite', { message: t('group:question.perform_transaction', {
action: 'GROUP_INVITE',
postProcess: 'capitalize', postProcess: 'capitalize',
}), }),
publishFee: fee.fee + ' QORT', publishFee: fee.fee + ' QORT',

View File

@ -88,7 +88,10 @@ export const ListOfBans = ({ groupId, setInfoSnack, setOpenSnack, show }) => {
try { try {
const fee = await getFee('CANCEL_GROUP_BAN'); const fee = await getFee('CANCEL_GROUP_BAN');
await show({ await show({
message: t('group:question.cancel_ban', { postProcess: 'capitalize' }), message: t('group:question.perform_transaction', {
action: 'CANCEL_GROUP_BAN',
postProcess: 'capitalize',
}),
publishFee: fee.fee + ' QORT', publishFee: fee.fee + ' QORT',
}); });
setIsLoadingUnban(true); setIsLoadingUnban(true);

View File

@ -51,6 +51,11 @@ import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
import ExpandLessIcon from '@mui/icons-material/ExpandLess'; import ExpandLessIcon from '@mui/icons-material/ExpandLess';
import { getFee } from '../../background'; import { getFee } from '../../background';
import { useAtom, useSetAtom } from 'jotai'; import { useAtom, useSetAtom } from 'jotai';
import { useTranslation } from 'react-i18next';
const THIRTY_MINUTES = 30 * 60 * 1000; // 30 minutes in milliseconds
const uid = new ShortUniqueId({ length: 8 });
export const requestQueuePromos = new RequestQueueWithPromise(3); export const requestQueuePromos = new RequestQueueWithPromise(3);
export function utf8ToBase64(inputString: string): string { export function utf8ToBase64(inputString: string): string {
@ -65,13 +70,11 @@ export function utf8ToBase64(inputString: string): string {
return base64String; return base64String;
} }
const uid = new ShortUniqueId({ length: 8 });
export function getGroupId(str) { export function getGroupId(str) {
const match = str.match(/group-(\d+)-/); const match = str.match(/group-(\d+)-/);
return match ? match[1] : null; return match ? match[1] : null;
} }
const THIRTY_MINUTES = 30 * 60 * 1000; // 30 minutes in milliseconds
export const ListOfGroupPromotions = () => { export const ListOfGroupPromotions = () => {
const [popoverAnchor, setPopoverAnchor] = useState(null); const [popoverAnchor, setPopoverAnchor] = useState(null);
const [openPopoverIndex, setOpenPopoverIndex] = useState(null); const [openPopoverIndex, setOpenPopoverIndex] = useState(null);
@ -98,6 +101,7 @@ export const ListOfGroupPromotions = () => {
const setTxList = useSetAtom(txListAtom); const setTxList = useSetAtom(txListAtom);
const theme = useTheme(); const theme = useTheme();
const { t } = useTranslation(['core', 'group']);
const listRef = useRef(); const listRef = useRef();
const rowVirtualizer = useVirtualizer({ const rowVirtualizer = useVirtualizer({
count: promotions.length, count: promotions.length,
@ -120,6 +124,7 @@ export const ListOfGroupPromotions = () => {
console.log(error); console.log(error);
} }
}, []); }, []);
const getPromotions = useCallback(async () => { const getPromotions = useCallback(async () => {
try { try {
setPromotionTimeInterval(Date.now()); setPromotionTimeInterval(Date.now());
@ -213,6 +218,7 @@ export const ListOfGroupPromotions = () => {
setPopoverAnchor(null); setPopoverAnchor(null);
setOpenPopoverIndex(null); setOpenPopoverIndex(null);
}; };
const publishPromo = async () => { const publishPromo = async () => {
try { try {
setIsLoadingPublish(true); setIsLoadingPublish(true);
@ -264,7 +270,10 @@ export const ListOfGroupPromotions = () => {
const groupId = group.groupId; const groupId = group.groupId;
const fee = await getFee('JOIN_GROUP'); const fee = await getFee('JOIN_GROUP');
await show({ await show({
message: 'Would you like to perform an JOIN_GROUP transaction?', message: t('group:question.perform_transaction', {
action: 'JOIN_GROUP',
postProcess: 'capitalize',
}),
publishFee: fee.fee + ' QORT', publishFee: fee.fee + ' QORT',
}); });
setIsLoadingJoinGroup(true); setIsLoadingJoinGroup(true);

View File

@ -18,6 +18,7 @@ import { getNameInfo } from './Group';
import { getFee } from '../../background'; import { getFee } from '../../background';
import { LoadingButton } from '@mui/lab'; import { LoadingButton } from '@mui/lab';
import { getBaseApiReact } from '../../App'; import { getBaseApiReact } from '../../App';
import { useTranslation } from 'react-i18next';
export const getMemberInvites = async (groupNumber) => { export const getMemberInvites = async (groupNumber) => {
const response = await fetch( const response = await fetch(
@ -59,7 +60,7 @@ export const ListOfInvites = ({
const [popoverAnchor, setPopoverAnchor] = useState(null); // Track which list item the popover is anchored to const [popoverAnchor, setPopoverAnchor] = useState(null); // Track which list item the popover is anchored to
const [openPopoverIndex, setOpenPopoverIndex] = useState(null); // Track which list item has the popover open const [openPopoverIndex, setOpenPopoverIndex] = useState(null); // Track which list item has the popover open
const [isLoadingCancelInvite, setIsLoadingCancelInvite] = useState(false); const [isLoadingCancelInvite, setIsLoadingCancelInvite] = useState(false);
const { t } = useTranslation(['core', 'group']);
const listRef = useRef(); const listRef = useRef();
const getInvites = async (groupId) => { const getInvites = async (groupId) => {
@ -92,8 +93,12 @@ export const ListOfInvites = ({
try { try {
// TODO translate // TODO translate
const fee = await getFee('CANCEL_GROUP_INVITE'); const fee = await getFee('CANCEL_GROUP_INVITE');
await show({ await show({
message: 'Would you like to perform a CANCEL_GROUP_INVITE transaction?', message: t('group:question.perform_transaction', {
action: 'CANCEL_GROUP_INVITE',
postProcess: 'capitalize',
}),
publishFee: fee.fee + ' QORT', publishFee: fee.fee + ' QORT',
}); });
setIsLoadingCancelInvite(true); setIsLoadingCancelInvite(true);

View File

@ -95,7 +95,10 @@ export const ListOfJoinRequests = ({
try { try {
const fee = await getFee('GROUP_INVITE'); // TODO translate const fee = await getFee('GROUP_INVITE'); // TODO translate
await show({ await show({
message: 'Would you like to perform a GROUP_INVITE transaction?', message: t('group:question.perform_transaction', {
action: 'GROUP_INVITE',
postProcess: 'capitalize',
}),
publishFee: fee.fee + ' QORT', publishFee: fee.fee + ' QORT',
}); });
setIsLoadingAccept(true); setIsLoadingAccept(true);

View File

@ -19,6 +19,7 @@ import {
import { LoadingButton } from '@mui/lab'; import { LoadingButton } from '@mui/lab';
import { getFee } from '../../background'; import { getFee } from '../../background';
import { getBaseApiReact } from '../../App'; import { getBaseApiReact } from '../../App';
import { useTranslation } from 'react-i18next';
const cache = new CellMeasurerCache({ const cache = new CellMeasurerCache({
fixedWidth: true, fixedWidth: true,
@ -41,6 +42,7 @@ const ListOfMembers = ({
const [isLoadingMakeAdmin, setIsLoadingMakeAdmin] = useState(false); const [isLoadingMakeAdmin, setIsLoadingMakeAdmin] = useState(false);
const [isLoadingRemoveAdmin, setIsLoadingRemoveAdmin] = useState(false); const [isLoadingRemoveAdmin, setIsLoadingRemoveAdmin] = useState(false);
const theme = useTheme(); const theme = useTheme();
const { t } = useTranslation(['core', 'group']);
const listRef = useRef(); const listRef = useRef();
const handlePopoverOpen = (event, index) => { const handlePopoverOpen = (event, index) => {
@ -57,7 +59,10 @@ const ListOfMembers = ({
try { try {
const fee = await getFee('GROUP_KICK'); const fee = await getFee('GROUP_KICK');
await show({ await show({
message: 'Would you like to perform a GROUP_KICK transaction?', message: t('group:question.perform_transaction', {
action: 'GROUP_KICK',
postProcess: 'capitalize',
}),
publishFee: fee.fee + ' QORT', publishFee: fee.fee + ' QORT',
}); });
@ -106,7 +111,10 @@ const ListOfMembers = ({
try { try {
const fee = await getFee('GROUP_BAN'); // TODO translate const fee = await getFee('GROUP_BAN'); // TODO translate
await show({ await show({
message: 'Would you like to perform a GROUP_BAN transaction?', message: t('group:question.perform_transaction', {
action: 'GROUP_BAN',
postProcess: 'capitalize',
}),
publishFee: fee.fee + ' QORT', publishFee: fee.fee + ' QORT',
}); });
setIsLoadingBan(true); setIsLoadingBan(true);
@ -155,7 +163,10 @@ const ListOfMembers = ({
try { try {
const fee = await getFee('ADD_GROUP_ADMIN'); const fee = await getFee('ADD_GROUP_ADMIN');
await show({ await show({
message: 'Would you like to perform a ADD_GROUP_ADMIN transaction?', message: t('group:question.perform_transaction', {
action: 'ADD_GROUP_ADMIN',
postProcess: 'capitalize',
}),
publishFee: fee.fee + ' QORT', publishFee: fee.fee + ' QORT',
}); });
setIsLoadingMakeAdmin(true); setIsLoadingMakeAdmin(true);
@ -203,7 +214,10 @@ const ListOfMembers = ({
try { try {
const fee = await getFee('REMOVE_GROUP_ADMIN'); const fee = await getFee('REMOVE_GROUP_ADMIN');
await show({ await show({
message: 'Would you like to perform a REMOVE_GROUP_ADMIN transaction?', message: t('group:question.perform_transaction', {
action: 'REMOVE_GROUP_ADMIN',
postProcess: 'capitalize',
}),
publishFee: fee.fee + ' QORT', publishFee: fee.fee + ' QORT',
}); });
setIsLoadingRemoveAdmin(true); setIsLoadingRemoveAdmin(true);

View File

@ -75,7 +75,10 @@ export const ManageMembers = ({
setIsLoadingLeave(true); setIsLoadingLeave(true);
const fee = await getFee('LEAVE_GROUP'); // TODO translate const fee = await getFee('LEAVE_GROUP'); // TODO translate
await show({ await show({
message: 'Would you like to perform an LEAVE_GROUP transaction?', message: t('group:question.perform_transaction', {
action: 'LEAVE_GROUP',
postProcess: 'capitalize',
}),
publishFee: fee.fee + ' QORT', publishFee: fee.fee + ' QORT',
}); });

View File

@ -99,7 +99,8 @@ export const UserListOfInvites = ({
const fee = await getFee('JOIN_GROUP'); const fee = await getFee('JOIN_GROUP');
await show({ await show({
message: t('group:question.join_group', { message: t('group:question.perform_transaction', {
action: 'JOIN_GROUP',
postProcess: 'capitalize', postProcess: 'capitalize',
}), }),
publishFee: fee.fee + ' QORT', publishFee: fee.fee + ' QORT',