@@ -6,7 +6,6 @@ function getNet() {
6
6
let net
7
7
if ( document . getElementById ( "tn" ) . checked ) net = "wss://s.altnet.rippletest.net:51233/"
8
8
if ( document . getElementById ( "dn" ) . checked ) net = "wss://s.devnet.rippletest.net:51233/"
9
- const client = new xrpl . Client ( net )
10
9
return net
11
10
} // End of getNet()
12
11
@@ -18,23 +17,36 @@ async function getAccount() {
18
17
let net = getNet ( )
19
18
const client = new xrpl . Client ( net )
20
19
await client . connect ( )
21
- let results = `\nConnected to ${ net } .`
22
- let faucetHost = null
23
- const my_wallet = ( await client . fundWallet ( null , { faucetHost} ) ) . wallet
24
- const newAccount = [ my_wallet . address , my_wallet . seed ]
25
- return ( newAccount )
26
- client . disconnect ( )
20
+ resultField . value = `===Getting Account===\n\nConnected to ${ net } .`
21
+ try {
22
+ let faucetHost = null
23
+ const my_wallet = ( await client . fundWallet ( null , { faucetHost} ) ) . wallet
24
+ const newAccount = [ my_wallet . address , my_wallet . seed ]
25
+ return ( newAccount )
26
+ }
27
+ catch ( error ) {
28
+ console . error ( '===Error getting account:' , error ) ;
29
+ results += `\nError: ${ error . message } \n`
30
+ resultField . value = results
31
+ throw error ; // Re-throw the error to be handled by the caller
32
+ }
33
+ finally {
34
+ // Disconnect from the client
35
+ await client . disconnect ( ) ;
36
+ }
27
37
} // End of getAccount()
28
38
29
39
async function getNewAccount1 ( ) {
30
- account1address . value = "Getting new account."
40
+ account1address . value = "=== Getting new account. ===\n\n"
41
+ account1seed . value = ""
31
42
const accountInfo = await getAccount ( )
32
43
account1address . value = accountInfo [ 0 ]
33
44
account1seed . value = accountInfo [ 1 ]
34
45
}
35
46
36
47
async function getNewAccount2 ( ) {
37
- account2address . value = "Getting new account."
48
+ account2address . value = "=== Getting new account. ===\n\n"
49
+ account2seed . value = ""
38
50
const accountInfo = await getAccount ( )
39
51
account2address . value = accountInfo [ 0 ]
40
52
account2seed . value = accountInfo [ 1 ]
@@ -48,13 +60,26 @@ async function getAccountFromSeed(my_seed) {
48
60
const net = getNet ( )
49
61
const client = new xrpl . Client ( net )
50
62
await client . connect ( )
51
- let results = '\nConnected, finding wallet.\n'
63
+ let results = '===Finding wallet.===\n \n'
52
64
resultField . value = results
53
- const wallet = xrpl . Wallet . fromSeed ( my_seed )
54
- // ----------------------Populate the fields for left and right accounts.
55
- const address = wallet . address
56
- client . disconnect ( )
57
- return ( address )
65
+ try {
66
+ const wallet = xrpl . Wallet . fromSeed ( my_seed )
67
+ const address = wallet . address
68
+ results += "===Wallet found.===\n\n"
69
+ results += "Account address: " + address + "\n\n"
70
+ resultField . value = results
71
+ return ( address )
72
+ }
73
+ catch ( error ) {
74
+ console . error ( '===Error getting account from seed:' , error ) ;
75
+ results += `\nError: ${ error . message } \n`
76
+ resultField . value = results
77
+ throw error ; // Re-throw the error to be handled by the caller
78
+ }
79
+ finally {
80
+ // Disconnect from the client
81
+ await client . disconnect ( ) ;
82
+ }
58
83
} // End of getAccountFromSeed()
59
84
60
85
// *****************************************************
@@ -120,15 +145,32 @@ function populate2() {
120
145
}
121
146
122
147
// *******************************************************
123
- // **************** Get Xrp Balance *********************
148
+ // **************** Get XRP Balance *********************
124
149
// *******************************************************
125
150
126
151
async function getXrpBalance ( ) {
127
152
const net = getNet ( )
128
153
const client = new xrpl . Client ( net )
129
154
await client . connect ( )
130
- xrpBalanceField . value = await client . getXrpBalance ( accountAddressField . value )
131
- client . disconnect ( )
155
+ let results = `\n===Getting XRP balance...===\n\n`
156
+ resultField . value = results
157
+ try {
158
+ const wallet = xrpl . Wallet . fromSeed ( accountSeedField . value )
159
+ const balance = await client . getXrpBalance ( wallet . address )
160
+ results += accountNameField . value + " current XRP balance: " + balance + "\n\n"
161
+ xrpBalanceField . value = await client . getXrpBalance ( accountAddressField . value )
162
+ resultField . value = results
163
+ }
164
+ catch ( error ) {
165
+ console . error ( 'Error getting XRP balance:' , error ) ;
166
+ results += `\nError: ${ error . message } \n`
167
+ resultField . value = results
168
+ throw error ; // Re-throw the error to be handled by the caller
169
+ }
170
+ finally {
171
+ // Disconnect from the client
172
+ await client . disconnect ( ) ;
173
+ }
132
174
} // End of getXrpBalance()
133
175
134
176
// *******************************************************
@@ -138,21 +180,29 @@ async function getXrpBalance() {
138
180
async function getTokenBalance ( ) {
139
181
let net = getNet ( )
140
182
const client = new xrpl . Client ( net )
141
- results = 'Connecting to ' + getNet ( ) + '....'
142
- resultField . value = results
143
183
await client . connect ( )
144
- results += '\nConnected.'
145
- resultField . value = results
146
- const wallet = xrpl . Wallet . fromSeed ( accountSeedField . value )
147
- results = "\nGetting account balance...\n"
148
- const balance = await client . request ( {
149
- command : "gateway_balances" ,
150
- account : wallet . address ,
151
- ledger_index : "validated" ,
152
- } )
153
- results += JSON . stringify ( balance . result , null , 2 )
154
- resultField . value = results
155
- xrpBalanceField . value = ( await client . getXrpBalance ( wallet . address ) )
156
- client . disconnect ( )
184
+ let results = `===Connected to ${ net } .===\n===Getting account token balance...===\n\n`
185
+ resultField . value += results
186
+ try {
187
+ const wallet = xrpl . Wallet . fromSeed ( accountSeedField . value )
188
+ const balance = await client . request ( {
189
+ command : "gateway_balances" ,
190
+ account : wallet . address ,
191
+ ledger_index : "validated" ,
192
+ } )
193
+ results = accountNameField . value + "\'s token balance(s): " + JSON . stringify ( balance . result , null , 2 ) + "\n"
194
+ resultField . value += results
195
+ xrpBalanceField . value = ( await client . getXrpBalance ( wallet . address ) )
196
+ }
197
+ catch ( error ) {
198
+ console . error ( 'Error getting token balance:' , error ) ;
199
+ results = `\nError: ${ error . message } \n`
200
+ resultField . value += results
201
+ throw error ; // Re-throw the error to be handled by the caller
202
+ }
203
+ finally {
204
+ // Disconnect from the client
205
+ await client . disconnect ( ) ;
206
+ }
157
207
} // End of getTokenBalance()
158
208
0 commit comments