forked from TxnLab/use-wallet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
70 lines (62 loc) · 1.86 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import './style.css'
import typescriptLogo from './typescript.svg'
import viteLogo from '/vite.svg'
import { NetworkId, WalletId, WalletManager } from '@txnlab/use-wallet'
import { ActiveNetwork } from './ActiveNetwork'
import { WalletComponent } from './WalletComponent'
const walletManager = new WalletManager({
wallets: [
WalletId.DEFLY,
WalletId.DEFLY_WEB,
WalletId.EXODUS,
WalletId.PERA,
{
id: WalletId.WALLETCONNECT,
options: { projectId: 'fcfde0713d43baa0d23be0773c80a72b' }
},
{
id: WalletId.BIATEC,
options: { projectId: 'fcfde0713d43baa0d23be0773c80a72b' }
},
WalletId.KMD,
WalletId.KIBISIS,
WalletId.LUTE,
{
id: WalletId.MAGIC,
options: { apiKey: 'pk_live_D17FD8D89621B5F3' }
},
WalletId.MNEMONIC
],
defaultNetwork: NetworkId.TESTNET
})
const appDiv = document.querySelector<HTMLDivElement>('#app')
appDiv!.innerHTML = `
<div>
<a href="https://vitejs.dev" target="_blank">
<img src="${viteLogo}" class="logo" alt="Vite logo" />
</a>
<a href="https://www.typescriptlang.org/" target="_blank">
<img src="${typescriptLogo}" class="logo vanilla" alt="TypeScript logo" />
</a>
<h1>@txnlab/use-wallet</h1>
</div>
`
const activeNetwork = new ActiveNetwork(walletManager)
appDiv?.appendChild(activeNetwork.element)
const walletComponents = walletManager.wallets.map(
(wallet) => new WalletComponent(wallet, walletManager)
)
walletComponents.forEach((walletComponent) => {
appDiv?.appendChild(walletComponent.element)
})
document.addEventListener('DOMContentLoaded', async () => {
try {
await walletManager.resumeSessions()
} catch (error) {
console.error('[App] Error resuming sessions:', error)
}
})
// Cleanup
window.addEventListener('beforeunload', () => {
walletComponents.forEach((walletComponent) => walletComponent.destroy())
})