Skip to content

Commit

Permalink
v1.17.8
Browse files Browse the repository at this point in the history
  • Loading branch information
mytonwalletorg committed Dec 27, 2023
1 parent 4d2a7be commit 3349a64
Show file tree
Hide file tree
Showing 32 changed files with 289 additions and 154 deletions.
1 change: 1 addition & 0 deletions changelogs/1.17.8.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Bug fixes
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.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mytonwallet",
"version": "1.17.7",
"version": "1.17.8",
"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 All @@ -18,9 +18,9 @@
"extension-opera:package": "cross-env IS_OPERA_EXTENSION=1 IS_EXTENSION=1 webpack && bash ./deploy/package_extension.sh opera",
"extension-opera:package:staging": "cross-env APP_ENV=staging npm run extension-opera:package",
"extension-opera:package:production": "npm run extension-opera:package",
"electron:dev": "npm run electron:webpack && IS_ELECTRON_BUILD=1 concurrently -n main,renderer,electron \"npm run electron:webpack -- --watch\" \"npm run dev\" \"electronmon dist/electron\"",
"electron:dev": "npm run electron:webpack && IS_PACKAGED_ELECTRON=1 concurrently -n main,renderer,electron \"npm run electron:webpack -- --watch\" \"npm run dev\" \"electronmon dist/electron\"",
"electron:webpack": "cross-env APP_ENV=$ENV webpack --config ./webpack-electron.config.ts",
"electron:build": "IS_ELECTRON_BUILD=1 npm run build:$ENV && electron-builder install-app-deps && electron-rebuild && ENV=$ENV npm run electron:webpack",
"electron:build": "IS_PACKAGED_ELECTRON=1 npm run build:$ENV && electron-builder install-app-deps && electron-rebuild && ENV=$ENV npm run electron:webpack",
"electron:package": "npm run electron:build && npx rimraf dist-electron && electron-builder build --win --mac --linux --config src/electron/config.yml",
"electron:package:staging": "ENV=staging npm run electron:package -- -p never",
"electron:release:production": "ENV=production npm run electron:package -- -p always",
Expand Down
2 changes: 1 addition & 1 deletion public/electronVersion.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.17.4
1.17.8
2 changes: 1 addition & 1 deletion public/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.17.7
1.17.8
14 changes: 10 additions & 4 deletions src/api/blockchains/ton/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export type TokenBalanceParsed = {
slug: string;
balance: string;
token: ApiTokenSimple;
} | undefined;
jettonWallet: string;
};

const KNOWN_TOKENS: ApiBaseToken[] = [
{
Expand All @@ -61,17 +62,22 @@ export async function getAccountTokenBalances(accountId: string) {
return balancesRaw.map(parseTokenBalance).filter(Boolean);
}

function parseTokenBalance(balanceRaw: JettonBalance): TokenBalanceParsed {
function parseTokenBalance(balanceRaw: JettonBalance): TokenBalanceParsed | undefined {
if (!balanceRaw.jetton) {
return undefined;
}

try {
const { balance, jetton } = balanceRaw;
const { balance, jetton, walletAddress } = balanceRaw;
const minterAddress = toBase64Address(jetton.address, true);
const token = buildTokenByMetadata(minterAddress, jetton);

return { slug: token.slug, balance, token };
return {
slug: token.slug,
balance,
token,
jettonWallet: toBase64Address(walletAddress.address),
};
} catch (err) {
logDebugError('parseTokenBalance', err);
return undefined;
Expand Down
2 changes: 1 addition & 1 deletion src/api/blockchains/ton/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ type SubmitMultiTransferResult = {

const { Address, fromNano } = TonWeb.utils;

const DEFAULT_FEE = '10966001';
const DEFAULT_FEE = '15000000';
const DEFAULT_EXPIRE_AT_TIMEOUT_SEC = 60; // 60 sec.
const GET_TRANSACTIONS_LIMIT = 50;
const GET_TRANSACTIONS_MAX_LIMIT = 100;
Expand Down
66 changes: 39 additions & 27 deletions src/api/blockchains/ton/util/tonapiio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,55 @@ import type { ApiNetwork } from '../../../types';

import { TONAPIIO_MAINNET_URL, TONAPIIO_TESTNET_URL } from '../../../../config';
import { logDebugError } from '../../../../util/logs';
import { API_HEADERS } from '../../../environment';
import { getEnvironment } from '../../../environment';

const MAX_LIMIT = 1000;

const configurationMainnet = new Configuration({
basePath: TONAPIIO_MAINNET_URL,
headers: API_HEADERS,
});
const configurationTestnet = new Configuration({
basePath: TONAPIIO_TESTNET_URL,
headers: API_HEADERS,
});
let apiByNetwork: Record<ApiNetwork, {
blockchainApi: BlockchainApi;
nftApi: NFTApi;
accountsApi: AccountsApi;
}> | undefined;

export const tonapiioByNetwork = {
mainnet: {
configuration: configurationMainnet,
blockchainApi: new BlockchainApi(configurationMainnet),
nftApi: new NFTApi(configurationMainnet),
accountsApi: new AccountsApi(configurationMainnet),
},
testnet: {
configuration: configurationTestnet,
blockchainApi: new BlockchainApi(configurationTestnet),
nftApi: new NFTApi(configurationTestnet),
accountsApi: new AccountsApi(configurationTestnet),
},
};
function getApi(network: ApiNetwork) {
if (!apiByNetwork) {
const headers = getEnvironment().apiHeaders;

const configurationMainnet = new Configuration({
basePath: TONAPIIO_MAINNET_URL,
...(headers && { headers }),
});
const configurationTestnet = new Configuration({
basePath: TONAPIIO_TESTNET_URL,
...(headers && { headers }),
});

apiByNetwork = {
mainnet: {
blockchainApi: new BlockchainApi(configurationMainnet),
nftApi: new NFTApi(configurationMainnet),
accountsApi: new AccountsApi(configurationMainnet),
},
testnet: {
blockchainApi: new BlockchainApi(configurationTestnet),
nftApi: new NFTApi(configurationTestnet),
accountsApi: new AccountsApi(configurationTestnet),
},
};
}

return apiByNetwork[network];
}

export function fetchJettonBalances(network: ApiNetwork, account: string) {
const api = tonapiioByNetwork[network].accountsApi;
const api = getApi(network).accountsApi;
return tonapiioErrorHandler(async () => {
return (await api.getJettonsBalances({ accountId: account })).balances;
}, []);
}

export function fetchNftItems(network: ApiNetwork, addresses: string[]) {
const api = tonapiioByNetwork[network].nftApi;
const api = getApi(network).nftApi;
return tonapiioErrorHandler(async () => (await api.getNftItemsByAddresses({
getAccountsRequest: { accountIds: addresses },
})).nftItems, []);
Expand All @@ -58,7 +70,7 @@ export function fetchAccountNfts(network: ApiNetwork, address: string, options?:
limit?: number;
}) {
const { collection, offset, limit } = options ?? {};
const api = tonapiioByNetwork[network].accountsApi;
const api = getApi(network).accountsApi;

return tonapiioErrorHandler(async () => (await api.getNftItemsByOwner({
accountId: address,
Expand All @@ -70,7 +82,7 @@ export function fetchAccountNfts(network: ApiNetwork, address: string, options?:
}

export function fetchAccountEvents(network: ApiNetwork, address: string, fromSec: number, limit?: number) {
const api = tonapiioByNetwork[network].accountsApi;
const api = getApi(network).accountsApi;
return tonapiioErrorHandler(async () => (await api.getEventsByAccount({
accountId: address,
limit: limit ?? MAX_LIMIT,
Expand Down
28 changes: 16 additions & 12 deletions src/api/blockchains/ton/util/tonweb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
import { logDebugError } from '../../../../util/logs';
import withCacheAsync from '../../../../util/withCacheAsync';
import { base64ToBytes, fetchJson, hexToBytes } from '../../../common/utils';
import { API_HEADERS } from '../../../environment';
import { getEnvironment } from '../../../environment';
import {
DEFAULT_IS_BOUNCEABLE,
JettonOpCode,
Expand All @@ -37,16 +37,7 @@ export const { toNano, fromNano } = TonWeb.utils;

const TON_MAX_COMMENT_BYTES = 127;

const tonwebByNetwork = {
mainnet: new TonWeb(new CustomHttpProvider(TONHTTPAPI_MAINNET_URL, {
apiKey: TONHTTPAPI_MAINNET_API_KEY,
headers: API_HEADERS,
})) as MyTonWeb,
testnet: new TonWeb(new CustomHttpProvider(TONHTTPAPI_TESTNET_URL, {
apiKey: TONHTTPAPI_TESTNET_API_KEY,
headers: API_HEADERS,
})) as MyTonWeb,
};
let tonwebByNetwork: Record<ApiNetwork, MyTonWeb> | undefined;

export const resolveTokenWalletAddress = withCacheAsync(
async (network: ApiNetwork, address: string, minterAddress: string) => {
Expand Down Expand Up @@ -118,7 +109,7 @@ export async function fetchTransactions(
}, {
headers: {
...(apiKey && { 'X-Api-Key': apiKey }),
...API_HEADERS,
...getEnvironment().apiHeaders,
},
});

Expand Down Expand Up @@ -180,6 +171,19 @@ function getRawBody(msg: any) {
}

export function getTonWeb(network: ApiNetwork = 'mainnet') {
if (!tonwebByNetwork) {
tonwebByNetwork = {
mainnet: new TonWeb(new CustomHttpProvider(TONHTTPAPI_MAINNET_URL, {
apiKey: TONHTTPAPI_MAINNET_API_KEY,
headers: getEnvironment().apiHeaders,
})) as MyTonWeb,
testnet: new TonWeb(new CustomHttpProvider(TONHTTPAPI_TESTNET_URL, {
apiKey: TONHTTPAPI_TESTNET_API_KEY,
headers: getEnvironment().apiHeaders,
})) as MyTonWeb,
};
}

return tonwebByNetwork[network];
}

Expand Down
45 changes: 38 additions & 7 deletions src/api/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,44 @@
* This module is to be used instead of /src/util/environment.ts
* when `window` is not available (e.g. in a web worker).
*/
import { APP_ENV, IS_ELECTRON_BUILD, IS_EXTENSION } from '../config';
import type { ApiInitArgs } from './types';

// eslint-disable-next-line no-restricted-globals
export const IS_CHROME_EXTENSION = Boolean(self?.chrome?.system);
import {
APP_ENV,
ELECTRON_TONHTTPAPI_MAINNET_API_KEY,
ELECTRON_TONHTTPAPI_TESTNET_API_KEY,
IS_CAPACITOR,
IS_EXTENSION,
TONHTTPAPI_MAINNET_API_KEY,
TONHTTPAPI_TESTNET_API_KEY,
} from '../config';

// eslint-disable-next-line no-restricted-globals
export const X_APP_ORIGIN = self.origin;
export const API_HEADERS = IS_EXTENSION || (IS_ELECTRON_BUILD && APP_ENV !== 'development')
? { 'X-App-Origin': X_APP_ORIGIN }
: undefined;
export const X_APP_ORIGIN = self?.origin;

let environment: ApiInitArgs & {
isDappSupported: boolean;
isSseSupported: boolean;
apiHeaders?: AnyLiteral;
tonhttpapiMainnetKey?: string;
tonhttpapiTestnetKey?: string;
};

export function setEnvironment(args: ApiInitArgs) {
environment = {
...args,
isDappSupported: IS_EXTENSION || IS_CAPACITOR || args.isElectron,
isSseSupported: args.isElectron || IS_CAPACITOR,
apiHeaders: IS_EXTENSION || (args.isElectron && APP_ENV !== 'development')
// eslint-disable-next-line no-restricted-globals
? { 'X-App-Origin': X_APP_ORIGIN }
: undefined,
tonhttpapiMainnetKey: args.isElectron ? ELECTRON_TONHTTPAPI_MAINNET_API_KEY : TONHTTPAPI_MAINNET_API_KEY,
tonhttpapiTestnetKey: args.isElectron ? ELECTRON_TONHTTPAPI_TESTNET_API_KEY : TONHTTPAPI_TESTNET_API_KEY,
};
return environment;
}

export function getEnvironment() {
return environment;
}
8 changes: 4 additions & 4 deletions src/api/methods/auth.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { LedgerWalletInfo } from '../../util/ledger/types';
import type { ApiAccount, ApiNetwork, ApiTxIdBySlug } from '../types';

import { IS_DAPP_SUPPORTED } from '../../config';
import blockchains from '../blockchains';
import { toBase64Address } from '../blockchains/ton/util/tonweb';
import {
Expand All @@ -13,6 +12,7 @@ import {
} from '../common/accounts';
import { bytesToHex } from '../common/utils';
import { apiDb } from '../db';
import { getEnvironment } from '../environment';
import { handleServerError } from '../errors';
import { storage } from '../storages';
import { activateAccount, deactivateAllAccounts, deactivateCurrentAccount } from './accounts';
Expand Down Expand Up @@ -131,7 +131,7 @@ export async function removeNetworkAccounts(network: ApiNetwork) {
await Promise.all([
removeNetworkAccountsValue(network, 'mnemonicsEncrypted'),
removeNetworkAccountsValue(network, 'accounts'),
IS_DAPP_SUPPORTED && removeNetworkDapps(network),
getEnvironment().isDappSupported && removeNetworkDapps(network),
]);
}

Expand All @@ -142,7 +142,7 @@ export async function resetAccounts() {
storage.removeItem('mnemonicsEncrypted'),
storage.removeItem('accounts'),
storage.removeItem('currentAccountId'),
IS_DAPP_SUPPORTED && removeAllDapps(),
getEnvironment().isDappSupported && removeAllDapps(),
apiDb.nfts.clear(),
]);
}
Expand All @@ -151,7 +151,7 @@ export async function removeAccount(accountId: string, nextAccountId: string, ne
await Promise.all([
removeAccountValue(accountId, 'mnemonicsEncrypted'),
removeAccountValue(accountId, 'accounts'),
IS_DAPP_SUPPORTED && removeAccountDapps(accountId),
getEnvironment().isDappSupported && removeAccountDapps(accountId),
apiDb.nfts.where({ accountId }).delete(),
]);

Expand Down
7 changes: 4 additions & 3 deletions src/api/methods/init.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ApiInitArgs, OnApiUpdate } from '../types';

import { IS_DAPP_SUPPORTED, IS_SSE_SUPPORTED } from '../../config';
import { connectUpdater, startStorageMigration } from '../common/helpers';
import { setEnvironment } from '../environment';
import { addHooks } from '../hooks';
import * as tonConnect from '../tonConnect';
import { resetupSseConnection, sendSseDisconnect } from '../tonConnect/sse';
Expand All @@ -16,21 +16,22 @@ addHooks({
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export default async function init(onUpdate: OnApiUpdate, args: ApiInitArgs) {
connectUpdater(onUpdate);
const environment = setEnvironment(args);

methods.initPolling(onUpdate, methods.isAccountActive);
methods.initTransactions(onUpdate);
methods.initStaking();
methods.initSwap(onUpdate);
methods.initNfts(onUpdate);

if (IS_DAPP_SUPPORTED) {
if (environment.isDappSupported) {
methods.initDapps(onUpdate);
tonConnect.initTonConnect(onUpdate);
}

await startStorageMigration(onUpdate);

if (IS_SSE_SUPPORTED) {
if (environment.isSseSupported) {
void resetupSseConnection();
}
}
Loading

0 comments on commit 3349a64

Please sign in to comment.