Skip to content

Commit

Permalink
v3.0.33
Browse files Browse the repository at this point in the history
  • Loading branch information
mytonwalletorg committed Nov 4, 2024
1 parent 17f6605 commit aefd361
Show file tree
Hide file tree
Showing 38 changed files with 459 additions and 99 deletions.
1 change: 1 addition & 0 deletions changelogs/3.0.33.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Bug fixes and performance improvements
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mytonwallet",
"version": "3.0.32",
"version": "3.0.33",
"description": "The most feature-rich web wallet and browser extension for TON – with support of multi-accounts, tokens (jettons), NFT, TON DNS, TON Sites, TON Proxy, and TON Magic.",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion public/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.32
3.0.33
8 changes: 4 additions & 4 deletions src/api/chains/ton/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { callBackendGet } from '../../common/backend';
import { getAccountCache, getStakingCommonCache, updateAccountCache } from '../../common/cache';
import { getClientId } from '../../common/other';
import { isKnownStakingPool } from '../../common/utils';
import { apiDb } from '../../db';
import { nftRepository } from '../../db';
import { getEnvironment } from '../../environment';
import { STAKE_COMMENT, UNSTAKE_COMMENT } from './constants';
import { checkTransactionDraft, submitTransfer } from './transactions';
Expand Down Expand Up @@ -254,12 +254,12 @@ export async function getStakingState(
let unstakeAmount = 0n;

if (collection) {
const nfts = await apiDb.nfts.where({
const nfts = await nftRepository.find({
accountId,
collectionAddress: collection,
}).toArray();
});

for (const nft of nfts) {
for (const nft of nfts ?? []) {
const billAmount = nft.name?.match(/Bill for (?<amount>[\d.]+) Pool Jetton/)?.groups?.amount;
if (billAmount) {
unstakeAmount += fromDecimal(billAmount);
Expand Down
7 changes: 5 additions & 2 deletions src/api/chains/ton/util/sendExternal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,14 @@ export async function sendExternal(
.store(storeMessage(ext))
.endCell();

const isW5Gasless = gaslessType === 'w5';

const msgHash = cell.hash().toString('base64');
const bodyMessageHash = message.hash().toString('base64');
const boc = cell.toBoc().toString('base64');

let paymentLink;
if (gaslessType === 'w5') {
if (isW5Gasless) {
const result = await dieselW5SendRequest(boc);
paymentLink = result.paymentLink;
} else if (gaslessType === 'diesel') {
Expand All @@ -53,7 +56,7 @@ export async function sendExternal(

return {
boc,
msgHash,
msgHash: isW5Gasless ? bodyMessageHash : msgHash,
paymentLink,
};
}
12 changes: 6 additions & 6 deletions src/api/common/nft.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import type { ApiNft, ApiUpdate, OnApiUpdate } from '../types';

import { apiDb, type ApiDbNft } from '../db';
import { type ApiDbNft, nftRepository } from '../db';

export async function processNftUpdates(accountId: string, updates: ApiUpdate[], onUpdate: OnApiUpdate) {
updates.filter((update) => !(update.type === 'nftReceived' && update.nft.isHidden)).forEach(onUpdate);

for (const update of updates) {
if (update.type === 'nftSent') {
const key = [accountId, update.nftAddress];
await apiDb.nfts.delete(key);
await nftRepository.delete(key);
} else if (update.type === 'nftReceived') {
const dbNft = convertToDbEntity(accountId, update.nft);
await apiDb.nfts.put(dbNft);
await nftRepository.put(dbNft);
} else if (update.type === 'nftPutUpForSale') {
const key = [accountId, update.nftAddress];
await apiDb.nfts.update(key, { isOnSale: true });
await nftRepository.update(key, { isOnSale: true });
}
}
}
Expand All @@ -28,8 +28,8 @@ export async function updateAccountNfts(accountId: string, nfts: ApiNft[], onUpd

const dbNfts = nfts.map((nft) => convertToDbEntity(accountId, nft));

await apiDb.nfts.where({ accountId }).delete();
await apiDb.nfts.bulkPut(dbNfts);
await nftRepository.deleteWhere({ accountId });
await nftRepository.bulkPut(dbNfts);
}

function convertToDbEntity(accountId: string, nft: ApiNft): ApiDbNft {
Expand Down
6 changes: 3 additions & 3 deletions src/api/common/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import type {
} from '../types';

import { TOKEN_INFO } from '../../config';
import { apiDb } from '../db';
import { tokenRepository } from '../db';
import { getPricesCache } from './cache';

const tokensCache = {
...TOKEN_INFO,
} as Record<string, ApiToken>;

export async function loadTokensCache() {
const tokens = await apiDb.tokens.toArray();
const tokens = await tokenRepository.all();
return addTokens(tokens);
}

Expand All @@ -25,7 +25,7 @@ export async function addTokens(tokens: ApiToken[], onUpdate?: OnApiUpdate, shou
tokensCache[token.slug] = token;
}

await apiDb.tokens.bulkPut(tokens);
await tokenRepository.bulkPut(tokens);

if ((shouldForceSend || newTokens.length) && onUpdate) {
sendUpdateTokens(onUpdate);
Expand Down
7 changes: 6 additions & 1 deletion src/api/db.ts → src/api/db/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type { Table } from 'dexie';
import Dexie from 'dexie';

import type { ApiNft, ApiToken } from './types';
import type { ApiNft, ApiToken } from '../types';

import { DbRepository } from './repository';

export type ApiDbNft = ApiNft & {
accountId: string;
Expand Down Expand Up @@ -34,3 +36,6 @@ export class ApiDb extends Dexie {
}

export const apiDb = new ApiDb();

export const nftRepository = new DbRepository(apiDb.nfts);
export const tokenRepository = new DbRepository(apiDb.tokens);
70 changes: 70 additions & 0 deletions src/api/db/repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import type { Table, UpdateSpec } from 'dexie';

const IGNORED_DEXIE_ERRORS = new Set(['AbortError', 'BulkError', 'UnknownError']);

async function tryDbQuery<T>(cb: () => Promise<T>) {
try {
return await cb();
} catch (error: any) {
if (IGNORED_DEXIE_ERRORS.has(error?.name)) return undefined;
else throw error;
}
}

export class DbRepository<T> {
table: Table<T>;

constructor(table: Table<T>) {
this.table = table;
}

all() {
return this.table.toArray();
}

find(where: {
[key: string]: any;
}) {
return tryDbQuery(() => {
return this.table.where(where).toArray();
});
}

put(item: T) {
return tryDbQuery(() => {
return this.table.put(item);
});
}

bulkPut(items: T[]) {
return tryDbQuery(() => {
return this.table.bulkPut(items);
});
}

update(key: string[], update: UpdateSpec<T>) {
return tryDbQuery(() => {
return this.table.update(key, update);
});
}

delete(key: string[]) {
return tryDbQuery(() => {
return this.table.delete(key);
});
}

deleteWhere(where: {
[key: string]: any;
}) {
return tryDbQuery(() => {
return this.table.where(where).delete();
});
}

clear() {
return tryDbQuery(() => {
return this.table.clear();
});
}
}
6 changes: 3 additions & 3 deletions src/api/methods/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
import {
decryptMnemonic, encryptMnemonic, generateBip39Mnemonic, validateBip39Mnemonic,
} from '../common/mnemonic';
import { apiDb } from '../db';
import { nftRepository } from '../db';
import { getEnvironment } from '../environment';
import { handleServerError } from '../errors';
import { storage } from '../storages';
Expand Down Expand Up @@ -177,15 +177,15 @@ export async function resetAccounts() {
storage.removeItem('accounts'),
storage.removeItem('currentAccountId'),
getEnvironment().isDappSupported && removeAllDapps(),
apiDb.nfts.clear(),
nftRepository.clear(),
]);
}

export async function removeAccount(accountId: string, nextAccountId: string, newestTxTimestamps?: ApiTxTimestamps) {
await Promise.all([
removeAccountValue(accountId, 'accounts'),
getEnvironment().isDappSupported && removeAccountDapps(accountId),
apiDb.nfts.where({ accountId }).delete(),
nftRepository.deleteWhere({ accountId }),
]);

deactivateCurrentAccount();
Expand Down
13 changes: 7 additions & 6 deletions src/api/methods/other.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import nacl from 'tweetnacl';

import type { Theme } from '../../global/types';
import type { AccountCache } from '../common/cache';
import type { StorageKey } from '../storages/types';
import type { ApiChain, ApiNetwork } from '../types';

import { logDebugError } from '../../util/logs';
import { getLogs, logDebugError } from '../../util/logs';
import { setIsAppFocused } from '../../util/pauseOrFocus';
import chains from '../chains';
import { fetchStoredAccounts, fetchStoredTonWallet, updateStoredAccount } from '../common/accounts';
Expand Down Expand Up @@ -46,15 +47,15 @@ export async function getBackendAuthToken(accountId: string, password: string) {

export async function fetchAccountConfigForDebugPurposesOnly() {
try {
const [accounts, stateVersion] = await Promise.all([
const [accounts, stateVersion, mnemonicsEncrypted] = await Promise.all([
fetchStoredAccounts(),
storage.getItem('stateVersion'),
storage.getItem('mnemonicsEncrypted' as StorageKey),
]);

return JSON.stringify({ accounts, stateVersion });
return JSON.stringify({ accounts, stateVersion, mnemonicsEncrypted });
} catch (err) {
// eslint-disable-next-line no-console
console.error(err);
logDebugError('fetchAccountConfigForDebugPurposesOnly', err);

return undefined;
}
Expand All @@ -68,7 +69,7 @@ export function updateAccountMemoryCache(accountId: string, address: string, par
updateAccountCache(accountId, address, partial);
}

export { setIsAppFocused };
export { setIsAppFocused, getLogs };

export async function getMoonpayOnrampUrl(address: string, theme: Theme) {
try {
Expand Down
3 changes: 1 addition & 2 deletions src/api/providers/worker/connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ async function ensureWorkerPing() {
.then(() => (isResolved ? undefined : Promise.reject(new Error('HEALTH_CHECK_TIMEOUT')))),
]);
} catch (err) {
// eslint-disable-next-line no-console
console.error(err);
logDebugError('ensureWorkerPing', err);

if (Date.now() - startedAt >= HEALTH_CHECK_MIN_DELAY) {
worker?.terminate();
Expand Down
9 changes: 7 additions & 2 deletions src/components/main/sections/Card/Card.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@
.icon {
font-size: 1rem;
vertical-align: -0.1875rem;

&:global(.icon-ledger) {
margin-inline-end: 0.25rem;
}
}

.menuItem {
Expand Down Expand Up @@ -367,13 +371,13 @@
}

.tokenName {
display: block;
display: flex;

margin-top: 0.25rem;

font-size: 0.8125rem;
font-weight: 500;
line-height: 1;
line-height: 0.9375rem;
color: var(--color-card-second-text);
}

Expand Down Expand Up @@ -427,6 +431,7 @@

font-size: 0.625rem;
font-weight: 700;
line-height: 1;
color: var(--color-card-apy-text);

background-color: var(--color-card-apy-background);
Expand Down
7 changes: 5 additions & 2 deletions src/components/main/sections/Card/CardAddress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ import styles from './Card.module.scss';
interface StateProps {
addressByChain?: Account['addressByChain'];
isTestnet?: boolean;
isHardwareAccount?: boolean;
}

function CardAddress({ addressByChain, isTestnet }: StateProps) {
function CardAddress({ addressByChain, isTestnet, isHardwareAccount }: StateProps) {
const { showNotification } = getActions();

const lang = useLang();
Expand Down Expand Up @@ -143,6 +144,7 @@ function CardAddress({ addressByChain, isTestnet }: StateProps) {
aria-label={lang('Copy wallet address')}
onClick={() => handleCopyAddress(addressByChain![chain])}
>
{isHardwareAccount && <i className={buildClassName(styles.icon, 'icon-ledger')} aria-hidden />}
{shortenAddress(addressByChain![chain])}
<i className={buildClassName(styles.icon, 'icon-copy')} aria-hidden />
</button>
Expand All @@ -161,10 +163,11 @@ function CardAddress({ addressByChain, isTestnet }: StateProps) {
}

export default memo(withGlobal((global): StateProps => {
const { addressByChain } = selectAccount(global, global.currentAccountId!) || {};
const { addressByChain, isHardware } = selectAccount(global, global.currentAccountId!) || {};

return {
addressByChain,
isTestnet: global.settings.isTestnet,
isHardwareAccount: isHardware,
};
})(CardAddress));
Loading

0 comments on commit aefd361

Please sign in to comment.