Skip to content

Commit

Permalink
v1.18.16
Browse files Browse the repository at this point in the history
  • Loading branch information
mytonwalletorg committed Mar 21, 2024
1 parent b9d00bf commit 1ef4f65
Show file tree
Hide file tree
Showing 21 changed files with 191 additions and 118 deletions.
1 change: 1 addition & 0 deletions changelogs/1.18.16.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": "1.18.15",
"version": "1.18.16",
"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.18.15
1.18.16
3 changes: 2 additions & 1 deletion src/api/blockchains/ton/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export const UNSTAKE_COMMENT = 'w';
export const ATTEMPTS = 5;

export const DEFAULT_DECIMALS = 9;
export const DEFAULT_IS_BOUNCEABLE = false;
export const DEFAULT_IS_BOUNCEABLE = true;
export const WALLET_IS_BOUNCEABLE = false;

// Fee may change, so we add 5% for more reliability. This is only safe for low-fee blockchains such as TON.
export const FEE_FACTOR = 1.05;
Expand Down
4 changes: 4 additions & 0 deletions src/api/methods/other.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,8 @@ export async function fetchAccountConfigForDebugPurposesOnly() {
}
}

export function ping() {
return true;
}

export { setIsAppFocused };
65 changes: 62 additions & 3 deletions src/api/providers/worker/connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,36 @@ import { IS_CAPACITOR } from '../../../config';
import { createWindowProvider } from '../../../util/capacitorStorageProxy';
import { logDebugError } from '../../../util/logs';
import { createConnector } from '../../../util/PostMessageConnector';
import { pause } from '../../../util/schedulers';
import { IS_IOS } from '../../../util/windowEnvironment';

let connector: Connector;
const HEALTH_CHECK_TIMEOUT = 150;
const HEALTH_CHECK_MIN_DELAY = 5000; // 5 sec

let updateCallback: OnApiUpdate;
let worker: Worker | undefined;
let connector: Connector | undefined;
let isInitialized = false;

export function initApi(onUpdate: OnApiUpdate, initArgs: ApiInitArgs | (() => ApiInitArgs)) {
updateCallback = onUpdate;

if (!connector) {
const worker = new Worker(
worker = new Worker(
/* webpackChunkName: "worker" */ new URL('./provider.ts', import.meta.url),
);
connector = createConnector(worker, onUpdate);

if (IS_CAPACITOR) {
createWindowProvider(worker);
createWindowProvider(worker!);
}
}

if (!isInitialized) {
if (IS_IOS) {
setupIosHealthCheck();
}
isInitialized = true;
}

const args = typeof initArgs === 'function' ? initArgs() : initArgs;
Expand All @@ -40,3 +57,45 @@ export async function callApi<T extends keyof AllMethods>(fnName: T, ...args: Al
return undefined;
}
}

export function callApiWithThrow<T extends keyof AllMethods>(fnName: T, ...args: AllMethodArgs<T>) {
return (connector!.request({
name: fnName,
args,
}) as AllMethodResponse<T>);
}

const startedAt = Date.now();

// Workaround for iOS sometimes stops interacting with worker
function setupIosHealthCheck() {
window.addEventListener('focus', () => {
void ensureWorkerPing();
// Sometimes a single check is not enough
setTimeout(() => ensureWorkerPing(), 1000);
});
}

async function ensureWorkerPing() {
let isResolved = false;

try {
await Promise.race([
callApiWithThrow('ping'),
pause(HEALTH_CHECK_TIMEOUT)
.then(() => (isResolved ? undefined : Promise.reject(new Error('HEALTH_CHECK_TIMEOUT')))),
]);
} catch (err) {
// eslint-disable-next-line no-console
console.error(err);

if (Date.now() - startedAt >= HEALTH_CHECK_MIN_DELAY) {
worker?.terminate();
worker = undefined;
connector = undefined;
updateCallback({ type: 'requestReconnectApi' });
}
} finally {
isResolved = true;
}
}
7 changes: 6 additions & 1 deletion src/api/types/updates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ export type ApiOpenUrl = {
url: string;
};

export type ApiRequestReconnect = {
type: 'requestReconnectApi';
};

export type ApiUpdate =
| ApiUpdateBalances
| ApiUpdateNewActivities
Expand All @@ -198,6 +202,7 @@ export type ApiUpdate =
| ApiUpdateAccount
| ApiUpdateRegion
| ApiUpdateWalletVersions
| ApiOpenUrl;
| ApiOpenUrl
| ApiRequestReconnect;

export type OnApiUpdate = (update: ApiUpdate) => void;
6 changes: 3 additions & 3 deletions src/components/main/Main.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ $scrollOffset: 0.1875rem;
display: grid;
grid-template-columns: 21.5rem 1fr;

/* 948px + 1rem padding on both sides */
max-width: 61.25rem;
height: 100%;
max-height: calc(var(--vh, 1vh) * 100);
Expand All @@ -59,14 +60,13 @@ $scrollOffset: 0.1875rem;
padding-top: 0;
}

// Fix for opera, dead zone of 37 pixels in extension window on windows
// Fix for Opera, dead zone of 37 pixels in extension window on Windows
:global(html.is-windows.is-opera.is-extension) & {
padding-top: 2.3125rem;
}

:global(html.is-ios) {
/* iPad 10th in landscape mode */
max-width: 73.75rem;
max-width: none;
}

.sidebar {
Expand Down
10 changes: 9 additions & 1 deletion src/components/main/sections/Card/Card.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@
cursor: pointer;

position: absolute;
bottom: 0.625rem;
bottom: 1.25rem;
left: 50%;
transform: translateX(-50%);

Expand All @@ -465,6 +465,14 @@
font-size: 0.9375rem;
font-weight: 700;
color: var(--color-card-text);

transition: opacity 150ms;

&_disabled {
pointer-events: none;

opacity: 0.8;
}
}

.periodItem {
Expand Down
29 changes: 9 additions & 20 deletions src/components/main/sections/Card/ChartHistorySwitcher.tsx
Original file line number Diff line number Diff line change
@@ -1,62 +1,51 @@
import React, { memo, useMemo } from '../../../../lib/teact/teact';
import React, { memo } from '../../../../lib/teact/teact';
import { getActions, withGlobal } from '../../../../global';

import type { TokenPeriod } from '../../../../global/types';
import type { DropdownItem } from '../../../ui/Dropdown';

import { HISTORY_PERIODS } from '../../../../config';

import useLastCallback from '../../../../hooks/useLastCallback';

import DropdownMenu from '../../../ui/DropdownMenu';

interface OwnProps {
isOpen: boolean;
excludedPeriod?: TokenPeriod;
menuPositionHorizontal?: 'right' | 'left';
onClose: NoneToVoidFunction;
onChange?: (period: TokenPeriod) => void;
}

interface StateProps {
currentPeriod?: TokenPeriod;
}

const HISTORY_PERIODS: DropdownItem[] = [
{ value: '1D', name: '1D' },
{ value: '7D', name: '7D' },
{ value: '1M', name: '1M' },
{ value: '3M', name: '3M' },
{ value: '1Y', name: '1Y' },
];
const ITEMS = HISTORY_PERIODS.map((key) => ({ value: key, name: key }));

function ChartHistorySwitcher({
isOpen,
currentPeriod,
excludedPeriod,
menuPositionHorizontal,
onClose,
onChange,
}: OwnProps & StateProps) {
const { setCurrentTokenPeriod } = getActions();

const historyList = useMemo(
() => HISTORY_PERIODS.filter((item) => item.value !== excludedPeriod),
[excludedPeriod],
);

const handlePeriodChange = useLastCallback((period: string) => {
onClose();

if (period === currentPeriod) return;

setCurrentTokenPeriod({ period: period as TokenPeriod });
onChange?.(period as TokenPeriod);
});

return (
<DropdownMenu
isOpen={isOpen}
onClose={onClose}
items={historyList}
items={ITEMS}
shouldTranslateOptions
selectedValue={currentPeriod}
menuPositionHorizontal={menuPositionHorizontal}
menuPositionHorizontal="right"
onSelect={handlePeriodChange}
/>
);
Expand Down
3 changes: 3 additions & 0 deletions src/components/main/sections/Card/CurrencySwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface OwnProps {
excludedCurrency?: string;
menuPositionHorizontal?: 'right' | 'left';
onClose: NoneToVoidFunction;
onChange?: (currency: ApiBaseCurrency) => void;
}

interface StateProps {
Expand All @@ -26,6 +27,7 @@ function CurrencySwitcher({
excludedCurrency,
menuPositionHorizontal,
onClose,
onChange,
}: OwnProps & StateProps) {
const { changeBaseCurrency } = getActions();

Expand All @@ -40,6 +42,7 @@ function CurrencySwitcher({
if (currency === currentCurrency) return;

changeBaseCurrency({ currency: currency as ApiBaseCurrency });
onChange?.(currency as ApiBaseCurrency);
});

return (
Expand Down
Loading

0 comments on commit 1ef4f65

Please sign in to comment.