Skip to content

Commit

Permalink
v3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mytonwalletorg committed Jul 24, 2024
1 parent 2199122 commit 0c2d47f
Show file tree
Hide file tree
Showing 84 changed files with 1,045 additions and 441 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
}
}
],
"react/jsx-key": [2, { "checkFragmentShorthand": true}],
"arrow-body-style": "off",
"no-else-return": "off",
"no-plusplus": "off",
Expand Down
1 change: 1 addition & 0 deletions changelogs/1.20.19.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Bug fixes and performance improvements
1 change: 1 addition & 0 deletions changelogs/2.0.0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Bug fixes and performance improvements
8 changes: 8 additions & 0 deletions changelogs/3.0.0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- Significantly Improved In-App Browser Interface.
- Manual NFT Hiding.
- Enhanced Scam Detection.
- Ledger v2.1 Support.
- W5 Wallet Version Support.
- Boosted Connection Speed & App Performance.
- Dapp Connection Fixes.
- Multiple Fixes and 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.20.18",
"version": "3.0.0",
"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.20.18
3.0.0
4 changes: 2 additions & 2 deletions src/api/blockchains/ton/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -626,18 +626,18 @@ async function populateTransactions(network: ApiNetwork, transactions: ApiTransa

if (parsedPayload?.type === 'nft:ownership-assigned') {
const nft = nftsByAddress[parsedPayload.nftAddress];
transaction.nft = nft;
if (nft?.isScam) {
transaction.metadata = { ...transaction.metadata, isScam: true };
} else {
transaction.nft = nft;
transaction.fromAddress = addressBook[parsedPayload.prevOwner].user_friendly;
}
} else if (parsedPayload?.type === 'nft:transfer') {
const nft = nftsByAddress[parsedPayload.nftAddress];
transaction.nft = nft;
if (nft?.isScam) {
transaction.metadata = { ...transaction.metadata, isScam: true };
} else {
transaction.nft = nft;
transaction.toAddress = addressBook[parsedPayload.newOwner].user_friendly;
}
}
Expand Down
12 changes: 8 additions & 4 deletions src/api/blockchains/ton/util/tonCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,7 @@ export function buildLiquidStakingWithdrawBody(options: {
queryId, amount, responseAddress, waitTillRoundEnd, fillOrKill,
} = options;

const customPayload = new Builder()
.storeUint(Number(waitTillRoundEnd), 1)
.storeUint(Number(fillOrKill), 1)
.asCell();
const customPayload = buildLiquidStakingWithdrawCustomPayload(waitTillRoundEnd, fillOrKill);

return new Builder()
.storeUint(JettonOpCode.Burn, 32)
Expand All @@ -318,6 +315,13 @@ export function buildLiquidStakingWithdrawBody(options: {
.asCell();
}

export function buildLiquidStakingWithdrawCustomPayload(waitTillRoundEnd?: boolean, fillOrKill?: boolean) {
return new Builder()
.storeUint(Number(waitTillRoundEnd), 1)
.storeUint(Number(fillOrKill), 1)
.asCell();
}

export function getTokenBalance(network: ApiNetwork, walletAddress: string) {
const tokenWallet = getTonClient(network).open(new JettonWallet(Address.parse(walletAddress)));
return tokenWallet.getJettonBalance();
Expand Down
14 changes: 4 additions & 10 deletions src/api/common/addresses.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import type { ApiAddressInfo, ApiKnownAddresses } from '../types';

import {
RE_EMPTY_CHARS,
RE_FAKE_DOTS, RE_LINK_TEMPLATE, RE_SPACE_CHARS, RE_TG_BOT_MENTION,
} from '../../config';
import { RE_LINK_TEMPLATE, RE_TG_BOT_MENTION } from '../../config';
import { cleanText } from '../../lib/confusables';
import { logDebugError } from '../../util/logs';
import { callBackendGet } from './backend';

Expand Down Expand Up @@ -51,11 +49,7 @@ export function checkIsTrustedCollection(address: string) {
}

export function checkHasScamLink(text: string) {
const matches = text
.replace(RE_EMPTY_CHARS, '')
.replace(RE_SPACE_CHARS, ' ')
.replace(RE_FAKE_DOTS, '.')
.matchAll(RE_LINK_TEMPLATE);
const matches = cleanText(text).matchAll(RE_LINK_TEMPLATE);

for (const match of matches) {
const host = match.groups?.host;
Expand All @@ -68,5 +62,5 @@ export function checkHasScamLink(text: string) {
}

export function checkHasTelegramBotMention(text: string) {
return RE_TG_BOT_MENTION.test(text.replace(RE_EMPTY_CHARS, '').replace(RE_SPACE_CHARS, ' '));
return RE_TG_BOT_MENTION.test(cleanText(text));
}
4 changes: 2 additions & 2 deletions src/api/common/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ export function buildLocalTransaction(

export function updateTransactionMetadata(transaction: ApiTransactionExtra): ApiTransactionExtra {
const {
normalizedAddress, comment, type, isIncoming,
normalizedAddress, comment, type, isIncoming, nft,
} = transaction;
let { metadata = {} } = transaction;

const isNftTransfer = type === 'nftTransferred' || type === 'nftReceived';
const isNftTransfer = type === 'nftTransferred' || type === 'nftReceived' || Boolean(nft);
const knownAddresses = getKnownAddresses();
const hasScamMarkers = comment ? getScamMarkers().some((sm) => sm.test(comment)) : false;
const shouldCheckComment = !hasScamMarkers && comment && isIncoming
Expand Down
6 changes: 2 additions & 4 deletions src/api/methods/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
sendUpdateTokens,
setupBalanceBasedPolling,
setupStakingPolling,
setupSwapPolling,
setupVestingPolling,
setupWalletVersionsPolling,
} from './polling';
Expand All @@ -33,7 +32,7 @@ export async function activateAccount(accountId: string, newestTxIds?: ApiTxIdBy
deactivateAllDapps();
}

callHook('onFirstLogin');
void callHook('onFirstLogin');

onActiveDappAccountUpdated(accountId);
}
Expand All @@ -44,7 +43,6 @@ export async function activateAccount(accountId: string, newestTxIds?: ApiTxIdBy

void setupBalanceBasedPolling(accountId, newestTxIds);
void setupStakingPolling(accountId);
void setupSwapPolling(accountId);
void setupWalletVersionsPolling(accountId);
void setupVestingPolling(accountId);
}
Expand All @@ -55,7 +53,7 @@ export function deactivateAllAccounts() {

if (IS_EXTENSION) {
deactivateAllDapps();
callHook('onFullLogout');
void callHook('onFullLogout');
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/api/methods/dapps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export async function deleteAllDapps(accountId: string) {
accountId,
origin,
});
callHook('onDappDisconnected', accountId, origin);
void callHook('onDappDisconnected', accountId, origin);
});

await callHook('onDappsChanged');
Expand Down Expand Up @@ -208,7 +208,7 @@ export function getDappsState(): Promise<ApiDappsState | undefined> {
export async function removeAccountDapps(accountId: string) {
await removeAccountValue(accountId, 'dapps');

callHook('onDappsChanged');
void callHook('onDappsChanged');
}

export async function removeAllDapps() {
Expand Down
1 change: 0 additions & 1 deletion src/api/methods/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import * as methods from '.';
addHooks({
onDappDisconnected: tonConnectSse.sendSseDisconnect,
onDappsChanged: tonConnectSse.resetupSseConnection,
onSwapCreated: methods.setupSwapPolling,
});

// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down
100 changes: 2 additions & 98 deletions src/api/methods/polling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import type {
ApiStakingCommonData,
ApiStakingState,
ApiSwapAsset,
ApiSwapHistoryItem,
ApiTokenPrice,
ApiTransactionActivity,
ApiTxIdBySlug,
Expand Down Expand Up @@ -39,9 +38,7 @@ import { processNftUpdates, updateAccountNfts } from './nfts';
import { resolveDataPreloadPromise } from './preload';
import { getBaseCurrency } from './prices';
import { getBackendStakingState, tryUpdateStakingCommonData } from './staking';
import {
swapGetAssets, swapGetHistory, swapItemToActivity, swapReplaceTransactionsByRanges,
} from './swap';
import { swapGetAssets, swapReplaceTransactionsByRanges } from './swap';
import { fetchVestings } from './vesting';

type IsAccountActiveFn = (accountId: string) => boolean;
Expand All @@ -59,9 +56,6 @@ const STAKING_INTERVAL_WHEN_NOT_FOCUSED = 10 * SEC;
const BACKEND_INTERVAL = 30 * SEC;
const LONG_BACKEND_INTERVAL = 60 * SEC;
const NFT_FULL_INTERVAL = 60 * SEC;
const SWAP_POLLING_INTERVAL = 3 * SEC;
const SWAP_POLLING_INTERVAL_WHEN_NOT_FOCUSED = 10 * SEC;
const SWAP_FINISHED_STATUSES = new Set(['failed', 'completed', 'expired']);
const VERSIONS_INTERVAL = 5 * 60 * SEC;
const VERSIONS_INTERVAL_WHEN_NOT_FOCUSED = 15 * 60 * SEC;
const VESTING_INTERVAL = 10 * SEC;
Expand All @@ -81,7 +75,7 @@ const prices: {
baseCurrency: DEFAULT_PRICE_CURRENCY,
bySlug: {},
};
let swapPollingAccountId: string | undefined;

const lastBalanceCache: Record<string, AccountBalanceCache> = {};

export async function initPolling(_onUpdate: OnApiUpdate, _isAccountActive: IsAccountActiveFn) {
Expand Down Expand Up @@ -563,100 +557,10 @@ export function sendUpdateTokens() {
});
}

export async function setupSwapPolling(accountId: string) {
if (swapPollingAccountId === accountId) return; // Double launch is not allowed
swapPollingAccountId = accountId;

const { address, lastFinishedSwapTimestamp } = await fetchStoredAccount(accountId);

let fromTimestamp = lastFinishedSwapTimestamp ?? await getActualLastFinishedSwapTimestamp(accountId, address);

const localOnUpdate = onUpdate;
const swapById: Record<string, ApiSwapHistoryItem> = {};

while (isAlive(localOnUpdate, accountId)) {
try {
const swaps = await swapGetHistory(address, {
fromTimestamp,
});
if (!isAlive(localOnUpdate, accountId)) break;
if (!swaps.length) break;

swaps.reverse();

let isLastFinishedSwapUpdated = false;
let isPrevFinished = true;

for (const swap of swaps) {
if (swap.cex) {
if (swap.cex.status === swapById[swap.id]?.cex!.status) {
continue;
}
} else if (swap.status === swapById[swap.id]?.status) {
continue;
}

swapById[swap.id] = swap;

const isFinished = SWAP_FINISHED_STATUSES.has(swap.status);
if (isFinished && isPrevFinished) {
fromTimestamp = swap.timestamp;
isLastFinishedSwapUpdated = true;
}
isPrevFinished = isFinished;

if (swap.cex || swap.status !== 'completed') {
// Completed onchain swaps are processed in swapReplaceTransactions
onUpdate({
type: 'newActivities',
accountId,
activities: [swapItemToActivity(swap)],
});
}
}

if (isLastFinishedSwapUpdated) {
await updateStoredAccount(accountId, {
lastFinishedSwapTimestamp: fromTimestamp,
});
}
} catch (err) {
logDebugError('setupSwapPolling', err);
}

await pauseOrFocus(SWAP_POLLING_INTERVAL, SWAP_POLLING_INTERVAL_WHEN_NOT_FOCUSED);
}

if (accountId === swapPollingAccountId) {
swapPollingAccountId = undefined;
}
}

function isAlive(localOnUpdate: OnApiUpdate, accountId: string) {
return isUpdaterAlive(localOnUpdate) && isAccountActive(accountId);
}

async function getActualLastFinishedSwapTimestamp(accountId: string, address: string) {
const swaps = await swapGetHistory(address, {});

swaps.reverse();

let timestamp = Date.now();
for (const swap of swaps) {
if (SWAP_FINISHED_STATUSES.has(swap.status)) {
timestamp = swap.timestamp;
} else {
break;
}
}

await updateStoredAccount(accountId, {
lastFinishedSwapTimestamp: timestamp,
});

return timestamp;
}

function logAndRescue(err: Error) {
logDebugError('Polling error', err);

Expand Down
18 changes: 12 additions & 6 deletions src/api/methods/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ export async function submitUnstake(
}

export async function getBackendStakingState(accountId: string): Promise<ApiBackendStakingState> {
const { address, ledger } = await fetchStoredAccount(accountId);
const state = await fetchBackendStakingState(address, Boolean(ledger));
const { address } = await fetchStoredAccount(accountId);
const state = await fetchBackendStakingState(address);
return {
...state,
nominatorsPool: {
Expand All @@ -123,7 +123,7 @@ export async function getBackendStakingState(accountId: string): Promise<ApiBack
};
}

export async function fetchBackendStakingState(address: string, isLedger: boolean): Promise<ApiBackendStakingState> {
export async function fetchBackendStakingState(address: string): Promise<ApiBackendStakingState> {
const cacheItem = backendStakingStateByAddress[address];
if (cacheItem && cacheItem[0] > Date.now()) {
return cacheItem[1];
Expand All @@ -136,9 +136,7 @@ export async function fetchBackendStakingState(address: string, isLedger: boolea
'X-App-Env': APP_ENV,
};

const stakingState = await callBackendGet(`/staking/state/${address}`, {
isLedger,
}, headers);
const stakingState = await callBackendGet(`/staking/state/${address}`, headers);
stakingState.balance = fromDecimal(stakingState.balance);
stakingState.totalProfit = fromDecimal(stakingState.totalProfit);

Expand Down Expand Up @@ -178,3 +176,11 @@ export async function tryUpdateStakingCommonData() {
logDebugError('tryUpdateLiquidStakingState', err);
}
}

export async function getStakingState(accountId: string) {
const blockchain = blockchains[resolveBlockchainKey(accountId)!];
const backendState = await getBackendStakingState(accountId);
const state = await blockchain.getStakingState(accountId, backendState);

return { backendState, state };
}
Loading

0 comments on commit 0c2d47f

Please sign in to comment.