Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iPad Updates #331

Merged
merged 21 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apps/tablet/ios/App/App/App.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
<dict>
<key>aps-environment</key>
<string>development</string>
<key>com.apple.developer.associated-domains</key>
<array>
<string>applinks:app.tonkeeper.com</string>
</array>
<key>keychain-access-groups</key>
<array>
<string>$(AppIdentifierPrefix)com.tonapps.tonkeeperpro</string>
Expand Down
4 changes: 4 additions & 0 deletions apps/tablet/ios/App/App/AppRelease.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
<dict>
<key>aps-environment</key>
<string>development</string>
<key>com.apple.developer.associated-domains</key>
<array>
<string>applinks:app.tonkeeper.com</string>
</array>
<key>keychain-access-groups</key>
<array>
<string>$(AppIdentifierPrefix)com.tonapps.tonkeeperpro</string>
Expand Down
10 changes: 5 additions & 5 deletions apps/tablet/ios/App/App/GoogleService-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
<plist version="1.0">
<dict>
<key>API_KEY</key>
<string>AIzaSyBfuV_ymekwDZwlD6TkvKB5292oYd96dbM</string>
<string>AIzaSyCpV-zBAgyo22ua1DEZtER8PgUg862hK-c</string>
<key>GCM_SENDER_ID</key>
<string>488327313434</string>
<string>695609596302</string>
<key>PLIST_VERSION</key>
<string>1</string>
<key>BUNDLE_ID</key>
<string>com.tonapps.tonkeeperpro</string>
<key>PROJECT_ID</key>
<string>tonkeeper-web</string>
<string>tonkeeper-3b1dc</string>
<key>STORAGE_BUCKET</key>
<string>tonkeeper-web.appspot.com</string>
<string>tonkeeper-3b1dc.appspot.com</string>
<key>IS_ADS_ENABLED</key>
<false></false>
<key>IS_ANALYTICS_ENABLED</key>
Expand All @@ -25,6 +25,6 @@
<key>IS_SIGNIN_ENABLED</key>
<true></true>
<key>GOOGLE_APP_ID</key>
<string>1:488327313434:ios:85fdb7916fec750461f9a3</string>
<string>1:695609596302:ios:54607bbb498c208809acdf</string>
</dict>
</plist>
4 changes: 4 additions & 0 deletions apps/tablet/ios/App/App/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,9 @@
<string>dev-pro.tonconsole.com</string>
<string>pro.tonconsole.com</string>
</array>
<key>NSUserActivityTypes</key>
<array>
<string>NSUserActivityTypeBrowsingWeb</string>
</array>
</dict>
</plist>
1 change: 1 addition & 0 deletions apps/tablet/ios/App/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def capacitor_pods
pod 'CapacitorCamera', :path => '../../node_modules/@capacitor/camera'
pod 'CapacitorClipboard', :path => '../../node_modules/@capacitor/clipboard'
pod 'CapacitorDevice', :path => '../../node_modules/@capacitor/device'
pod 'CapacitorHaptics', :path => '../../node_modules/@capacitor/haptics'
pod 'CapacitorPreferences', :path => '../../node_modules/@capacitor/preferences'
pod 'CapacitorPushNotifications', :path => '../../node_modules/@capacitor/push-notifications'
pod 'CapacitorSplashScreen', :path => '../../node_modules/@capacitor/splash-screen'
Expand Down
8 changes: 7 additions & 1 deletion apps/tablet/ios/App/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ PODS:
- CapacitorCordova (6.2.0)
- CapacitorDevice (6.0.2):
- Capacitor
- CapacitorHaptics (6.0.2):
- Capacitor
- CapacitorPreferences (6.0.3):
- Capacitor
- CapacitorPushNotifications (6.0.3):
Expand Down Expand Up @@ -77,6 +79,7 @@ DEPENDENCIES:
- "CapacitorClipboard (from `../../node_modules/@capacitor/clipboard`)"
- "CapacitorCordova (from `../../node_modules/@capacitor/ios`)"
- "CapacitorDevice (from `../../node_modules/@capacitor/device`)"
- "CapacitorHaptics (from `../../node_modules/@capacitor/haptics`)"
- "CapacitorPreferences (from `../../node_modules/@capacitor/preferences`)"
- "CapacitorPushNotifications (from `../../node_modules/@capacitor/push-notifications`)"
- "CapacitorSplashScreen (from `../../node_modules/@capacitor/splash-screen`)"
Expand Down Expand Up @@ -106,6 +109,8 @@ EXTERNAL SOURCES:
:path: "../../node_modules/@capacitor/ios"
CapacitorDevice:
:path: "../../node_modules/@capacitor/device"
CapacitorHaptics:
:path: "../../node_modules/@capacitor/haptics"
CapacitorPreferences:
:path: "../../node_modules/@capacitor/preferences"
CapacitorPushNotifications:
Expand All @@ -120,6 +125,7 @@ SPEC CHECKSUMS:
CapacitorClipboard: 4443c3cdb7c77b1533dfe3ff0f9f7756aa8579df
CapacitorCordova: b33e7f4aa4ed105dd43283acdd940964374a87d9
CapacitorDevice: 9efd479d71d1baad74b75df531184c3f730eaa48
CapacitorHaptics: 4fc15afe22b123d093e6ace24d95e8e3b1f261b9
CapacitorPreferences: f3eadae2369ac3ab8e21743a2959145b0d1286a3
CapacitorPushNotifications: 9b178e010634d2f7bfca97b81478503463f86b6c
CapacitorSplashScreen: fd8bf1bf9081d9aa8817b7cd37d740d1bdaf2fb2
Expand All @@ -132,6 +138,6 @@ SPEC CHECKSUMS:
nanopb: fad817b59e0457d11a5dfbde799381cd727c1275
PromisesObjC: f5707f49cb48b9636751c5b2e7d227e43fba9f47

PODFILE CHECKSUM: f9d707744c97cd8f502d129ac50e6f2a2abd9aca
PODFILE CHECKSUM: 909da498bd070920c1661b81df41f840cf5ecf80

COCOAPODS: 1.16.2
3 changes: 2 additions & 1 deletion apps/tablet/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tonkeeper/tablet",
"version": "3.0.0",
"version": "3.1.0",
"license": "Apache-2.0",
"description": "Your tablet wallet on The Open Network",
"type": "module",
Expand All @@ -26,6 +26,7 @@
"@capacitor/clipboard": "^6.0.1",
"@capacitor/core": "latest",
"@capacitor/device": "^6.0.2",
"@capacitor/haptics": "^6.0.2",
"@capacitor/ios": "^6.1.2",
"@capacitor/preferences": "^6.0.2",
"@capacitor/push-notifications": "^6.0.3",
Expand Down
33 changes: 24 additions & 9 deletions apps/tablet/src/libs/appSdk.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import {
BaseApp,
CookieService,
IAppSdk,
KeychainPassword,
TouchId,
CookieService, NotificationService
NotificationService,
TouchId
} from "@tonkeeper/core/dist/AppSdk";
import packageJson from '../../package.json';
import { TabletStorage } from './storage';
import { Clipboard } from '@capacitor/clipboard';
import { getWindow } from './utils';
import packageJson from "../../package.json";
import { TabletStorage } from "./storage";
import { Clipboard } from "@capacitor/clipboard";
import { getWindow } from "./utils";
import { Biometric, SecureStorage } from "./plugins";
import { CapacitorCookies } from "@capacitor/core";
import { Device } from '@capacitor/device';
import { Device } from "@capacitor/device";
import { Haptics, NotificationType } from "@capacitor/haptics";

export class KeychainTablet implements KeychainPassword {
setPassword = async (publicKey: string, mnemonic: string) => {
Expand All @@ -36,6 +38,8 @@ export class CookieTablet implements CookieService {
}

export class TouchIdTablet implements TouchId {
constructor(private alert: (text: string) => void) { }

canPrompt = async () => {
try {
const result = await Biometric.canPrompt();
Expand All @@ -47,7 +51,14 @@ export class TouchIdTablet implements TouchId {
};

prompt = async (reason: (lang: string) => string) => {
return Biometric.prompt(reason('en'));
try {
return await Biometric.prompt(reason('en'));
} catch (e) {
if (e && typeof e === 'object' && 'message' in e && typeof e.message === 'string') {
this.alert(e.message);
}
throw e;
}
};
}

Expand All @@ -61,7 +72,7 @@ export class TabletAppSdk extends BaseApp implements IAppSdk {
*/
notifications: NotificationService | undefined = undefined;

touchId = new TouchIdTablet();
touchId = new TouchIdTablet(this.topMessage.bind(this));

constructor() {
super(new TabletStorage());
Expand All @@ -79,6 +90,10 @@ export class TabletAppSdk extends BaseApp implements IAppSdk {
version = packageJson.version ?? 'Unknown';

targetEnv = TABLET_APPLICATION_ID;

hapticNotification = (type: 'success' | 'error') => {
return Haptics.notification({type: type === 'success' ? NotificationType.Success : NotificationType.Error});
};
}

export const getTabletOS = async ()=> {
Expand Down
4 changes: 2 additions & 2 deletions apps/tablet/src/libs/tabletNotifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ export class TabletNotifications implements NotificationService {
await this.storage.set(AppKey.NOTIFICATIONS, records);
}
async subscribeTonConnect() {
throw new Error('Method not supported.');
// TODO
}
async unsubscribeTonConnect() {
throw new Error('Method not supported.');
// TODO
}
async subscribed(address: string) {
const records = await this.getRecords();
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"sdk": "npm-run-all -p generate:*",
"generate:sdkV2": "rm -fr src/tonApiV2 && docker build -f resource/Dockerfile.apiV2 . -t tonapisdkv2 && docker run --rm --user=$(id -u):$(id -g) -v \"$PWD\":/local tonapisdkv2",
"generate:tronApi": "rm -fr src/tronApi && docker build -f resource/Dockerfile.tronApi . -t tronapisdk && docker run --rm --user=$(id -u):$(id -g) -v \"$PWD\":/local tronapisdk",
"generate:tonConsoleApi": "rm -r ./src/tonConsoleApi || true && npx openapi-typescript-codegen --input 'https://raw.githubusercontent.com/tonkeeper/tonconsole_backend/dev/swagger.yaml?token=GHSAT0AAAAAACKHFPNI4HJL4Q4RIAYDUQ3MZPAKM2A' --output ./src/tonConsoleApi",
"generate:tonConsoleApi": "rm -r ./src/tonConsoleApi || true && npx openapi-typescript-codegen --input 'https://raw.githubusercontent.com/tonkeeper/tonconsole_backend/refs/heads/main/swagger.yaml?token=GHSAT0AAAAAACJYQUOCGQXJBM2BFNOB6XREZ2ZZZCA' --output ./src/tonConsoleApi",
"generate:swapsApi": "rm -r ./src/swapsApi || true && npx openapi-typescript-codegen --input 'https://raw.githubusercontent.com/tonkeeper/swaps-backend/master/swagger.yaml?token=GHSAT0AAAAAACJYQUODBKR67AB7WULZBFWEZSUUGFQ' --output ./src/swapsApi",
"generate:batteryApi": "rm -fr ./src/batteryApi && docker build -f resource/Dockerfile.batteryApi . -t batteryapi && docker run --rm --user=$(id -u):$(id -g) -v \"$PWD\":/local batteryapi",
"build:pkg": "yarn build"
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/Keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export enum AppKey {
USER_ID = 'user_id',
PRO = 'pro_state',
PRO_BACKUP = 'pro_backup',
PRO_AUTH_TOKEN = 'pro_auth_token',

SIGNER_MESSAGE = 'signer_message',
SWAP_CUSTOM_ASSETS = 'swap_custom_assets',
Expand Down
56 changes: 38 additions & 18 deletions packages/core/src/service/proService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
FiatCurrencies as FiatCurrenciesGenerated,
InvoiceStatus,
InvoicesInvoice,
Lang,
ProServiceDashboardCellAddress,
ProServiceDashboardCellNumericCrypto,
ProServiceDashboardCellNumericFiat,
Expand All @@ -44,9 +43,12 @@ export const getBackupState = async (storage: IStorage) => {
return backup ?? toEmptySubscription();
};

export const getProState = async (storage: IStorage): Promise<ProState> => {
export const getProState = async (
authTokenService: ProAuthTokenService,
storage: IStorage
): Promise<ProState> => {
try {
return await loadProState(storage);
return await loadProState(authTokenService, storage);
} catch (e) {
console.error(e);
return {
Expand Down Expand Up @@ -81,7 +83,16 @@ export const walletVersionFromProServiceDTO = (value: string) => {
}
};

export const loadProState = async (storage: IStorage): Promise<ProState> => {
export type ProAuthTokenService = {
attachToken: () => Promise<void>;
onTokenUpdated: (token: string | null) => Promise<void>;
};

const loadProState = async (
authService: ProAuthTokenService,
storage: IStorage
): Promise<ProState> => {
await authService.attachToken();
const user = await ProServiceService.proServiceGetUserInfo();

let authorizedWallet: ProStateWallet | null = null;
Expand Down Expand Up @@ -147,16 +158,8 @@ export const loadProState = async (storage: IStorage): Promise<ProState> => {
};
};

export const checkAuthCookie = async () => {
try {
await ProServiceService.proServiceVerify();
return true;
} catch (e) {
return false;
}
};

export const authViaTonConnect = async (
authService: ProAuthTokenService,
api: APIConfig,
wallet: TonWalletStandard,
signProof: (bufferToSing: Buffer) => Promise<Uint8Array>
Expand Down Expand Up @@ -187,13 +190,17 @@ export const authViaTonConnect = async (
if (!result.ok) {
throw new Error('Unable to authorize');
}

await authService.onTokenUpdated(result.auth_token);
};

export const logoutTonConsole = async () => {
export const logoutTonConsole = async (authService: ProAuthTokenService) => {
const result = await ProServiceService.proServiceLogout();
if (!result.ok) {
throw new Error('Unable to logout');
}

await authService.onTokenUpdated(null);
};

export const getProServiceTiers = async (lang?: Language | undefined, promoCode?: string) => {
Expand Down Expand Up @@ -237,9 +244,9 @@ export const createRecipient = async (
return [recipient, asset];
};

export const retryProService = async (storage: IStorage) => {
export const retryProService = async (authService: ProAuthTokenService, storage: IStorage) => {
for (let i = 0; i < 10; i++) {
const state = await getProState(storage);
const state = await getProState(authService, storage);
if (state.subscription.valid) {
return;
}
Expand All @@ -260,12 +267,20 @@ export const waitProServiceInvoice = async (invoice: InvoicesInvoice) => {
} while (updated.status === InvoiceStatus.PENDING);
};

export async function startProServiceTrial(botId: string, lang?: string) {
export async function startProServiceTrial(
authService: ProAuthTokenService,
botId: string,
lang?: string
) {
const tgData = await loginViaTG(botId, lang);
if (!tgData) {
return false;
}
return (await ProServiceService.proServiceTrial(tgData)).ok;
const result = await ProServiceService.proServiceTrial(tgData);

await authService.onTokenUpdated(result.auth_token);

return result.ok;
}

export async function getDashboardColumns(lang?: string): Promise<DashboardColumn[]> {
Expand All @@ -283,6 +298,11 @@ export async function getDashboardColumns(lang?: string): Promise<DashboardColum
}));
}

enum Lang {
EN = 'en',
RU = 'ru'
}

export async function getDashboardData(
query: {
accounts: string[];
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/tonConsoleApi/core/ApiError.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* generated using openapi-typescript-codegen -- do not edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/tonConsoleApi/core/ApiRequestOptions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* generated using openapi-typescript-codegen -- do not edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/tonConsoleApi/core/ApiResult.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* generated using openapi-typescript-codegen -- do not edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/tonConsoleApi/core/CancelablePromise.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* generated using openapi-typescript-codegen -- do not edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
Expand Down Expand Up @@ -85,9 +85,9 @@ export class CancelablePromise<T> implements Promise<T> {
});
}

get [Symbol.toStringTag]() {
return "Cancellable Promise";
}
get [Symbol.toStringTag]() {
return "Cancellable Promise";
}

public then<TResult1 = T, TResult2 = never>(
onFulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/tonConsoleApi/core/OpenAPI.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* generated using openapi-typescript-codegen -- do not edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
Expand Down
Loading
Loading