From e889feb9bb21f8857f7f7000e3c68d0898d3b46c Mon Sep 17 00:00:00 2001 From: Behrang Norouzinia Date: Mon, 9 Oct 2023 17:05:30 +0330 Subject: [PATCH] Add TWA return url and activate redirecting to wallet --- src/Model.ts | 24 +++++++++++++++++++----- src/main.tsx | 8 -------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/Model.ts b/src/Model.ts index a522871..42f030b 100644 --- a/src/Model.ts +++ b/src/Model.ts @@ -111,11 +111,20 @@ export class Model { localStorage.theme === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches) + document.onvisibilitychange = () => { + if (document.hidden) { + this.pause() + } else { + this.resume() + } + } + this.initTonConnect(buttonRootId) autorun(() => { this.connectTonAccess() }) + autorun(() => { void this.readLastBlock() }) @@ -502,11 +511,16 @@ export class Model { ], } const tonBalance = this.tonBalance - void this.tonConnectUI.sendTransaction(tx).then(() => { - this.setAmount('') - this.setWaitForTransaction('wait') - return this.checkIfBalanceChanged(tonBalance, 1) - }) + void this.tonConnectUI + .sendTransaction(tx, { + skipRedirectToWallet: 'never', + twaReturnUrl: 'https://t.me/HipoFinanceBot', + }) + .then(() => { + this.setAmount('') + this.setWaitForTransaction('wait') + return this.checkIfBalanceChanged(tonBalance, 1) + }) } } diff --git a/src/main.tsx b/src/main.tsx index 5a24964..f239130 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -8,14 +8,6 @@ import './index.css' const model = new Model('testnet') model.init('ton-connect-button') -document.onvisibilitychange = () => { - if (document.hidden) { - model.pause() - } else { - model.resume() - } -} - ReactDOM.createRoot(document.querySelector('#root') ?? document.body).render(