-
Notifications
You must be signed in to change notification settings - Fork 5
/
connector.ts
40 lines (37 loc) · 1.33 KB
/
connector.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
import TonConnect, { isWalletInfoRemote } from '@tonconnect/sdk';
import { FSStorage } from './storage';
import path from 'path';
import qrcode from 'qrcode-terminal';
const storagePath = path.join(process.cwd(), 'temp', 'ton-connect.json');
export async function getConnector(): Promise<TonConnect> {
const connector = new TonConnect({
manifestUrl:
'https://raw.githubusercontent.com/ton-defi-org/tonconnect-manifest-temp/main/tonconnect-manifest.json',
storage: new FSStorage(storagePath),
});
await connector.restoreConnection();
if (connector.connected) {
return connector;
}
const walletsList = await connector.getWallets();
const remoteWalletsList = walletsList.filter(isWalletInfoRemote);
const walletInfo = remoteWalletsList.find((wallet) => wallet.appName === 'tonkeeper');
const url = connector.connect({
universalLink: walletInfo!.universalLink,
bridgeUrl: walletInfo!.bridgeUrl,
});
qrcode.generate(url, { small: true });
console.log(url);
connector.onStatusChange((wallet) => {
if (wallet) {
console.log(wallet);
}
});
return new Promise<TonConnect>((resolve) => {
connector.onStatusChange((wallet) => {
if (wallet) {
resolve(connector);
}
});
});
}