Skip to content

Commit

Permalink
Add TWA return url and activate redirecting to wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
behrang committed Oct 9, 2023
1 parent 12b0125 commit e889feb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
24 changes: 19 additions & 5 deletions src/Model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
Expand Down Expand Up @@ -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)
})
}
}

Expand Down
8 changes: 0 additions & 8 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<React.StrictMode>
<App model={model} />
Expand Down

0 comments on commit e889feb

Please sign in to comment.