Skip to content

Commit

Permalink
fix(PRO-156): bugs 1-4, 6
Browse files Browse the repository at this point in the history
  • Loading branch information
siandreev committed Dec 25, 2024
1 parent bc1ce3a commit 36c100c
Show file tree
Hide file tree
Showing 20 changed files with 235 additions and 62 deletions.
2 changes: 1 addition & 1 deletion packages/core/resource/Dockerfile.2faApi
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FROM openapitools/openapi-generator-cli

CMD ["generate", "-i", "https://raw.githubusercontent.com/tonkeeper/tonkeeper_2fa_backend/refs/heads/main/swagger.yaml?token=GHSAT0AAAAAACJYQUODSKLU7RLKH2FXU6KKZ3LAPXA", "-g", "typescript-fetch", "-o", "/local/src/2faApi", "-p", "supportsES6=true,withInterfaces=true", "--openapi-normalizer", "KEEP_ONLY_FIRST_TAG_IN_OPERATION=true"]
CMD ["generate", "-i", "https://raw.githubusercontent.com/tonkeeper/tonkeeper_2fa_backend/refs/heads/main/swagger.yaml?token=GHSAT0AAAAAACJYQUOCG3M3IRKQM3KPJSAUZ3MA5IA", "-g", "typescript-fetch", "-o", "/local/src/2faApi", "-p", "supportsES6=true,withInterfaces=true", "--openapi-normalizer", "KEEP_ONLY_FIRST_TAG_IN_OPERATION=true"]
1 change: 1 addition & 0 deletions packages/core/src/2faApi/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ apis/SystemApi.ts
apis/index.ts
index.ts
models/ConnectRequest.ts
models/ErrorCode.ts
models/ExistsExtensionRequest.ts
models/Message.ts
models/MessageID.ts
Expand Down
53 changes: 53 additions & 0 deletions packages/core/src/2faApi/models/ErrorCode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* tslint:disable */
/* eslint-disable */
/**
* REST API
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 0.0.1
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/


/**
*
* @export
*/
export const ErrorCode = {
NUMBER_0: 0,
NUMBER_1: 1
} as const;
export type ErrorCode = typeof ErrorCode[keyof typeof ErrorCode];


export function instanceOfErrorCode(value: any): boolean {
for (const key in ErrorCode) {
if (Object.prototype.hasOwnProperty.call(ErrorCode, key)) {
if (ErrorCode[key as keyof typeof ErrorCode] === value) {
return true;
}
}
}
return false;
}

export function ErrorCodeFromJSON(json: any): ErrorCode {
return ErrorCodeFromJSONTyped(json, false);
}

export function ErrorCodeFromJSONTyped(json: any, ignoreDiscriminator: boolean): ErrorCode {
return json as ErrorCode;
}

export function ErrorCodeToJSON(value?: ErrorCode | null): any {
return value as any;
}

export function ErrorCodeToJSONTyped(value: any, ignoreDiscriminator: boolean): ErrorCode {
return value as ErrorCode;
}

3 changes: 2 additions & 1 deletion packages/core/src/2faApi/models/MessageState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export const MessageState = {
Waiting: 'waiting',
Expired: 'expired',
Confirmed: 'confirmed',
Failed: 'failed'
Failed: 'failed',
Canceled: 'canceled'
} as const;
export type MessageState = typeof MessageState[keyof typeof MessageState];

Expand Down
19 changes: 19 additions & 0 deletions packages/core/src/2faApi/models/PingReadyGet500Response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
*/

import { mapValues } from '../runtime';
import type { ErrorCode } from './ErrorCode';
import {
ErrorCodeFromJSON,
ErrorCodeFromJSONTyped,
ErrorCodeToJSON,
ErrorCodeToJSONTyped,
} from './ErrorCode';

/**
*
* @export
Expand All @@ -25,13 +33,22 @@ export interface PingReadyGet500Response {
* @memberof PingReadyGet500Response
*/
error: string;
/**
*
* @type {ErrorCode}
* @memberof PingReadyGet500Response
*/
code: ErrorCode;
}



/**
* Check if a given object implements the PingReadyGet500Response interface.
*/
export function instanceOfPingReadyGet500Response(value: object): value is PingReadyGet500Response {
if (!('error' in value) || value['error'] === undefined) return false;
if (!('code' in value) || value['code'] === undefined) return false;
return true;
}

Expand All @@ -46,6 +63,7 @@ export function PingReadyGet500ResponseFromJSONTyped(json: any, ignoreDiscrimina
return {

'error': json['error'],
'code': ErrorCodeFromJSON(json['code']),
};
}

Expand All @@ -61,6 +79,7 @@ export function PingReadyGet500ResponseFromJSONTyped(json: any, ignoreDiscrimina
return {

'error': value['error'],
'code': ErrorCodeToJSON(value['code']),
};
}

1 change: 1 addition & 0 deletions packages/core/src/2faApi/models/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* tslint:disable */
/* eslint-disable */
export * from './ConnectRequest';
export * from './ErrorCode';
export * from './ExistsExtensionRequest';
export * from './Message';
export * from './MessageID';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,22 @@ import { WalletContractV5R1 } from '@ton/ton';
import { ISender } from './ISender';
import { AssetAmount } from '../../../entries/crypto/asset/asset-amount';
import { TON_ASSET } from '../../../entries/crypto/asset/constants';
import { AuthApi, Configuration as TwoFaConfiguration, MessageApi } from '../../../2faApi';
import {
AuthApi,
Configuration as TwoFaConfiguration,
MessageApi,
MessageState
} from '../../../2faApi';
import {
Address,
beginCell,
Cell,
external,
internal,
MessageRelaxed,
storeMessage,
storeMessageRelaxed,
toNano,
external,
MessageRelaxed
toNano
} from '@ton/core';
import { TwoFAEncoder } from '../encoder/two-fa-encoder';
import { AccountsApi, BlockchainApi, EmulationApi } from '../../../tonApiV2';
Expand Down Expand Up @@ -61,10 +66,14 @@ export class TwoFAMessageSender implements ISender {
const closeConfirmModal = this.options.openConfirmModal?.();

lastSearchingMessageId = res.messageId;
const result = Cell.fromBase64(await this.bocByMsgId(res.messageId));

closeConfirmModal?.();
return result;
try {
return Cell.fromBase64(await this.bocByMsgId(res.messageId));
} catch (e) {
console.error(e);
throw e;
} finally {
closeConfirmModal?.();
}
}

public async estimate(outgoing: WalletOutgoingMessage) {
Expand Down Expand Up @@ -156,10 +165,13 @@ export class TwoFAMessageSender implements ISender {
const closeConfirmModal = this.options.openConfirmModal?.();

lastSearchingMessageId = res.messageId;
const result = Cell.fromBase64(await this.bocByMsgId(res.messageId));
closeConfirmModal?.();

return result;
try {
return Cell.fromBase64(await this.bocByMsgId(res.messageId));
} catch (e) {
console.error(e);
} finally {
closeConfirmModal?.();
}
}

public async sendCancelRecovery() {
Expand Down Expand Up @@ -318,22 +330,32 @@ export class TwoFAMessageSender implements ISender {

const maxAttempts = confirmMessageTGTtlMS / timeoutMS;

try {
const result = await new MessageApi(this.api.twoFaApi).getMessageInfo({ id: msgId });
if (!result.extMsg) {
throw new Error('Message not found');
}
if (attempt >= maxAttempts) {
throw new Error('Message was not confirmed in timeout');
}

return result.extMsg;
let result;
try {
result = await new MessageApi(this.api.twoFaApi).getMessageInfo({ id: msgId });
} catch (e) {
console.error(e);
}

if (attempt < maxAttempts) {
await new Promise(resolve => setTimeout(resolve, timeoutMS));
return this.bocByMsgId(msgId, attempt + 1);
} else {
throw e;
if (result) {
if (result.state === MessageState.Failed || result.state === MessageState.Canceled) {
throw new Error('Message was not confirmed');
}

if (result.state === MessageState.Expired) {
throw new Error('Message was not confirmed in timeout');
}

if (result.state === MessageState.Confirmed) {
return result.extMsg!;
}
}

await new Promise(resolve => setTimeout(resolve, timeoutMS));
return this.bocByMsgId(msgId, attempt + 1);
}
}
1 change: 1 addition & 0 deletions packages/locales/src/tonkeeper-web/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@
"PasswordChanged": "Password Changed",
"PasswordDoNotMatch": "Passwords do not match.",
"pinned_jettons": "Pinned",
"please_try_again_later": "Please try again later",
"preferences_aside_dev_menu": "Dev Menu",
"preferences_aside_faq": "FAQ",
"preferences_aside_sign_out": "Sign Out",
Expand Down
1 change: 1 addition & 0 deletions packages/locales/src/tonkeeper-web/ru-RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@
"Password": "Пароль",
"PasswordChanged": "Пароль изменен",
"PasswordDoNotMatch": "Пароли не совпадают.",
"please_try_again_later": "Попробуйте позже",
"preferences_aside_dev_menu": "Функции для разработчиков",
"preferences_aside_faq": "FAQ",
"preferences_aside_sign_out": "Выйти из аккаунта",
Expand Down
16 changes: 16 additions & 0 deletions packages/uikit/src/components/Notification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,14 @@ NotificationOverlay.displayName = 'NotificationOverlay';

export type OnCloseInterceptor = ((closeHandle: () => void) => void) | undefined;

const allNotificationsControl$ = {
closeHandlers: new Set<() => void>()
};

export function closeAllNotifications() {
allNotificationsControl$.closeHandlers.forEach(handler => handler());
}

export const Notification: FC<{
isOpen: boolean;
handleClose: () => void;
Expand Down Expand Up @@ -447,6 +455,14 @@ export const Notification: FC<{
setTimeout(() => setOpen(isOpen));
}, [isOpen]);

useEffect(() => {
allNotificationsControl$.closeHandlers.add(handleClose);

return () => {
allNotificationsControl$.closeHandlers.delete(handleClose);
};
}, [handleClose]);

const sdk = useAppSdk();
const nodeRef = useRef<HTMLDivElement>(null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const TelegramIconStyled = styled(TelegramIcon)`

const Body2Styled = styled(Body2)`
margin-top: 4px;
text-align: center;
color: ${p => p.theme.textSecondary};
`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ const useNftTransferEstimation = (
return BATTERY_SENDER_CHOICE;
}

if (selectedSenderType === 'two_fa') {
return TWO_FA_SENDER_CHOICE;
}

throw new Error(`Unsupported sender type for nft transfer ${selectedSenderType}`);
}, [selectedSenderType, account]);

Expand Down Expand Up @@ -252,7 +256,6 @@ export const ConfirmNftView: FC<{
const onSubmit: React.FormEventHandler<HTMLFormElement> = async e => {
e.stopPropagation();
e.preventDefault();
handleSubmit();
};

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Notification } from '../../Notification';
import { closeAllNotifications, Notification } from '../../Notification';
import styled from 'styled-components';
import { FC, useEffect, useRef } from 'react';
import { useCountdown } from '../../../hooks/useCountDown';
Expand Down Expand Up @@ -102,7 +102,7 @@ export const ConfirmView2FATelegramContent: FC<{

const onHelp = () => {
onClose();
document.getElementById('react-portal-modal-container')?.remove();
closeAllNotifications();
};

return (
Expand Down
8 changes: 6 additions & 2 deletions packages/uikit/src/hooks/blockchain/nft/useEstimateNftLink.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { useQuery } from '@tanstack/react-query';
import { EXTERNAL_SENDER_CHOICE, useGetEstimationSender } from '../useSender';
import { EXTERNAL_SENDER_CHOICE, TWO_FA_SENDER_CHOICE, useGetEstimationSender } from '../useSender';
import { useTonRawTransactionService } from '../useBlockchainService';
import { NFTEncoder } from '@tonkeeper/core/dist/service/ton-blockchain/encoder/nft-encoder';
import { useActiveAccount } from '../../../state/wallet';
import { useToQueryKeyPart } from '../../useToQueryKeyPart';
import { TonEstimation } from '@tonkeeper/core/dist/entries/send';
import { useTwoFAWalletConfig } from '../../../state/two-fa';

export const useEstimateNftLink = (args: { nftAddress: string; linkToAddress: string }) => {
const getSender = useGetEstimationSender(EXTERNAL_SENDER_CHOICE);
const { data: twoFaConfig } = useTwoFAWalletConfig();
const getSender = useGetEstimationSender(
twoFaConfig?.status === 'active' ? TWO_FA_SENDER_CHOICE : EXTERNAL_SENDER_CHOICE
);
const getSenderKey = useToQueryKeyPart(getSender);
const rawTransactionService = useTonRawTransactionService();
const activeAccount = useActiveAccount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ import { useTonRawTransactionService } from '../useBlockchainService';
import { useActiveAccount } from '../../../state/wallet';
import { useQuery } from '@tanstack/react-query';
import { NFTEncoder } from '@tonkeeper/core/dist/service/ton-blockchain/encoder/nft-encoder';
import { EXTERNAL_SENDER_CHOICE, useGetEstimationSender } from '../useSender';
import { EXTERNAL_SENDER_CHOICE, TWO_FA_SENDER_CHOICE, useGetEstimationSender } from '../useSender';
import { useToQueryKeyPart } from '../../useToQueryKeyPart';
import { TonEstimation } from '@tonkeeper/core/dist/entries/send';
import { useTwoFAWalletConfig } from '../../../state/two-fa';

export const useEstimateNftRenew = (args: { nftAddress: string }) => {
const getSender = useGetEstimationSender(EXTERNAL_SENDER_CHOICE);
const { data: twoFaConfig } = useTwoFAWalletConfig();
const getSender = useGetEstimationSender(
twoFaConfig?.status === 'active' ? TWO_FA_SENDER_CHOICE : EXTERNAL_SENDER_CHOICE
);
const getSenderKey = useToQueryKeyPart(getSender);
const rawTransactionService = useTonRawTransactionService();
const activeAccount = useActiveAccount();
Expand Down
Loading

0 comments on commit 36c100c

Please sign in to comment.