-
Notifications
You must be signed in to change notification settings - Fork 0
/
wallet.service.js
43 lines (41 loc) · 999 Bytes
/
wallet.service.js
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
import { Chain, Network, Wallet } from 'mintbase'
export class WalletService {
async walletProvider(data) {
const apiKey = data.apiKey
const netVal =
data.network === 'testnet' ? Network.testnet : Network.mainnet
console.log('apikey', apiKey)
console.log('Network', netVal)
async function initWallet() {
const { data: walletData, error } = await new Wallet().init({
networkName: netVal,
chain: Chain.near,
apiKey,
})
if (error) {
return 'no data'
}
let details
const { wallet, isConnected } = walletData
if (isConnected) {
try {
const { data } = await wallet.details()
details = data
} catch (err) {
return err
}
}
return {
wallet,
isConnected,
details,
}
}
const { wallet, details, isConnected } = await initWallet()
return {
wallet,
isConnected,
details,
}
}
}