Полностью поддерживает английский язык

This commit is contained in:
AidarKC
2026-11-10 14:02:34 +03:00
parent 405b9a91a7
commit 9c30b33b39
71 changed files with 2658 additions and 1445 deletions
+11 -9
View File
@@ -1,3 +1,5 @@
import { t } from '../i18n/index.js';
import { formatNumber } from '../i18n/format.js';
import { getBalanceSol, getStoredSolanaWalletChoices, encodeSolanaSecretKeyBase58, formatSol } from './solana-wallet-service.js';
import { state } from '../state.js';
@@ -10,17 +12,17 @@ function parseSolToLamports(amountSol) {
const raw = String(amountSol ?? '').trim().replace(',', '.');
const match = raw.match(/^(\d+)(?:\.(\d+))?$/);
if (!match) {
throw new Error('Сумма пополнения должна быть числом');
throw new Error(t('remaining.turbo.top_up_amount_must_be_a_number'));
}
const intPart = BigInt(match[1] || '0');
const frac = String(match[2] || '');
if (frac.length > 9) {
throw new Error('Слишком много знаков после запятой для SOL');
throw new Error(t('remaining.turbo.too_many_decimal_places_for_sol'));
}
const fracPadded = `${frac}${'0'.repeat(9 - frac.length)}`;
const lamports = (intPart * 1_000_000_000n) + BigInt(fracPadded || '0');
if (lamports <= 0n) {
throw new Error('Сумма пополнения должна быть больше 0');
throw new Error(t('remaining.turbo.top_up_amount_must_be_greater_than_zero'));
}
return lamports.toString();
}
@@ -41,7 +43,7 @@ async function getTurboWalletChoice({ login, storagePwd, keySource = 'blockchain
const choices = await getStoredSolanaWalletChoices({ login, storagePwd });
const selected = choices.find((item) => item.keySource === normalizedKeySource) || choices[0] || null;
if (!selected?.keypair) {
throw new Error('На устройстве не найден blockchain key для Turbo.');
throw new Error(t('remaining.turbo.blockchain_key_for_turbo_not_found_on_this_device'));
}
return selected;
}
@@ -50,7 +52,7 @@ async function createTurboClientFromWalletChoice(choice) {
const moduleRef = await loadTurboLib();
const TurboFactory = moduleRef?.TurboFactory;
if (!TurboFactory?.authenticated) {
throw new Error('Turbo SDK не удалось инициализировать.');
throw new Error(t('remaining.turbo.could_not_initialize_turbo_sdk'));
}
const privateKey = await encodeSolanaSecretKeyBase58(choice.keypair.secretKey);
return TurboFactory.authenticated({
@@ -82,7 +84,7 @@ export function getFreeTurboUploadBytesLimit() {
export function formatTurboCredits(value, digits = 6) {
const n = Number(value);
if (!Number.isFinite(n)) return '0';
return n.toLocaleString('ru-RU', {
return formatNumber(n, {
minimumFractionDigits: 0,
maximumFractionDigits: digits,
});
@@ -124,13 +126,13 @@ export async function getTurboBalanceForStoredSolanaKey({ login, storagePwd, key
export async function estimateTurboUploadPrice({ login, storagePwd, keySource = 'blockchain', byteLength } = {}) {
const bytes = Number(byteLength);
if (!Number.isInteger(bytes) || bytes <= 0) {
throw new Error('Некорректный размер файла для Turbo.');
throw new Error(t('remaining.turbo.invalid_file_size_for_turbo'));
}
const ctx = await getTurboContextForStoredSolanaKey({ login, storagePwd, keySource });
const rows = await ctx.turbo.getUploadCosts({ bytes: [bytes] });
const price = Array.isArray(rows) ? rows[0] : null;
if (!price) {
throw new Error('Turbo не вернул цену загрузки.');
throw new Error(t('remaining.turbo.turbo_did_not_return_an_upload_price'));
}
const winc = String(price.winc || '0');
return {
@@ -152,7 +154,7 @@ export async function uploadFileWithTurbo({
onProgress,
} = {}) {
if (!(file instanceof File)) {
throw new Error('Выберите файл для загрузки через Turbo.');
throw new Error(t('remaining.turbo.select_a_file_to_upload_through_turbo'));
}
const ctx = await getTurboContextForStoredSolanaKey({ login, storagePwd, keySource });
const result = await ctx.turbo.uploadFile({