@@ -97,21 +97,21 @@ async function registerAccount(username, password, inviteCode, salt, enableSessi
97
97
const nodeService = new NodeApiHttpClient ( CONFIG . NODE_BASE_URL ) ;
98
98
99
99
// Check if account already exists
100
+ let accountInfo ;
100
101
try {
101
102
const response = await fetch ( `${ CONFIG . WALLET_API_BASE_URL } /v1/indexer/contract/${ CONFIG . WALLET_CONTRACT_NAME } /account/${ username } ` ) ;
102
-
103
103
if ( ! response . ok ) {
104
104
throw new Error ( `Failed to check account existence: ${ response . statusText } ` ) ;
105
105
}
106
-
107
- const accountInfo = await response . json ( ) ;
108
-
109
- if ( accountInfo ) {
110
- throw new Error ( `Account with username "${ username } " already exists.` ) ;
111
- }
106
+ accountInfo = await response . json ( ) ;
112
107
} catch ( error ) {
113
108
// If error, assume account does not exist and continue
114
- console . log ( "Account does not exist, proceeding with registration..." ) ;
109
+ console . log ( `Account ${ username } does not exist, proceeding with registration...` ) ;
110
+ }
111
+
112
+ if ( accountInfo ) {
113
+ console . log ( `Account ${ username } already exists` ) ;
114
+ return { success : true , wallet : accountInfo } ;
115
115
}
116
116
117
117
// Validate password
@@ -178,7 +178,7 @@ async function registerAccount(username, password, inviteCode, salt, enableSessi
178
178
console . log ( `Blob transaction hash: ${ txHash } ` ) ;
179
179
180
180
// Send the actual blob transaction
181
- console . log ( "Sending blob transaction..." , blobTx ) ;
181
+ console . log ( "Sending blob transaction..." ) ;
182
182
await nodeService . sendBlobTx ( blobTx ) ;
183
183
console . log ( "Blob transaction sent successfully" ) ;
184
184
@@ -259,18 +259,20 @@ async function transferFunds(username, password, amount, token, destination) {
259
259
const identity = `${ username } @${ CONFIG . WALLET_CONTRACT_NAME } ` ;
260
260
const salted_password = `${ password } :${ accountInfo . salt } ` ;
261
261
262
-
263
262
// Check that account has enough balance
264
263
console . log ( "Checking balance..." ) ;
264
+ let balance ;
265
265
try {
266
- const balance = await indexerService . get ( `v1/indexer/contract/${ token } /balance/${ identity } ` , "Checking balance" ) ;
267
- console . log ( "Balance..." , balance ) ;
268
- if ( balance < parsedAmount ) {
269
- throw new Error ( `Account "${ username } " does not have enough balance to transfer ${ amount } ${ token } ` ) ;
270
- }
266
+ const result = await indexerService . get ( `v1/indexer/contract/${ token } /balance/${ identity } ` , "Checking balance" ) ;
267
+ balance = result . balance ;
271
268
} catch ( error ) {
272
269
throw new Error ( `Failed to get balance: ${ error . message } . User might have no balance for this token.` ) ;
273
270
}
271
+ console . log ( `Balance for ${ username } is` , balance ) ;
272
+
273
+ if ( balance < parsedAmount ) {
274
+ throw new Error ( `Account "${ username } " does not have enough balance to transfer ${ amount } ${ token } ` ) ;
275
+ }
274
276
275
277
// Create blobs for transfer
276
278
console . log ( "Creating transfer blobs..." ) ;
@@ -289,7 +291,7 @@ async function transferFunds(username, password, amount, token, destination) {
289
291
console . log ( `Blob transaction hash: ${ txHash } ` ) ;
290
292
291
293
// Send the actual blob transaction
292
- console . log ( "Sending blob transaction..." , blobTx ) ;
294
+ console . log ( "Sending blob transaction..." ) ;
293
295
await nodeService . sendBlobTx ( blobTx ) ;
294
296
console . log ( "Blob transaction sent successfully" ) ;
295
297
0 commit comments