Skip to content

Commit

Permalink
v3.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
mytonwalletorg committed Aug 14, 2024
1 parent 3129839 commit 798d091
Show file tree
Hide file tree
Showing 30 changed files with 253 additions and 116 deletions.
1 change: 1 addition & 0 deletions changelogs/3.0.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": "3.0.6",
"version": "3.0.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 @@
3.0.6
3.0.7
1 change: 1 addition & 0 deletions src/api/blockchains/ton/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export {
} from './other';
export {
getAccountTokenBalances,
getTokenBalances,
getAddressTokenBalances,
fetchToken,
resolveTokenBySlug,
Expand Down
4 changes: 4 additions & 0 deletions src/api/blockchains/ton/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ export async function getAccountTokenBalances(accountId: string) {
const { network } = parseAccountId(accountId);
const address = await fetchStoredAddress(accountId);

return getTokenBalances(network, address);
}

export async function getTokenBalances(network: ApiNetwork, address: string) {
const balancesRaw: Array<JettonBalance> = await fetchJettonBalances(network, address);
return balancesRaw.map((balance) => parseTokenBalance(network, balance)).filter(Boolean);
}
Expand Down
10 changes: 9 additions & 1 deletion src/api/blockchains/ton/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { parseAccountId } from '../../../util/account';
import { pick } from '../../../util/iteratees';
import withCacheAsync from '../../../util/withCacheAsync';
import { stringifyTxId } from './util';
import { fetchJettonBalances } from './util/tonapiio';
import {
getTonClient, toBase64Address, walletClassMap,
} from './util/tonCore';
Expand Down Expand Up @@ -136,7 +137,7 @@ export async function pickBestWallet(network: ApiNetwork, publicKey: Uint8Array)
}

const withBiggestBalance = allWallets.reduce<typeof allWallets[0] | undefined>((best, current) => {
return best && best.balance > current.balance ? best : current;
return current.balance > (best?.balance ?? 0n) ? current : best;
}, undefined);

if (withBiggestBalance) {
Expand All @@ -149,6 +150,13 @@ export async function pickBestWallet(network: ApiNetwork, publicKey: Uint8Array)
return withLastTx;
}

// Workaround for NOT holders who do not have transactions
const v4Wallet = allWallets.find(({ version }) => version === 'v4R2')!;
const v4JettonBalances = await fetchJettonBalances(network, v4Wallet.address);
if (v4JettonBalances.length > 0) {
return v4Wallet;
}

return defaultWallet;
}

Expand Down
42 changes: 32 additions & 10 deletions src/api/methods/polling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { DEFAULT_PRICE_CURRENCY, POPULAR_WALLET_VERSIONS, TONCOIN_SLUG } from '.
import { parseAccountId } from '../../util/account';
import { areDeepEqual } from '../../util/areDeepEqual';
import { compareActivities } from '../../util/compareActivities';
import { buildCollectionByKey } from '../../util/iteratees';
import { buildCollectionByKey, omit } from '../../util/iteratees';
import { logDebugError } from '../../util/logs';
import { pauseOrFocus } from '../../util/pauseOrFocus';
import blockchains from '../blockchains';
Expand Down Expand Up @@ -572,30 +572,52 @@ export async function setupWalletVersionsPolling(accountId: string) {

const localOnUpdate = onUpdate;

const { publicKey, version } = await fetchStoredAccount(accountId);
const {
address, publicKey, version, isInitialized,
} = await fetchStoredAccount(accountId);
const publicKeyBytes = hexToBytes(publicKey);
const { network } = parseAccountId(accountId);

const versions = POPULAR_WALLET_VERSIONS.filter((value) => value !== version);
let lastResult: ApiWalletInfo[] | undefined;

let shouldCheckV4 = false;
let v4HasTokens: boolean | undefined;

if (version === 'W5' && !isInitialized) {
const { lastTxId } = await ton.getWalletInfo(network, address);
shouldCheckV4 = !lastTxId;
}

while (isAlive(localOnUpdate, accountId)) {
try {
const versionInfos = (await ton.getWalletVersionInfos(
network, publicKeyBytes, versions,
)).filter((versionInfo) => !!versionInfo.lastTxId || versionInfo.version === 'W5');

const filteredVersions = versionInfos.map(({ wallet, ...rest }) => rest);
const allWalletInfos = (await ton.getWalletVersionInfos(network, publicKeyBytes, versions))
.map((versionInfo) => omit(versionInfo, ['wallet']));
const filteredInfos: ApiWalletInfo[] = [];

for (const walletInfo of allWalletInfos) {
if (!!walletInfo.lastTxId || walletInfo.version === 'W5') {
filteredInfos.push(walletInfo);
} else if (walletInfo.version === 'v4R2' && !walletInfo.lastTxId && shouldCheckV4) {
if (v4HasTokens === undefined) {
v4HasTokens = !!(await ton.getTokenBalances(network, walletInfo.address)).length;
}

if (v4HasTokens) {
filteredInfos.push(walletInfo);
}
}
}

if (!isAlive(localOnUpdate, accountId)) return;

if (!areDeepEqual(versionInfos, lastResult)) {
lastResult = versionInfos;
if (!areDeepEqual(allWalletInfos, lastResult)) {
lastResult = allWalletInfos;
onUpdate({
type: 'updateWalletVersions',
accountId,
currentVersion: version,
versions: filteredVersions,
versions: filteredInfos,
});
}
} catch (err) {
Expand Down
37 changes: 27 additions & 10 deletions src/components/swap/Swap.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,13 @@
}

.balanceContainer,
.priceContainer,
.advancedSlippageContainer {
position: relative;
z-index: 1;

width: 100%;
}

.tokenPrice,
.balance {
position: absolute;
top: -0.125rem;
Expand All @@ -65,14 +63,6 @@
color: var(--color-gray-1);
}

.tokenPrice {
font-weight: 400;
}

.tokenPriceBold {
font-weight: 600;
}

.balanceLink {
cursor: var(--custom-cursor, pointer);

Expand Down Expand Up @@ -256,10 +246,27 @@
cursor: var(--custom-cursor, pointer);
}

.tokenPrice,
.feeText {
font-size: 0.8125rem;
font-weight: 600;
color: var(--color-gray-2);
white-space: nowrap;
}

.tokenPrice + .feeText::before {
content: '';

display: inline-block;

width: 0.125rem;
height: 0.125rem;
margin: 0 0.3125rem 0 0.0625rem;

vertical-align: 0.1875rem;

background-color: var(--color-gray-2);
border-radius: 50%;
}

.feeIcon {
Expand Down Expand Up @@ -426,6 +433,16 @@
max-width: 100% !important;
}

.swapArrowIcon {
margin: 0 -0.125rem;

font-size: 1.25rem;

&:global(.icon-arrow-right) {
font-weight: 600 !important;
}
}

.priceImpact {
cursor: var(--custom-cursor, pointer);

Expand Down
66 changes: 43 additions & 23 deletions src/components/swap/SwapInitial.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ function SwapInitial({
pairs,
isSettingsModalOpen,
dieselStatus,
swapFee,
},
accountId,
tokens,
Expand Down Expand Up @@ -373,6 +374,9 @@ function SwapInitial({
function renderPrice() {
const isPriceVisible = Boolean(amountIn && amountOut);
const shouldBeRendered = isPriceVisible && !isEstimating;

if (!shouldBeRendered) return undefined;

const rate = getSwapRate(
amountIn ? String(amountIn) : undefined,
amountOut ? String(amountOut) : undefined,
Expand All @@ -384,21 +388,12 @@ function SwapInitial({
if (!rate) return undefined;

return (
<Transition
name="fade"
activeKey={shouldBeRendered ? 0 : 1}
>
<div className={styles.priceContainer}>
{shouldBeRendered && (
<span className={styles.tokenPrice}>
{rate.firstCurrencySymbol}{' ≈ '}
<span className={styles.tokenPriceBold}>
{rate.price}{' '}{rate.secondCurrencySymbol}
</span>
</span>
)}
</div>
</Transition>
<span className={styles.tokenPrice}>
{rate.firstCurrencySymbol}{' ≈ '}
<span className={styles.tokenPriceBold}>
{rate.price}{' '}{rate.secondCurrencySymbol}
</span>
</span>
);
}

Expand Down Expand Up @@ -469,17 +464,41 @@ function SwapInitial({
}

function renderFee() {
if (swapType === SwapType.CrosschainToToncoin) return undefined;

const isFeeEqualZero = realNetworkFee === 0;
const text = lang(isFeeEqualZero ? '$fee_value' : '$fee_value_almost_equal', {
fee: formatCurrency(realNetworkFee, TON_SYMBOL),
});

let feeBlock: React.JSX.Element | undefined;

if (
swapType === SwapType.OnChain
&& !isEnoughToncoin
&& swapFee
&& tokenIn
&& tokenIn?.slug !== TONCOIN_SLUG
&& !isLoading
) {
// Gasless swap
feeBlock = (
<span className={styles.feeText}>{lang('$fee_value', {
fee: formatCurrency(swapFee, tokenIn.symbol),
})}
</span>
);
} else if (swapType !== SwapType.CrosschainToToncoin) {
feeBlock = (
<span className={styles.feeText}>{lang(isFeeEqualZero ? '$fee_value' : '$fee_value_almost_equal', {
fee: formatCurrency(realNetworkFee, TON_SYMBOL),
})}
</span>
);
}

const priceBlock = renderPrice();
const activeKey = (isFeeEqualZero ? 0 : 1) + (priceBlock ? 2 : 3);

return (
<Transition
name="fade"
activeKey={isFeeEqualZero ? 0 : 1}
activeKey={activeKey}
className={styles.feeWrapper}
>
<div
Expand All @@ -489,7 +508,9 @@ function SwapInitial({
)}
onClick={isCrosschain ? undefined : openSettingsModal}
>
<span className={styles.feeText}>{text}</span>
{priceBlock}
{feeBlock}

{
isCrosschain
? undefined
Expand Down Expand Up @@ -530,7 +551,6 @@ function SwapInitial({
</div>

<div ref={inputOutRef} className={styles.inputContainer}>
{renderPrice()}
<RichNumberInput
id="swap-buy"
labelText={lang('You buy')}
Expand Down
Loading

0 comments on commit 798d091

Please sign in to comment.