From 2e794f51a87ee2ce49444ad4c06070021a0b2636 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Thu, 13 Jan 2022 17:51:33 +0000 Subject: [PATCH] use generateDtName from ocean.js (#992) --- src/@utils/datatokens/index.ts | 38 ---- src/@utils/datatokens/words.json | 204 ------------------ .../@shared/FormFields/Datatoken/index.tsx | 6 +- src/components/Publish/Pricing/Coin.tsx | 3 +- src/components/Publish/_types.ts | 3 +- 5 files changed, 5 insertions(+), 249 deletions(-) delete mode 100644 src/@utils/datatokens/index.ts delete mode 100644 src/@utils/datatokens/words.json diff --git a/src/@utils/datatokens/index.ts b/src/@utils/datatokens/index.ts deleted file mode 100644 index b4fb74590..000000000 --- a/src/@utils/datatokens/index.ts +++ /dev/null @@ -1,38 +0,0 @@ -import wordListDefault from './words.json' - -export interface DataTokenOptions { - cap?: string - name?: string - symbol?: string -} - -/** - * Generate new datatoken name & symbol from a word list - * @return {<{ name: String; symbol: String }>} datatoken name & symbol. Produces e.g. "Endemic Jellyfish Token" & "ENDJEL-45" - */ -export function generateDatatokenName(wordList?: { - nouns: string[] - adjectives: string[] -}): { - name: string - symbol: string -} { - const list = wordList || wordListDefault - const random1 = Math.floor(Math.random() * list.adjectives.length) - const random2 = Math.floor(Math.random() * list.nouns.length) - const indexNumber = Math.floor(Math.random() * 100) - - // Capitalized adjective & noun - const adjective = list.adjectives[random1].replace(/^\w/, (c) => - c.toUpperCase() - ) - const noun = list.nouns[random2].replace(/^\w/, (c) => c.toUpperCase()) - - const name = `${adjective} ${noun} Token` - // use first 3 letters of name, uppercase it, and add random number - const symbol = `${( - adjective.substring(0, 3) + noun.substring(0, 3) - ).toUpperCase()}-${indexNumber}` - - return { name, symbol } -} diff --git a/src/@utils/datatokens/words.json b/src/@utils/datatokens/words.json deleted file mode 100644 index 7f5dbe205..000000000 --- a/src/@utils/datatokens/words.json +++ /dev/null @@ -1,204 +0,0 @@ -{ - "nouns": [ - "Crab", - "Fish", - "Seal", - "Octopus", - "Shark", - "Seahorse", - "Walrus", - "Starfish", - "Whale", - "Orca", - "Penguin", - "Jellyfish", - "Squid", - "Lobster", - "Pelican", - "Shrimp", - "Oyster", - "Clam", - "Seagull", - "Dolphin", - "Shell", - "Cormorant", - "Otter", - "Anemone", - "Turtle", - "Coral", - "Ray", - "Barracuda", - "Krill", - "Anchovy", - "Angelfish", - "Barnacle", - "Clownfish", - "Cod", - "Cuttlefish", - "Eel", - "Fugu", - "Herring", - "Haddock", - "Ling", - "Mackerel", - "Manatee", - "Narwhal", - "Nautilus", - "Plankton", - "Porpoise", - "Prawn", - "Pufferfish", - "Swordfish", - "Tuna" - ], - "adjectives": [ - "adamant", - "adroit", - "amatory", - "ambitious", - "amused", - "animistic", - "antic", - "arcadian", - "artistic", - "astonishing", - "astounding", - "baleful", - "bellicose", - "bilious", - "blissful", - "boorish", - "brave", - "breathtaking", - "brilliant", - "calamitous", - "caustic", - "cerulean", - "clever", - "charming", - "comely", - "competent", - "concomitant", - "confident", - "contumacious", - "corpulent", - "crapulous", - "creative", - "dazzling", - "dedicated", - "defamatory", - "delighted", - "delightful", - "determined", - "didactic", - "dilatory", - "dowdy", - "efficacious", - "effulgent", - "egregious", - "empowered", - "endemic", - "enthusiastic", - "equanimous", - "exceptional", - "execrable", - "fabulous", - "fantastic", - "fastidious", - "feckless", - "fecund", - "friable", - "fulsome", - "garrulous", - "generous", - "gentle", - "guileless", - "gustatory", - "heuristic", - "histrionic", - "hubristic", - "incendiary", - "incredible", - "insidious", - "insolent", - "inspired", - "intransigent", - "inveterate", - "invidious", - "invigorated", - "irksome", - "jejune", - "juicy", - "jocular", - "joyful", - "judicious", - "kind", - "lachrymose", - "limpid", - "loquacious", - "lovely", - "luminous", - "mannered", - "marvelous", - "mendacious", - "meretricious", - "minatory", - "mordant", - "motivated", - "munificent", - "nefarious", - "noxious", - "obtuse", - "optimistic", - "parsimonious", - "pendulous", - "pernicious", - "pervasive", - "petulant", - "passionate", - "phenomenal", - "platitudinous", - "pleasant", - "powerful", - "precipitate", - "propitious", - "puckish", - "querulous", - "quiescent", - "rebarbative", - "recalcitant", - "redolent", - "rhadamanthine", - "risible", - "ruminative", - "sagacious", - "salubrious", - "sartorial", - "sclerotic", - "serpentine", - "smart", - "spasmodic", - "strident", - "stunning", - "stupendous", - "taciturn", - "tactful", - "tasty", - "tenacious", - "tremendous", - "tremulous", - "trenchant", - "turbulent", - "turgid", - "ubiquitous", - "uxorious", - "verdant", - "vibrant", - "voluble", - "voracious", - "wheedling", - "withering", - "wonderful", - "zealous" - ] -} diff --git a/src/components/@shared/FormFields/Datatoken/index.tsx b/src/components/@shared/FormFields/Datatoken/index.tsx index a8728b24f..d8f1749b0 100644 --- a/src/components/@shared/FormFields/Datatoken/index.tsx +++ b/src/components/@shared/FormFields/Datatoken/index.tsx @@ -4,14 +4,14 @@ import { InputProps } from '@shared/FormInput' import Logo from '@images/logo.svg' import RefreshName from './RefreshName' import styles from './index.module.css' -import { generateDatatokenName } from '@utils/datatokens' +import { generateDtName } from '@oceanprotocol/lib' export default function Datatoken(props: InputProps): ReactElement { const [field, meta, helpers] = useField(props.name) async function generateName() { - const dataTokenOptions = generateDatatokenName() - helpers.setValue({ ...dataTokenOptions }) + const datatokenOptions = generateDtName() + helpers.setValue({ ...datatokenOptions }) } // Generate new DT name & symbol on first mount diff --git a/src/components/Publish/Pricing/Coin.tsx b/src/components/Publish/Pricing/Coin.tsx index 212f52083..8a2b4bff6 100644 --- a/src/components/Publish/Pricing/Coin.tsx +++ b/src/components/Publish/Pricing/Coin.tsx @@ -3,7 +3,6 @@ import styles from './Coin.module.css' import InputElement from '@shared/FormInput/InputElement' import Logo from '@images/logo.svg' import Conversion from '@shared/Price/Conversion' -import { DataTokenOptions } from '@utils/datatokens' import { useField } from 'formik' import Error from './Error' @@ -13,7 +12,7 @@ export default function Coin({ weight, readOnly }: { - datatokenOptions: DataTokenOptions + datatokenOptions: { name: string; symbol: string } name: string weight: string readOnly?: boolean diff --git a/src/components/Publish/_types.ts b/src/components/Publish/_types.ts index 1cfe65c10..2e9267e71 100644 --- a/src/components/Publish/_types.ts +++ b/src/components/Publish/_types.ts @@ -1,5 +1,4 @@ import { ServiceComputeOptions } from '@oceanprotocol/lib' -import { DataTokenOptions } from '@utils/datatokens' import { NftMetadata } from '@utils/nft' import { ReactElement } from 'react' @@ -14,7 +13,7 @@ export interface FormPublishService { files: FileMetadata[] links?: FileMetadata[] timeout: string - dataTokenOptions: DataTokenOptions + dataTokenOptions: { name: string; symbol: string } access: 'Download' | 'Compute' | string providerUrl?: { url: string; valid: boolean } algorithmPrivacy?: boolean