Skip to content

Commit

Permalink
v1.18.7
Browse files Browse the repository at this point in the history
  • Loading branch information
mytonwalletorg committed Feb 21, 2024
1 parent 2c46f62 commit f6d8934
Show file tree
Hide file tree
Showing 12 changed files with 178 additions and 95 deletions.
1 change: 1 addition & 0 deletions changelogs/1.18.7.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": "1.18.6",
"version": "1.18.7",
"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 @@
1.18.6
1.18.7
20 changes: 16 additions & 4 deletions src/api/blockchains/ton/util/apiV3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ import {
TONHTTPAPI_V3_MAINNET_API_URL,
TONHTTPAPI_V3_TESTNET_API_URL,
} from '../../../../config';
import { split } from '../../../../util/iteratees';
import { fetchJson } from '../../../common/utils';
import { getEnvironment } from '../../../environment';
import { parseTxId, stringifyTxId } from './index';
import { toBase64Address } from './tonCore';

type AddressBook = Record<string, { user_friendly: string }>;

const ADDRESS_BOOK_CHUNK_SIZE = 128;

export async function fetchTransactions(
network: ApiNetwork,
address: string,
Expand Down Expand Up @@ -99,11 +102,20 @@ function getRawBody(msg: any) {
return msg.message_content.body;
}

export function fetchAddressBook(network: ApiNetwork, addresses: string[]): Promise<AddressBook> {
return callApiV3(network, '/addressBook', {
address: addresses,
});
export async function fetchAddressBook(network: ApiNetwork, addresses: string[]): Promise<AddressBook> {
const chunks = split(addresses, ADDRESS_BOOK_CHUNK_SIZE);

const results = await Promise.all(chunks.map((chunk) => {
return callApiV3(network, '/addressBook', {
address: chunk,
});
}));

return results.reduce((acc, value) => {
return Object.assign(acc, value);
}, {} as AddressBook);
}

function callApiV3(network: ApiNetwork, path: string, data?: AnyLiteral) {
const { apiHeaders, tonhttpapiMainnetKey, tonhttpapiTestnetKey } = getEnvironment();
const baseUrl = network === 'testnet' ? TONHTTPAPI_V3_TESTNET_API_URL : TONHTTPAPI_V3_MAINNET_API_URL;
Expand Down
27 changes: 11 additions & 16 deletions src/api/methods/polling.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { TokenBalanceParsed } from '../blockchains/ton/tokens';
import type {
ApiActivity,
ApiBackendStakingState,
ApiBalanceBySlug,
ApiBaseCurrency,
Expand Down Expand Up @@ -35,7 +34,7 @@ import { processNftUpdates, updateNfts } from './nfts';
import { getBaseCurrency } from './prices';
import { getBackendStakingState, getStakingCommonData, tryUpdateStakingCommonData } from './staking';
import {
swapGetAssets, swapGetHistory, swapItemToActivity, swapReplaceTransactions,
swapGetAssets, swapGetHistory, swapItemToActivity, swapReplaceTransactionsByRanges,
} from './swap';

type IsAccountActiveFn = (accountId: string) => boolean;
Expand Down Expand Up @@ -295,9 +294,7 @@ async function processNewActivities(
const { network, blockchain } = parseAccountId(accountId);
const activeBlockchain = blockchains[blockchain];

let allTransactions: ApiTransactionActivity[] = [];
let allActivities: ApiActivity[] = [];

const chunks: ApiTransactionActivity[][] = [];
const result: [string, string | undefined][] = [];

// Process TON transactions first
Expand All @@ -308,13 +305,10 @@ async function processNewActivities(
const transactions = await activeBlockchain.getTokenTransactionSlice(
accountId, slug, undefined, newestTxId, FIRST_TRANSACTIONS_LIMIT,
);
const activities = await swapReplaceTransactions(accountId, transactions, network, slug);

if (transactions.length) {
newestTxId = transactions[0]!.txId;

allActivities = allActivities.concat(activities);
allTransactions = allTransactions.concat(transactions);
chunks.push(transactions);
}

result.push([slug, newestTxId]);
Expand All @@ -331,35 +325,36 @@ async function processNewActivities(
});
}

// Process token transactions
await Promise.all(tokenSlugs.map(async (slug) => {
let newestTxId = newestTxIds[slug];

const transactions = await activeBlockchain.getTokenTransactionSlice(
accountId, slug, undefined, newestTxId, FIRST_TRANSACTIONS_LIMIT,
);
const activities = await swapReplaceTransactions(accountId, transactions, network, slug);

if (transactions.length) {
newestTxId = transactions[0]!.txId;

allActivities = allActivities.concat(activities);
allTransactions = allTransactions.concat(transactions);
chunks.push(transactions);
}

result.push([slug, newestTxId]);
}));

allTransactions.sort((a, b) => compareActivities(a, b, true));
const allTransactions = chunks.flat().sort((a, b) => compareActivities(a, b));
const isFirstRun = !Object.keys(newestTxIds).length;
const activities = await swapReplaceTransactionsByRanges(accountId, allTransactions, chunks, isFirstRun);

allTransactions.sort((a, b) => compareActivities(a, b, true));
allTransactions.forEach((transaction) => {
txCallbacks.runCallbacks(transaction);
});

await activeBlockchain.fixTokenActivitiesAddressForm(network, allActivities);
await activeBlockchain.fixTokenActivitiesAddressForm(network, activities);

onUpdate({
type: 'newActivities',
activities: allActivities,
activities,
accountId,
});

Expand Down
Loading

0 comments on commit f6d8934

Please sign in to comment.