Skip to content

Commit

Permalink
v1.16.1
Browse files Browse the repository at this point in the history
  • Loading branch information
mytonwalletorg committed Sep 28, 2023
1 parent 2966b95 commit 23b336a
Show file tree
Hide file tree
Showing 186 changed files with 845 additions and 635 deletions.
19 changes: 15 additions & 4 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -149,39 +149,50 @@
"error",
{
"groups": [
// Side effect imports
["^\\u0000"],
// Lib and global imports
[
"^react",
"^ton",
"^tonweb(/.*|$)",
"^@?\\w",
"dist(/.*|$)",
"^(\\.+/)+(lib)(/.*|$)"
"^(\\.+/)+(lib/teact)(/.*|$)",
"^(\\.+/)+global$"
],
// Type imports
[
"^(\\.+/)+.+\\u0000$",
"^(\\.+/|\\w+/)+(types)(/.*|$)",
"^(\\.+/|\\w+/)+(types)\\u0000"
],
// Config, utils, helpers
[
"^(\\.+/)+config",
"^(\\.+/)+(global)(/.*|$)",
"^(\\.+/)+(lib)(?!/teact)(/.*|$)",
"^(\\.+/)+global/.+",
"^(\\.+/)+(util)(/.*|$)",
"^(\\.+/)+(contracts)(/.*|$)",
"^(\\.+/)+(ui)/[a-z](([a-z]+[A-Z]?)*)",
"^\\.\\.(?!/?$)",
"^\\.\\./?$",
"^\\./(?=.*/)(?!/?$)",
"^\\.(?!/?$)",
"^\\./?$"
],
// Hooks
[
"^(\\.+/)+(hooks)(/.*|$)"
".+(/hooks/)(.*|$)"
],
// Components
[
"\/[A-Z](([a-z]+[A-Z]?)*)"
],
// Styles and CSS modules
[
"^.+\\.s?css$"
],
// Assets: images, stickers, etc
[
"^(\\.+/)+(assets)(/.*|$)"
]
Expand Down
14 changes: 13 additions & 1 deletion .stylelintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@
"letter-spacing"
]
}
]
],
"order/order": [
{
"type": "at-rule",
"name": "import",
"hasBlock": false
}
],
"at-rule-empty-line-before": ["always", {
"ignore": [
"first-nested"
]
}]
}
}
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.16.0",
"version": "1.16.1",
"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
6 changes: 3 additions & 3 deletions src/api/blockchains/ton/staking.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import TonWeb from 'tonweb';
import BN from 'bn.js';

import {
ApiTransactionDraftError,
} from '../../types';
import type {
ApiBackendStakingState,
ApiNetwork,
ApiStakingState,
} from '../../types';
import {
ApiTransactionDraftError,
} from '../../types';

import { TON_TOKEN_SLUG } from '../../../config';
import { parseAccountId } from '../../../util/account';
Expand Down
30 changes: 19 additions & 11 deletions src/api/blockchains/ton/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import TonWeb from 'tonweb';
import type { Cell } from 'tonweb/dist/types/boc/cell';
import type { WalletContract } from 'tonweb/dist/types/contract/wallet/wallet-contract';

import { ApiTransactionDraftError, ApiTransactionError } from '../../types';
import type {
ApiNetwork, ApiSignedTransfer, ApiTransaction, ApiTxIdBySlug,
ApiNetwork, ApiSignedTransfer, ApiTransaction, ApiTransactionActivity, ApiTxIdBySlug,
} from '../../types';
import type { JettonWalletType } from './tokens';
import type { AnyPayload, ApiTransactionExtra, TonTransferParams } from './types';
import { ApiTransactionDraftError, ApiTransactionError } from '../../types';

import { TON_TOKEN_SLUG } from '../../../config';
import { parseAccountId } from '../../../util/account';
import { compareTransactions } from '../../../util/compareTransactions';
import { compareActivities } from '../../../util/compareActivities';
import { omit } from '../../../util/iteratees';
import { isValidLedgerComment } from '../../../util/ledger/utils';
import { logDebugError } from '../../../util/logs';
Expand All @@ -39,7 +40,6 @@ import { bytesToBase64, isKnownStakingPool } from '../../common/utils';
import { resolveAddress } from './address';
import { fetchKeyPair, fetchPrivateKey } from './auth';
import { ATTEMPTS, STAKE_COMMENT, UNSTAKE_COMMENT } from './constants';
import type { JettonWalletType } from './tokens';
import {
buildTokenTransfer, getTokenWalletBalance, parseTokenTransaction, resolveTokenBySlug,
} from './tokens';
Expand Down Expand Up @@ -355,7 +355,8 @@ export async function getAccountTransactionSlice(
return transactions
.map(updateTransactionType)
.map(updateTransactionMetadata)
.map(omitExtraData);
.map(omitExtraData)
.map(transactionToActivity);
}

export async function getMergedTransactionSlice(accountId: string, lastTxIds: ApiTxIdBySlug, limit: number) {
Expand All @@ -379,7 +380,7 @@ export async function getMergedTransactionSlice(accountId: string, lastTxIds: Ap
}));

const allTxs = [...tonTxs, ...results.flat()];
allTxs.sort((a, b) => compareTransactions(a, b, false));
allTxs.sort((a, b) => compareActivities(a, b, false));

return allTxs;
}
Expand All @@ -390,7 +391,7 @@ export async function getTokenTransactionSlice(
fromTxId?: string,
toTxId?: string,
limit?: number,
) {
): Promise<ApiTransactionActivity[]> {
if (tokenSlug === TON_TOKEN_SLUG) {
return getAccountTransactionSlice(accountId, fromTxId, toTxId, limit);
}
Expand All @@ -405,13 +406,12 @@ export async function getTokenTransactionSlice(
network, tokenWalletAddress, limit ?? GET_TRANSACTIONS_LIMIT, fromTxId, toTxId,
);

const parsedTxs = transactions
return transactions
.map((tx) => parseTokenTransaction(tx, tokenSlug, address))
.filter(Boolean)
.map(updateTransactionMetadata)
.map(omitExtraData);

return parsedTxs.filter(Boolean);
.map(omitExtraData)
.map(transactionToActivity);
}

function omitExtraData(tx: ApiTransactionExtra): ApiTransaction {
Expand Down Expand Up @@ -440,6 +440,14 @@ function updateTransactionType(transaction: ApiTransactionExtra) {
return transaction;
}

function transactionToActivity(transaction: ApiTransaction): ApiTransactionActivity {
return {
...transaction,
kind: 'transaction',
id: transaction.txId,
};
}

export async function checkMultiTransactionDraft(accountId: string, messages: TonTransferParams[]) {
const { network } = parseAccountId(accountId);

Expand Down
4 changes: 4 additions & 0 deletions src/api/blockchains/ton/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ export function buildTokenSlug(minterAddress: string) {
const addressPart = minterAddress.replace(/[^a-z\d]/gi, '').slice(0, 10);
return `ton-${addressPart}`.toLowerCase();
}

export function buildSwapId(backendId: string) {
return `swap:${backendId}`;
}
2 changes: 1 addition & 1 deletion src/api/blockchains/ton/util/tonCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
} from 'ton';
import axios from 'axios';

import { WORKCHAIN } from '../../../types';
import type { ApiNetwork, ApiWalletVersion } from '../../../types';
import { WORKCHAIN } from '../../../types';

import { TONHTTPAPI_MAINNET_URL, TONHTTPAPI_TESTNET_URL } from '../../../../config';
import { hexToBytes } from '../../../common/utils';
Expand Down
4 changes: 2 additions & 2 deletions src/api/common/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { mapValues } from '../../util/iteratees';
import { logDebugError } from '../../util/logs';
import { callBackendGet } from './backend';

let knownAddresses: ApiKnownAddresses;
let scamMarkers: RegExp[];
let knownAddresses: ApiKnownAddresses = {};
let scamMarkers: RegExp[] = [];

export async function tryUpdateKnownAddresses() {
try {
Expand Down
18 changes: 14 additions & 4 deletions src/api/common/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import type { ApiTransactionExtra } from '../blockchains/ton/types';
import type { StorageKey } from '../storages/types';
import type {
AccountIdParsed, ApiLocalTransactionParams, ApiTransaction, OnApiUpdate,
AccountIdParsed,
ApiLocalTransactionParams,
ApiTransaction,
ApiTransactionActivity,
OnApiUpdate,
} from '../types';

import { IS_EXTENSION, MAIN_ACCOUNT_ID } from '../../config';
Expand Down Expand Up @@ -34,7 +38,7 @@ export function createLocalTransaction(
onUpdate: OnApiUpdate,
accountId: string,
params: ApiLocalTransactionParams,
onTxComplete?: (transaction: ApiTransaction) => void,
onTxComplete?: (transaction: ApiTransactionActivity) => void,
) {
const { amount, toAddress } = params;

Expand Down Expand Up @@ -64,16 +68,22 @@ export function createLocalTransaction(
return localTransaction;
}

function buildLocalTransaction(params: ApiLocalTransactionParams): ApiTransaction {
function buildLocalTransaction(params: ApiLocalTransactionParams): ApiTransactionActivity {
const { amount, ...restParams } = params;

return updateTransactionMetadata({
const transaction: ApiTransaction = updateTransactionMetadata({
txId: getNextLocalId(),
timestamp: Date.now(),
isIncoming: false,
amount: `-${amount}`,
...restParams,
});

return {
...transaction,
id: transaction.txId,
kind: 'transaction',
};
}

export function updateTransactionMetadata(transaction: ApiTransactionExtra): ApiTransactionExtra {
Expand Down
6 changes: 3 additions & 3 deletions src/api/common/txCallbacks.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { ApiTransaction } from '../types';
import type { ApiTransactionActivity } from '../types';

import { createCallbackManager } from '../../util/callbacks';

export const txCallbacks = createCallbackManager();

export function whenTxComplete(toAddress: string, amount: string) {
return new Promise<{ result: boolean; transaction: ApiTransaction }>((resolve) => {
return new Promise<{ result: boolean; transaction: ApiTransactionActivity }>((resolve) => {
txCallbacks.addCallback(
function callback(transaction: ApiTransaction) {
function callback(transaction: ApiTransactionActivity) {
if (transaction.toAddress === toAddress && transaction.amount === `-${amount}`) {
txCallbacks.removeCallback(callback);
resolve({ result: true, transaction });
Expand Down
3 changes: 1 addition & 2 deletions src/api/extensionMethods/init.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import type { OnApiUpdate } from '../types';

import { addHooks } from '../hooks';
import * as legacyDappMethods from './legacy';
import * as siteMethods from './sites';
import { openPopupWindow } from './window';
import * as extensionMethods from '.';

import { addHooks } from '../hooks';

addHooks({
onWindowNeeded: openPopupWindow,
onFullLogout: extensionMethods.onFullLogout,
Expand Down
2 changes: 1 addition & 1 deletion src/api/extensionMethods/legacy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { OnApiSiteUpdate } from '../types/dappUpdates';
import type { ApiSignedTransfer, OnApiUpdate } from '../types';
import type { OnApiSiteUpdate } from '../types/dappUpdates';

import { TON_TOKEN_SLUG } from '../../config';
import { parseAccountId } from '../../util/account';
Expand Down
2 changes: 1 addition & 1 deletion src/api/extensionMethods/sites.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ApiSiteUpdate, OnApiSiteUpdate } from '../types/dappUpdates';
import type { OnApiUpdate } from '../types';
import type { ApiSiteUpdate, OnApiSiteUpdate } from '../types/dappUpdates';

import { getCurrentAccountIdOrFail, waitLogin } from '../common/accounts';
import { resolveDappPromise } from '../common/dappPromises';
Expand Down
3 changes: 1 addition & 2 deletions src/api/methods/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { IS_EXTENSION } from '../../config';
import { parseAccountId } from '../../util/account';
import { fetchStoredAccount, loginResolve } from '../common/accounts';
import { waitStorageMigration } from '../common/helpers';
import { callHook } from '../hooks';
import { storage } from '../storages';
import { deactivateAccountDapp, deactivateAllDapps, onActiveDappAccountUpdated } from './dapps';
import {
Expand All @@ -12,8 +13,6 @@ import {
setupBalanceBasedPolling,
} from './polling';

import { callHook } from '../hooks';

let activeAccountId: string | undefined;

export async function activateAccount(accountId: string, newestTxIds?: ApiTxIdBySlug) {
Expand Down
3 changes: 1 addition & 2 deletions src/api/methods/dapps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import {
getAccountValue, removeAccountValue, removeNetworkAccountsValue, setAccountValue,
} from '../common/accounts';
import { isUpdaterAlive } from '../common/helpers';
import { storage } from '../storages';

import { callHook } from '../hooks';
import { storage } from '../storages';

const activeDappByAccountId: Record<string, string> = {};

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

import { IS_DAPP_SUPPORTED, IS_SSE_SUPPORTED } from '../../config';
import { connectUpdater, startStorageMigration } from '../common/helpers';
import { addHooks } from '../hooks';
import * as tonConnect from '../tonConnect';
import { resetupSseConnection, sendSseDisconnect } from '../tonConnect/sse';
import * as methods from '.';

import { addHooks } from '../hooks';

addHooks({
onDappDisconnected: sendSseDisconnect,
onDappsChanged: resetupSseConnection,
Expand Down
Loading

0 comments on commit 23b336a

Please sign in to comment.