1
1
import * as React from 'react' ;
2
- import { useThemeHooks } from '@redocly/theme/core/hooks' ;
3
2
import axios , { AxiosError } from "axios" ;
4
3
import { parse } from "smol-toml" ;
5
4
import { getListEntries } from "./ListTomlFields" ;
@@ -25,8 +24,9 @@ async function validateAndDisplayFields(
25
24
domainToVerify ?: string ,
26
25
filterDisplayedFieldsTo ?: Function ) : Promise < boolean > {
27
26
28
- const { useTranslate } = useThemeHooks ( ) ;
29
- const { translate } = useTranslate ( ) ;
27
+ // Note, apparently this is not an appropriate place
28
+ // to call useThemeHooks for translation.
29
+ // TODO: Find a way to translate the outputs from this tool.
30
30
31
31
// If there's no data, do nothing
32
32
if ( ! fields ) {
@@ -61,7 +61,7 @@ async function validateAndDisplayFields(
61
61
id : headerText ,
62
62
status : {
63
63
icon : {
64
- label : translate ( "WRONG TYPE - SHOULD BE TABLE-ARRAY" ) ,
64
+ label : "WRONG TYPE - SHOULD BE TABLE-ARRAY" ,
65
65
type : "ERROR" ,
66
66
}
67
67
}
@@ -80,12 +80,10 @@ function validateAndDisplayMetadata(
80
80
setLogEntries : React . Dispatch < React . SetStateAction < LogEntryItem [ ] > > ,
81
81
metadata ?: MetadataField ) {
82
82
83
- const { translate } = useTranslate ( )
84
-
85
83
if ( metadata ) {
86
84
const metadataId = 'metadata-log'
87
85
const metadataLogEntry = {
88
- message : translate ( "Metadata section: " ) ,
86
+ message : "Metadata section: " ,
89
87
id : metadataId
90
88
}
91
89
addNewLogEntry ( setLogEntries , metadataLogEntry )
@@ -94,22 +92,22 @@ function validateAndDisplayMetadata(
94
92
if ( Array . isArray ( metadata ) ) {
95
93
updateLogEntry ( setLogEntries , { ...metadataLogEntry , status : {
96
94
icon : {
97
- label : translate ( "WRONG TYPE - SHOULD BE TABLE" ) ,
95
+ label : "WRONG TYPE - SHOULD BE TABLE" ,
98
96
type : "ERROR" ,
99
97
} ,
100
98
} } )
101
99
} else {
102
100
updateLogEntry ( setLogEntries , { ...metadataLogEntry , status : {
103
101
icon : {
104
- label : translate ( "FOUND" ) ,
102
+ label : "FOUND" ,
105
103
type : "SUCCESS" ,
106
104
} ,
107
105
} } )
108
106
109
107
if ( metadata . modified ) {
110
108
const modifiedLogId = 'modified-date-log'
111
109
const modifiedLogEntry = {
112
- message : translate ( "Modified date: " ) ,
110
+ message : "Modified date: " ,
113
111
id : modifiedLogId
114
112
}
115
113
addNewLogEntry ( setLogEntries , modifiedLogEntry )
@@ -123,7 +121,7 @@ function validateAndDisplayMetadata(
123
121
} catch ( e ) {
124
122
updateLogEntry ( setLogEntries , { ...modifiedLogEntry , status : {
125
123
icon : {
126
- label : translate ( "INVALID" ) ,
124
+ label : "INVALID" ,
127
125
type : "ERROR" ,
128
126
} ,
129
127
} } )
@@ -148,10 +146,9 @@ async function parseXRPLToml(
148
146
tomlData ,
149
147
addressToVerify ?: string ,
150
148
domain ?: string ) {
151
- const { translate } = useTranslate ( )
152
149
153
150
const parsingTomlLogEntry : LogEntryItem = {
154
- message : translate ( "Parsing TOML data..." ) ,
151
+ message : "Parsing TOML data..." ,
155
152
id : 'parsing-toml-data-log' ,
156
153
}
157
154
addNewLogEntry ( setLogEntries , parsingTomlLogEntry )
@@ -161,7 +158,7 @@ async function parseXRPLToml(
161
158
parsed = parse ( tomlData )
162
159
updateLogEntry ( setLogEntries , { ...parsingTomlLogEntry , status : {
163
160
icon : {
164
- label : translate ( "SUCCESS" ) ,
161
+ label : "SUCCESS" ,
165
162
type : "SUCCESS" ,
166
163
} ,
167
164
} } )
@@ -177,7 +174,7 @@ async function parseXRPLToml(
177
174
178
175
validateAndDisplayMetadata ( setLogEntries , parsed . METADATA )
179
176
180
- const accountHeader = translate ( "Accounts:" )
177
+ const accountHeader = "Accounts:"
181
178
if ( addressToVerify ) {
182
179
const filterToSpecificAccount = ( entry : AccountFields ) => entry . address === addressToVerify
183
180
const accountFound = await validateAndDisplayFields (
@@ -191,11 +188,11 @@ async function parseXRPLToml(
191
188
if ( accountFound ) {
192
189
// Then share whether the domain / account pair as a whole has been validated
193
190
addNewLogEntry ( setLogEntries , {
194
- message : translate ( 'Account has been found in TOML file and validated.' ) ,
191
+ message : 'Account has been found in TOML file and validated.' ,
195
192
id : statusLogId ,
196
193
status : {
197
194
icon : {
198
- label : translate ( "DOMAIN VALIDATED" ) ,
195
+ label : "DOMAIN VALIDATED" ,
199
196
type : "SUCCESS" ,
200
197
check : true ,
201
198
}
@@ -204,22 +201,22 @@ async function parseXRPLToml(
204
201
} else {
205
202
// We failed to find any entries which match the account we're looking for
206
203
addNewLogEntry ( setLogEntries , {
207
- message : translate ( "Account:" ) ,
204
+ message : "Account:" ,
208
205
id : 'toml-account-entry-log' ,
209
206
status : {
210
207
icon : {
211
- label : translate ( "NOT FOUND" ) ,
208
+ label : "NOT FOUND" ,
212
209
type : "ERROR"
213
210
}
214
211
}
215
212
} )
216
213
217
214
addNewLogEntry ( setLogEntries , {
218
- message : translate ( "Account not found in TOML file. Domain can not be verified." ) ,
215
+ message : "Account not found in TOML file. Domain can not be verified." ,
219
216
id : statusLogId ,
220
217
status : {
221
218
icon : {
222
- label : translate ( "VALIDATION FAILED" ) ,
219
+ label : "VALIDATION FAILED" ,
223
220
type : "ERROR" ,
224
221
}
225
222
}
@@ -228,13 +225,13 @@ async function parseXRPLToml(
228
225
} else {
229
226
// The final validation message is displayed under the validated account since in this case we're
230
227
// verifying a wallet address, not the toml file itself.
231
- await validateAndDisplayFields ( setLogEntries , translate ( accountHeader ) , parsed . ACCOUNTS , domain )
228
+ await validateAndDisplayFields ( setLogEntries , accountHeader , parsed . ACCOUNTS , domain )
232
229
233
230
// We then display the rest of the toml as additional information
234
- await validateAndDisplayFields ( setLogEntries , translate ( "Validators:" ) , parsed . VALIDATORS )
235
- await validateAndDisplayFields ( setLogEntries , translate ( "Principals:" ) , parsed . PRINCIPALS )
236
- await validateAndDisplayFields ( setLogEntries , translate ( "Servers:" ) , parsed . SERVERS )
237
- await validateAndDisplayFields ( setLogEntries , translate ( "Currencies:" ) , parsed . CURRENCIES )
231
+ await validateAndDisplayFields ( setLogEntries , "Validators:" , parsed . VALIDATORS )
232
+ await validateAndDisplayFields ( setLogEntries , "Principals:" , parsed . PRINCIPALS )
233
+ await validateAndDisplayFields ( setLogEntries , "Servers:" , parsed . SERVERS )
234
+ await validateAndDisplayFields ( setLogEntries , "Currencies:" , parsed . CURRENCIES )
238
235
}
239
236
}
240
237
@@ -272,12 +269,10 @@ export async function fetchFile(
272
269
domain : string ,
273
270
accountToVerify ?: string ) {
274
271
275
- const { translate } = useTranslate ( )
276
-
277
272
const url = "https://" + domain + TOML_PATH
278
273
const checkUrlId = `check-url-log`
279
274
const logEntry = {
280
- message : translate ( `Checking ${ url } ...` ) ,
275
+ message : `Checking ${ url } ...` ,
281
276
id : checkUrlId ,
282
277
}
283
278
addNewLogEntry ( setLogEntries , logEntry )
@@ -287,7 +282,7 @@ export async function fetchFile(
287
282
const data : string = response . data
288
283
updateLogEntry ( setLogEntries , { ...logEntry , status : {
289
284
icon : {
290
- label : translate ( "FOUND" ) ,
285
+ label : "FOUND" ,
291
286
type : "SUCCESS" ,
292
287
} ,
293
288
} } )
@@ -298,13 +293,13 @@ export async function fetchFile(
298
293
} catch ( e ) {
299
294
const errorUpdate : LogEntryItem = { ...logEntry , status : {
300
295
icon : {
301
- label : translate ( getHttpErrorCode ( ( e as AxiosError ) ?. status ) ) ,
296
+ label : getHttpErrorCode ( ( e as AxiosError ) ?. status ) ,
302
297
type : "ERROR" ,
303
298
} ,
304
299
followUpMessage : ( < p >
305
- { translate ( "Check if the file is actually hosted at the URL above, " )
306
- + translate ( "check your server's HTTPS settings and certificate, and make sure your server provides the required " ) }
307
- < a href = "xrp-ledger-toml.html#cors-setup" > { translate ( " CORS header." ) } </ a >
300
+ { "Check if the file is actually hosted at the URL above, "
301
+ + "check your server's HTTPS settings and certificate, and make sure your server provides the required " }
302
+ < a href = "xrp-ledger-toml.html#cors-setup" > CORS header.</ a >
308
303
</ p > )
309
304
} }
310
305
updateLogEntry ( setLogEntries , errorUpdate )
@@ -319,15 +314,13 @@ export async function fetchFile(
319
314
function displayDecodedWalletLog (
320
315
setAccountLogEntries : React . Dispatch < React . SetStateAction < LogEntryItem [ ] > > , ) {
321
316
322
- const { translate } = useTranslate ( )
323
-
324
317
const logId = 'decoding-domain-hex'
325
318
addNewLogEntry ( setAccountLogEntries , {
326
- message : translate ( 'Decoding domain hex' ) ,
319
+ message : 'Decoding domain hex' ,
327
320
id : logId ,
328
321
status : {
329
322
icon : {
330
- label : translate ( 'SUCCESS' ) ,
323
+ label : 'SUCCESS' ,
331
324
type : 'SUCCESS' ,
332
325
} ,
333
326
}
@@ -361,13 +354,12 @@ export function fetchWallet(
361
354
accountToVerify : string ,
362
355
socket ?: WebSocket )
363
356
{
364
- const { translate} = useTranslate ( )
365
357
366
358
// Reset the logs
367
359
setAccountLogEntries ( [ ] )
368
360
369
361
const walletLogEntry = {
370
- message : translate ( `Checking domain of account` ) ,
362
+ message : `Checking domain of account` ,
371
363
id : 'check-domain-account' ,
372
364
}
373
365
addNewLogEntry ( setAccountLogEntries , walletLogEntry )
@@ -387,7 +379,7 @@ export function fetchWallet(
387
379
// Defaults to error to simplify logic later on
388
380
let response : LogEntryStatus = {
389
381
icon : {
390
- label : translate ( `ERROR` ) ,
382
+ label : `ERROR` ,
391
383
type : `ERROR` ,
392
384
} ,
393
385
} ;
@@ -398,7 +390,7 @@ export function fetchWallet(
398
390
try {
399
391
response = {
400
392
icon : {
401
- label : translate ( 'SUCCESS' ) ,
393
+ label : 'SUCCESS' ,
402
394
type : 'SUCCESS' ,
403
395
} ,
404
396
}
@@ -408,13 +400,13 @@ export function fetchWallet(
408
400
fetchFile ( setAccountLogEntries , decodedDomain , accountToVerify )
409
401
} catch ( e ) {
410
402
console . log ( e )
411
- response . followUpMessage = < p > { translate ( `Error decoding domain field: ${ data . result . account_data . Domain } ` ) } </ p >
403
+ response . followUpMessage = < p > { `Error decoding domain field: ${ data . result . account_data . Domain } ` } </ p >
412
404
}
413
405
} else {
414
- response . followUpMessage = < p > { translate ( "Make sure the account has the Domain field set." ) } </ p >
406
+ response . followUpMessage = < p > { "Make sure the account has the Domain field set." } </ p >
415
407
}
416
408
} else {
417
- response . followUpMessage = < p > { translate ( "Make sure you are entering a valid XRP Ledger address." ) } </ p >
409
+ response . followUpMessage = < p > { "Make sure you are entering a valid XRP Ledger address." } </ p >
418
410
}
419
411
updateLogEntry ( setAccountLogEntries , { ...walletLogEntry , status : response } )
420
412
} catch {
0 commit comments