Skip to content

Commit

Permalink
v3.0.29
Browse files Browse the repository at this point in the history
  • Loading branch information
mytonwalletorg committed Oct 8, 2024
1 parent c93bd52 commit a179db7
Show file tree
Hide file tree
Showing 43 changed files with 517 additions and 299 deletions.
1 change: 1 addition & 0 deletions changelogs/3.0.29.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.28",
"version": "3.0.29",
"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.28
3.0.29
15 changes: 15 additions & 0 deletions src/api/chains/ton/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,21 @@ export const KnownContracts: Record<ContractName, ContractInfo> = {
hash: '14ce618a0e9a94adc99fa6e975219ddd675425b30dfa9728f98714c8dc55f9da',
isSwapAllowed: true,
},
stonRouterV2: {
name: 'stonRouterV2',
hash: 'd61cb7fb7bee0cc414286a482fccdec53c3f8717e4aae4fc362d98ab6254e6cd',
isSwapAllowed: true,
},
stonPoolV2: {
name: 'stonPoolV2',
hash: '16cc513c380e329f45d54f294787e2030e289799eca138961c1cd7e26e882c7c',
isSwapAllowed: true,
},
stonPtonWalletV2: {
name: 'stonPtonWalletV2',
hash: '2761042202032258de9eb1b672e1ec2e4f13b2af00700195801ada33f7ced1b6',
isSwapAllowed: true,
},
megatonWtonMaster: {
name: 'megatonWtonMaster',
hash: '4c9790d808ea4470614e021f76c40529efe2fbce8138da4284a29b5f1943ef19',
Expand Down
14 changes: 6 additions & 8 deletions src/api/chains/ton/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,12 @@ export interface JettonMetadata {
custom_payload_api_uri?: string;
}

export interface InitData {
code?: Cell;
data?: Cell;
}

export type ContractName = ApiTonWalletVersion | 'v4R1' | 'highloadV2' | 'multisig' | 'multisigV2' | 'multisigNew'
| 'nominatorPool' | 'vesting' | 'dedustPool' | 'dedustVaultNative' | 'dedustVaultJetton'
| 'stonPtonWallet' | 'stonRouter' | 'megatonWtonMaster' | 'megatonRouter';
export type ContractName = ApiTonWalletVersion
| 'v4R1' | 'highloadV2' | 'multisig' | 'multisigV2' | 'multisigNew'
| 'nominatorPool' | 'vesting'
| 'dedustPool' | 'dedustVaultNative' | 'dedustVaultJetton'
| 'stonPtonWallet' | 'stonRouter' | 'stonRouterV2' | 'stonPoolV2' | 'stonPtonWalletV2'
| 'megatonWtonMaster' | 'megatonRouter';

export type ContractInfo = {
name: ContractName;
Expand Down
1 change: 1 addition & 0 deletions src/api/chains/tron/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const ONE_TRX = 1_000_000n;
5 changes: 2 additions & 3 deletions src/api/chains/tron/polling.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type { ApiTxTimestamps, OnApiUpdate } from '../../types';

import {
getChainConfig, TRX,
} from '../../../config';
import { TRX } from '../../../config';
import { parseAccountId } from '../../../util/account';
import { getChainConfig } from '../../../util/chain';
import { compareActivities } from '../../../util/compareActivities';
import { logDebugError } from '../../../util/logs';
import { pauseOrFocus } from '../../../util/pauseOrFocus';
Expand Down
3 changes: 2 additions & 1 deletion src/api/chains/tron/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { TronWeb } from 'tronweb';

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

import { getChainConfig, TRX } from '../../../config';
import { TRX } from '../../../config';
import { parseAccountId } from '../../../util/account';
import { getChainConfig } from '../../../util/chain';
import { compareActivities } from '../../../util/compareActivities';
import { fetchJson } from '../../../util/fetch';
import { buildCollectionByKey } from '../../../util/iteratees';
Expand Down
18 changes: 15 additions & 3 deletions src/api/chains/tron/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import type { ContractParamter, Transaction } from 'tronweb/lib/commonjs/types';

import type { ApiSubmitTransferOptions, CheckTransactionDraftOptions } from '../../methods/types';
import type { ApiCheckTransactionDraftResult } from '../ton/types';
import type { ApiAccountWithMnemonic } from '../../types';
import { ApiTransactionDraftError, ApiTransactionError } from '../../types';
import type { ApiAccountWithMnemonic, ApiBip39Account } from '../../types';

import { parseAccountId } from '../../../util/account';
import { logDebugError } from '../../../util/logs';
Expand All @@ -16,6 +16,8 @@ import { getMnemonic } from '../../common/mnemonic';
import { handleServerError } from '../../errors';
import { getWalletBalance } from './wallet';
import type { ApiSubmitTransferTronResult } from './types';
import { hexToString } from '../../../util/stringFormat';
import { ONE_TRX } from './constants';

const SIGNATURE_SIZE = 65;
const FEE_LIMIT_TRX = 35_000_000n; // 35 TRX
Expand Down Expand Up @@ -93,11 +95,11 @@ export async function submitTransfer(options: ApiSubmitTransferOptions): Promise
const tronWeb = getTronClient(network);

const account = await fetchStoredAccount<ApiAccountWithMnemonic>(accountId);
const { address } = account.ton;
const { address } = (account as ApiBip39Account).tron;
const trxBalance = await getWalletBalance(network, address);

const trxAmount = tokenAddress ? fee : fee + amount;
const isEnoughTrx = trxBalance > trxAmount;
const isEnoughTrx = (trxBalance - ONE_TRX) >= trxAmount;

if (!isEnoughTrx) {
return { error: ApiTransactionError.InsufficientBalance };
Expand Down Expand Up @@ -127,6 +129,16 @@ export async function submitTransfer(options: ApiSubmitTransferOptions): Promise
privateKey,
});

if ('code' in result && !('result' in result && result.result)) {
const error = 'message' in result && result.message
? hexToString(result.message)
: result.code.toString();

logDebugError('submitTransfer', { error, result });

return { error };
}

return { amount, toAddress, txId: result.transaction.txID };
}
} catch (err: any) {
Expand Down
2 changes: 1 addition & 1 deletion src/api/chains/tron/util/tronweb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { TronWeb } from 'tronweb';

import type { ApiNetwork } from '../../../types';

import { getChainConfig } from '../../../../config';
import { getChainConfig } from '../../../../util/chain';

let clientByNetwork: Record<ApiNetwork, TronWeb> | undefined;

Expand Down
10 changes: 7 additions & 3 deletions src/api/common/swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { ApiSwapActivity, ApiSwapHistoryItem } from '../types';
import { TONCOIN } from '../../config';
import { buildSwapId } from '../../util/swap/buildSwapId';
import { callBackendGet, callBackendPost } from './backend';
import { buildTokenSlug } from './tokens';
import { buildTokenSlug, getTokenByAddress } from './tokens';

export function swapGetHistory(address: string, params: {
fromLt?: number;
Expand Down Expand Up @@ -37,7 +37,11 @@ export function swapItemToActivity(swap: ApiSwapHistoryItem): ApiSwapActivity {
}

export function getSwapItemSlug(item: ApiSwapHistoryItem, asset: string) {
if (asset === TONCOIN.symbol) return TONCOIN.slug;
if (item.cex) return asset;
if (asset === TONCOIN.symbol) {
return TONCOIN.slug;
}
if (item.cex) {
return getTokenByAddress(asset)?.slug ?? asset;
}
return buildTokenSlug('ton', asset);
}
3 changes: 2 additions & 1 deletion src/api/methods/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import type {
ApiChain, ApiLedgerAccount, ApiTonWallet, ApiTxTimestamps, OnApiUpdate,
} from '../types';

import { getChainConfig, IS_EXTENSION } from '../../config';
import { IS_EXTENSION } from '../../config';
import { parseAccountId } from '../../util/account';
import { getChainConfig } from '../../util/chain';
import chains from '../chains';
import {
fetchStoredAccount,
Expand Down
6 changes: 4 additions & 2 deletions src/api/methods/polling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
OnApiUpdate,
} from '../types';

import { IS_AIR_APP } from '../../config';
import { IS_AIR_APP, TONCOIN } from '../../config';
import { buildCollectionByKey, omit } from '../../util/iteratees';
import { logDebugError } from '../../util/logs';
import { pauseOrFocus } from '../../util/pauseOrFocus';
Expand Down Expand Up @@ -140,7 +140,9 @@ export async function tryLoadSwapTokens(localOnUpdate?: OnApiUpdate) {
// Fix legacy variable names
...omit(asset as any, ['blockchain']) as ApiSwapAsset,
chain: 'blockchain' in asset ? asset.blockchain as string : asset.chain,
tokenAddress: 'contract' in asset ? asset.contract as string : asset.tokenAddress,
tokenAddress: 'contract' in asset && asset.contract !== TONCOIN.symbol
? asset.contract as string
: asset.tokenAddress,
price: prices.bySlug[asset.slug]?.price ?? 0,
};
return acc;
Expand Down
2 changes: 1 addition & 1 deletion src/api/methods/swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,11 @@ export async function swapCexCreateTransaction(
const { swap } = await callBackendPost<ApiSwapCexCreateTransactionResponse>('/swap/cex/createTransaction', request, {
authToken,
});

const activity = swapItemToActivity(swap);

onUpdate({
type: 'newActivities',
chain: 'ton',
accountId,
activities: [activity],
});
Expand Down
4 changes: 2 additions & 2 deletions src/api/methods/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import type {
} from '../types';
import type { ApiSubmitTransferOptions, ApiSubmitTransferResult, CheckTransactionDraftOptions } from './types';

import { getChainConfig } from '../../config';
import { parseAccountId } from '../../util/account';
import { getChainConfig } from '../../util/chain';
import { compareActivities } from '../../util/compareActivities';
import { logDebugError } from '../../util/logs';
import chains from '../chains';
Expand Down Expand Up @@ -110,7 +110,7 @@ export async function submitTransfer(
chain: ApiChain,
options: ApiSubmitTransferOptions,
shouldCreateLocalTransaction = true,
) {
): Promise<(ApiSubmitTransferResult | ApiSubmitTransferWithDieselResult) & { txId?: string }> {
const {
accountId,
password,
Expand Down
2 changes: 1 addition & 1 deletion src/api/types/updates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export type ApiUpdateBalances = {
export type ApiUpdateNewActivities = {
type: 'newActivities';
accountId: string;
chain: ApiChain;
chain?: ApiChain;
activities: ApiActivity[];
noForward?: boolean; // Forbid cyclic update redirection to/from NBS
};
Expand Down
5 changes: 5 additions & 0 deletions src/components/common/SwapResult.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,8 @@
.changellyTextField {
width: 100%;
}

.feeBlock {
margin-top: 2rem;
margin-bottom: -0.75rem;
}
46 changes: 40 additions & 6 deletions src/components/common/SwapResult.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import React, { memo } from '../../lib/teact/teact';
import React, { memo, useMemo } from '../../lib/teact/teact';
import { withGlobal } from '../../global';

import type { Account, UserSwapToken } from '../../global/types';
import { SwapType } from '../../global/types';

import { TONCOIN } from '../../config';
import { getIsInternalSwap, getIsSupportedChain } from '../../global/helpers';
import { selectCurrentAccount } from '../../global/selectors';
import buildClassName from '../../util/buildClassName';
import { findChainConfig } from '../../util/chain';
import { formatCurrency } from '../../util/formatNumber';
import getChainNetworkName from '../../util/swap/getChainNetworkName';
import { ANIMATED_STICKERS_PATHS } from '../ui/helpers/animatedAssets';

Expand All @@ -15,6 +20,7 @@ import Button from '../ui/Button';
import InteractiveTextField from '../ui/InteractiveTextField';
import SwapTokensInfo from './SwapTokensInfo';

import transactionStyles from '../main/modals/TransactionModal.module.scss';
import styles from './SwapResult.module.scss';

interface OwnProps {
Expand All @@ -27,6 +33,7 @@ interface OwnProps {
secondButtonText?: string;
swapType?: SwapType;
toAddress?: string;
networkFee?: number;
onFirstButtonClick?: NoneToVoidFunction;
onSecondButtonClick?: NoneToVoidFunction;
}
Expand All @@ -45,12 +52,25 @@ function SwapResult({
secondButtonText,
swapType,
toAddress = '',
networkFee,
addressByChain,
onFirstButtonClick,
onSecondButtonClick,
}: OwnProps & StateProps) {
const lang = useLang();

const isInternalSwap = getIsInternalSwap({
from: tokenIn, to: tokenOut, toAddress, addressByChain,
});
const isToAddressInCurrentWallet = useMemo(() => {
return Boolean(toAddress && Object.values(addressByChain ?? {}).some((address) => address === toAddress));
}, [addressByChain, toAddress]);
const nativeToken = useMemo(() => {
if (!tokenIn) return undefined;

return findChainConfig(tokenIn.chain)?.nativeToken;
}, [tokenIn]);

function renderButtons() {
if (!firstButtonText && !secondButtonText) {
return undefined;
Expand All @@ -69,7 +89,7 @@ function SwapResult({
}

function renderSticker() {
if (swapType === SwapType.CrosschainFromToncoin) return undefined;
if (swapType === SwapType.CrosschainFromWallet && !isInternalSwap) return undefined;

return (
<AnimatedIconWithPreview
Expand All @@ -83,6 +103,19 @@ function SwapResult({
);
}

function renderFee() {
return (
<div className={buildClassName(styles.feeBlock, transactionStyles.textFieldWrapperFullWidth)}>
<span className={transactionStyles.textFieldLabel}>
{lang('Blockchain Fee')}
</span>
<div className={transactionStyles.textField}>
{formatCurrency(networkFee!, nativeToken?.symbol ?? TONCOIN.symbol, undefined, true)}
</div>
</div>
);
}

function renderTimeWarning() {
return (
<div className={styles.changellyInfoBlock}>
Expand All @@ -94,11 +127,10 @@ function SwapResult({
}

function renderChangellyInfo() {
if (swapType !== SwapType.CrosschainFromToncoin || (
toAddress && (toAddress === addressByChain?.ton || toAddress === addressByChain?.tron)
)) {
if (swapType !== SwapType.CrosschainFromWallet || isToAddressInCurrentWallet) {
return undefined;
}
const chain = getIsSupportedChain(tokenOut?.chain) ? tokenOut.chain : undefined;

return (
<div className={styles.changellyInfoBlock}>
Expand All @@ -114,7 +146,7 @@ function SwapResult({
}
</span>
<InteractiveTextField
chain="ton"
chain={chain}
address={toAddress}
copyNotification={lang('Address was copied!')}
noSavedAddress
Expand All @@ -136,6 +168,8 @@ function SwapResult({
amountOut={amountOut}
/>

{!!networkFee && renderFee()}

{swapType !== SwapType.OnChain && renderTimeWarning()}
{renderChangellyInfo()}

Expand Down
Loading

0 comments on commit a179db7

Please sign in to comment.