Skip to content

Commit bb0c6dc

Browse files
authored
Merge pull request #2878 from XRPLF/fix_checks_and_checker
Fix TOML checker and redundant Use Checks landing file
2 parents 0f1cb9a + ac042e9 commit bb0c6dc

File tree

2 files changed

+37
-63
lines changed

2 files changed

+37
-63
lines changed

@l10n/ja/docs/tutorials/how-tos/use-specialized-payment-types/use-checks/use-checks.md

Lines changed: 0 additions & 18 deletions
This file was deleted.

resources/dev-tools/toml-checker/ValidateTomlSteps.tsx

Lines changed: 37 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as React from 'react';
2-
import { useThemeHooks } from '@redocly/theme/core/hooks';
32
import axios, { AxiosError } from "axios";
43
import { parse } from "smol-toml";
54
import { getListEntries } from "./ListTomlFields";
@@ -25,8 +24,9 @@ async function validateAndDisplayFields(
2524
domainToVerify?: string,
2625
filterDisplayedFieldsTo?: Function): Promise<boolean> {
2726

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.
3030

3131
// If there's no data, do nothing
3232
if(!fields) {
@@ -61,7 +61,7 @@ async function validateAndDisplayFields(
6161
id: headerText,
6262
status: {
6363
icon: {
64-
label: translate("WRONG TYPE - SHOULD BE TABLE-ARRAY"),
64+
label: "WRONG TYPE - SHOULD BE TABLE-ARRAY",
6565
type: "ERROR",
6666
}
6767
}
@@ -80,12 +80,10 @@ function validateAndDisplayMetadata(
8080
setLogEntries: React.Dispatch<React.SetStateAction<LogEntryItem[]>>,
8181
metadata?: MetadataField) {
8282

83-
const { translate } = useTranslate()
84-
8583
if (metadata) {
8684
const metadataId = 'metadata-log'
8785
const metadataLogEntry = {
88-
message: translate("Metadata section: "),
86+
message: "Metadata section: ",
8987
id: metadataId
9088
}
9189
addNewLogEntry(setLogEntries, metadataLogEntry)
@@ -94,22 +92,22 @@ function validateAndDisplayMetadata(
9492
if (Array.isArray(metadata)) {
9593
updateLogEntry(setLogEntries, {...metadataLogEntry, status: {
9694
icon: {
97-
label: translate("WRONG TYPE - SHOULD BE TABLE"),
95+
label: "WRONG TYPE - SHOULD BE TABLE",
9896
type: "ERROR",
9997
},
10098
}})
10199
} else {
102100
updateLogEntry(setLogEntries, {...metadataLogEntry, status: {
103101
icon: {
104-
label: translate("FOUND"),
102+
label: "FOUND",
105103
type: "SUCCESS",
106104
},
107105
}})
108106

109107
if (metadata.modified) {
110108
const modifiedLogId = 'modified-date-log'
111109
const modifiedLogEntry = {
112-
message: translate("Modified date: "),
110+
message: "Modified date: ",
113111
id: modifiedLogId
114112
}
115113
addNewLogEntry(setLogEntries, modifiedLogEntry)
@@ -123,7 +121,7 @@ function validateAndDisplayMetadata(
123121
} catch(e) {
124122
updateLogEntry(setLogEntries, { ...modifiedLogEntry, status: {
125123
icon: {
126-
label: translate("INVALID"),
124+
label: "INVALID",
127125
type: "ERROR",
128126
},
129127
}})
@@ -148,10 +146,9 @@ async function parseXRPLToml(
148146
tomlData,
149147
addressToVerify?: string,
150148
domain?: string) {
151-
const { translate } = useTranslate()
152149

153150
const parsingTomlLogEntry: LogEntryItem = {
154-
message: translate("Parsing TOML data..."),
151+
message: "Parsing TOML data...",
155152
id: 'parsing-toml-data-log',
156153
}
157154
addNewLogEntry(setLogEntries, parsingTomlLogEntry)
@@ -161,7 +158,7 @@ async function parseXRPLToml(
161158
parsed = parse(tomlData)
162159
updateLogEntry(setLogEntries, {...parsingTomlLogEntry, status: {
163160
icon: {
164-
label: translate("SUCCESS"),
161+
label: "SUCCESS",
165162
type: "SUCCESS",
166163
},
167164
}})
@@ -177,7 +174,7 @@ async function parseXRPLToml(
177174

178175
validateAndDisplayMetadata(setLogEntries, parsed.METADATA)
179176

180-
const accountHeader = translate("Accounts:")
177+
const accountHeader = "Accounts:"
181178
if(addressToVerify) {
182179
const filterToSpecificAccount = (entry: AccountFields) => entry.address === addressToVerify
183180
const accountFound = await validateAndDisplayFields(
@@ -191,11 +188,11 @@ async function parseXRPLToml(
191188
if(accountFound) {
192189
// Then share whether the domain / account pair as a whole has been validated
193190
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.',
195192
id: statusLogId,
196193
status: {
197194
icon: {
198-
label: translate("DOMAIN VALIDATED"),
195+
label: "DOMAIN VALIDATED",
199196
type: "SUCCESS",
200197
check: true,
201198
}
@@ -204,22 +201,22 @@ async function parseXRPLToml(
204201
} else {
205202
// We failed to find any entries which match the account we're looking for
206203
addNewLogEntry(setLogEntries, {
207-
message: translate("Account:"),
204+
message: "Account:",
208205
id: 'toml-account-entry-log',
209206
status: {
210207
icon: {
211-
label: translate("NOT FOUND"),
208+
label: "NOT FOUND",
212209
type: "ERROR"
213210
}
214211
}
215212
})
216213

217214
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 cannot be verified.",
219216
id: statusLogId,
220217
status: {
221218
icon: {
222-
label: translate("VALIDATION FAILED"),
219+
label: "VALIDATION FAILED",
223220
type: "ERROR",
224221
}
225222
}
@@ -228,13 +225,13 @@ async function parseXRPLToml(
228225
} else {
229226
// The final validation message is displayed under the validated account since in this case we're
230227
// 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)
232229

233230
// 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)
238235
}
239236
}
240237

@@ -272,12 +269,10 @@ export async function fetchFile(
272269
domain: string,
273270
accountToVerify?: string) {
274271

275-
const { translate } = useTranslate()
276-
277272
const url = "https://" + domain + TOML_PATH
278273
const checkUrlId = `check-url-log`
279274
const logEntry = {
280-
message: translate(`Checking ${url} ...`),
275+
message: `Checking ${url} ...`,
281276
id: checkUrlId,
282277
}
283278
addNewLogEntry(setLogEntries, logEntry)
@@ -287,7 +282,7 @@ export async function fetchFile(
287282
const data: string = response.data
288283
updateLogEntry(setLogEntries, {...logEntry, status: {
289284
icon: {
290-
label: translate("FOUND"),
285+
label: "FOUND",
291286
type: "SUCCESS",
292287
},
293288
}})
@@ -298,13 +293,13 @@ export async function fetchFile(
298293
} catch (e) {
299294
const errorUpdate: LogEntryItem = {...logEntry, status: {
300295
icon: {
301-
label: translate(getHttpErrorCode((e as AxiosError)?.status)),
296+
label: getHttpErrorCode((e as AxiosError)?.status),
302297
type: "ERROR",
303298
},
304299
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>
308303
</p>)
309304
}}
310305
updateLogEntry(setLogEntries, errorUpdate)
@@ -319,15 +314,13 @@ export async function fetchFile(
319314
function displayDecodedWalletLog(
320315
setAccountLogEntries: React.Dispatch<React.SetStateAction<LogEntryItem[]>>,) {
321316

322-
const { translate } = useTranslate()
323-
324317
const logId = 'decoding-domain-hex'
325318
addNewLogEntry(setAccountLogEntries, {
326-
message: translate('Decoding domain hex'),
319+
message: 'Decoding domain hex',
327320
id: logId,
328321
status: {
329322
icon: {
330-
label: translate('SUCCESS'),
323+
label: 'SUCCESS',
331324
type: 'SUCCESS',
332325
},
333326
}
@@ -361,13 +354,12 @@ export function fetchWallet(
361354
accountToVerify: string,
362355
socket?: WebSocket)
363356
{
364-
const {translate} = useTranslate()
365357

366358
// Reset the logs
367359
setAccountLogEntries([])
368360

369361
const walletLogEntry = {
370-
message: translate(`Checking domain of account`),
362+
message: `Checking domain of account`,
371363
id: 'check-domain-account',
372364
}
373365
addNewLogEntry(setAccountLogEntries, walletLogEntry)
@@ -387,7 +379,7 @@ export function fetchWallet(
387379
// Defaults to error to simplify logic later on
388380
let response: LogEntryStatus = {
389381
icon: {
390-
label: translate(`ERROR`),
382+
label: `ERROR`,
391383
type: `ERROR`,
392384
},
393385
};
@@ -398,7 +390,7 @@ export function fetchWallet(
398390
try {
399391
response = {
400392
icon: {
401-
label: translate('SUCCESS'),
393+
label: 'SUCCESS',
402394
type: 'SUCCESS',
403395
},
404396
}
@@ -408,13 +400,13 @@ export function fetchWallet(
408400
fetchFile(setAccountLogEntries, decodedDomain, accountToVerify)
409401
} catch(e) {
410402
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>
412404
}
413405
} 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>
415407
}
416408
} 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>
418410
}
419411
updateLogEntry(setAccountLogEntries, { ...walletLogEntry, status: response })
420412
} catch {

0 commit comments

Comments
 (0)