diff --git a/src/components/Chat/AdminSpace.tsx b/src/components/Chat/AdminSpace.tsx index 49109aa..ca080d8 100644 --- a/src/components/Chat/AdminSpace.tsx +++ b/src/components/Chat/AdminSpace.tsx @@ -1,7 +1,7 @@ -import { useContext, useEffect, useState } from 'react'; -import { MyContext } from '../../App'; +import { useEffect, useState } from 'react'; import { Box, Typography } from '@mui/material'; import { AdminSpaceInner } from './AdminSpaceInner'; +import { useTranslation } from 'react-i18next'; export const AdminSpace = ({ selectedGroup, @@ -19,6 +19,8 @@ export const AdminSpace = ({ isOwner, }) => { const [isMoved, setIsMoved] = useState(false); + const { t } = useTranslation(['core', 'group']); + useEffect(() => { if (hide) { setTimeout(() => setIsMoved(true), 300); // Wait for the fade-out to complete before moving @@ -35,10 +37,10 @@ export const AdminSpace = ({ height: 'calc(100vh - 70px)', left: hide && '-1000px', opacity: hide ? 0 : 1, + overflow: 'auto', position: hide ? 'fixed' : 'relative', visibility: hide && 'hidden', width: '100%', - overflow: 'auto', }} > {!isAdmin && ( @@ -50,9 +52,14 @@ export const AdminSpace = ({ width: '100%', }} > - Sorry, this space is only for Admins. + + {t('core:message.generic.space_for_admins', { + postProcess: 'capitalizeFirst', + })} + )} + {isAdmin && ( { try { @@ -81,20 +84,24 @@ export const AdminSpaceInner = ({ selectedGroup ); if (getLatestPublish === false) return; - let data; const res = await fetch( `${getBaseApiReact()}/arbitrary/DOCUMENT_PRIVATE/${ getLatestPublish.name }/${getLatestPublish.identifier}?encoding=base64&rebuild=true` ); - data = await res.text(); + const data = await res.text(); const decryptedKey: any = await decryptResource(data); const dataint8Array = base64ToUint8Array(decryptedKey.data); const decryptedKeyToObject = uint8ArrayToObject(dataint8Array); + if (!validateSecretKey(decryptedKeyToObject)) - throw new Error('SecretKey is not valid'); + throw new Error( + t('auth:message.error.invalid_secret_key', { + postProcess: 'capitalizeFirst', + }) + ); setAdminGroupSecretKey(decryptedKeyToObject); setAdminGroupSecretKeyPublishDetails(getLatestPublish); } catch (error) { @@ -125,7 +132,10 @@ export const AdminSpaceInner = ({ const fee = await getFee('ARBITRARY'); await show({ - message: 'Would you like to perform an ARBITRARY transaction?', + message: t('core:question.perform_transaction', { + action: 'ARBITRARY', + postProcess: 'capitalizeFirst', + }), publishFee: fee.fee + ' QORT', }); @@ -141,22 +151,31 @@ export const AdminSpaceInner = ({ if (!response?.error) { setInfoSnackCustom({ type: 'success', - message: - 'Successfully re-encrypted secret key. It may take a couple of minutes for the changes to propagate. Refresh the group in 5 mins.', + message: t('auth:message.success.reencrypted_secret_key', { + postProcess: 'capitalizeFirst', + }), }); setOpenSnackGlobal(true); return; } setInfoSnackCustom({ type: 'error', - message: response?.error || 'unable to re-encrypt secret key', + message: + response?.error || + t('auth:message.error.unable_reencrypt_secret_key', { + postProcess: 'capitalizeFirst', + }), }); setOpenSnackGlobal(true); }) .catch((error) => { setInfoSnackCustom({ type: 'error', - message: error?.message || 'unable to re-encrypt secret key', + message: + error?.message || + t('auth:message.error.unable_reencrypt_secret_key', { + postProcess: 'capitalizeFirst', + }), }); setOpenSnackGlobal(true); }); @@ -184,10 +203,13 @@ export const AdminSpaceInner = ({ fontSize: '14px', }} > - Reminder: After publishing the key, it will take a couple of minutes for - it to appear. Please just wait. + {t('auth:message.error.publishing_key', { + postProcess: 'capitalizeFirst', + })} + + {isFetchingGroupSecretKey && ( - Fetching Group secret key publishes - )} - {!isFetchingGroupSecretKey && - groupSecretKeyPublishDetails === false && ( - No secret key published yet - )} - {groupSecretKeyPublishDetails && ( - Last encryption date:{' '} - {formatTimestampForum( - groupSecretKeyPublishDetails?.updated || - groupSecretKeyPublishDetails?.created - )}{' '} - {` by ${groupSecretKeyPublishDetails?.name}`} + {t('auth:message.generic.fetching_group_secret_key', { + postProcess: 'capitalizeFirst', + })} )} + + {!isFetchingGroupSecretKey && + groupSecretKeyPublishDetails === false && ( + + {t('auth:message.generic.no_secret_key_published', { + postProcess: 'capitalizeFirst', + })} + + )} + + {groupSecretKeyPublishDetails && ( + + {t('auth:message.generic.last_encryption_date', { + date: formatTimestampForum( + groupSecretKeyPublishDetails?.updated || + groupSecretKeyPublishDetails?.created + ), + name: groupSecretKeyPublishDetails?.name, + postProcess: 'capitalizeFirst', + })} + + )} + @@ -232,9 +269,9 @@ export const AdminSpaceInner = ({ fontSize: '14px', }} > - This key is to encrypt GROUP related content. This is the only one - used in this UI as of now. All group members will be able to see - content encrypted with this key. + {t('auth:tips.key_encrypt_group', { + postProcess: 'capitalizeFirst', + })} @@ -253,26 +290,41 @@ export const AdminSpaceInner = ({ }} > {isFetchingAdminGroupSecretKey && ( - Fetching Admins secret key - )} - {!isFetchingAdminGroupSecretKey && !adminGroupSecretKey && ( - No secret key published yet - )} - {adminGroupSecretKeyPublishDetails && ( - Last encryption date:{' '} - {formatTimestampForum( - adminGroupSecretKeyPublishDetails?.updated || - adminGroupSecretKeyPublishDetails?.created - )} + {t('auth:message.generic.fetching_admin_secret_key', { + postProcess: 'capitalizeFirst', + })} )} + + {!isFetchingAdminGroupSecretKey && !adminGroupSecretKey && ( + + {t('auth:message.generic.no_secret_key_published', { + postProcess: 'capitalizeFirst', + })} + + )} + + {adminGroupSecretKeyPublishDetails && ( + + {t('auth:message.generic.last_encryption_date', { + date: formatTimestampForum( + adminGroupSecretKeyPublishDetails?.updated || + adminGroupSecretKeyPublishDetails?.created + ), + postProcess: 'capitalizeFirst', + })} + + )} + @@ -282,11 +334,14 @@ export const AdminSpaceInner = ({ fontSize: '14px', }} > - This key is to encrypt ADMIN related content. Only admins would see - content encrypted with it. + {t('auth:tips.key_encrypt_admin', { + postProcess: 'capitalizeFirst', + })} + + {isOwner && ( - Group Avatar + + {t('group:group.avatar', { + postProcess: 'capitalizeFirst', + })} + { const threads = doInitWorkers(crypto.kdfThreads); @@ -18,7 +19,7 @@ export const decryptStoredWallet = async (password, wallet) => { .process(encryptedSeedBytes) .finish().result; if (Base58.encode(mac) !== wallet.mac) { - throw new Error('Incorrect password'); + throw new Error(i18n.t('auth:message.error.incorrect_password')); // TODO: i18n non-react integration } const decryptedBytes = AES_CBC.decrypt( encryptedSeedBytes,