From 25c7547178b1ae1a56604a9e3f58be9bb10c791a Mon Sep 17 00:00:00 2001 From: name Date: Wed, 11 Dec 2024 03:26:24 +0300 Subject: [PATCH] updated parseTypes with validation --- with-tailwindcss-app/package.json | 2 +- with-tailwindcss-app/styles/parseTypes.ts | 61 +++++++++++------------ with-tailwindcss-app/yarn.lock | 2 +- 3 files changed, 30 insertions(+), 35 deletions(-) diff --git a/with-tailwindcss-app/package.json b/with-tailwindcss-app/package.json index cfcbb71..284fc23 100644 --- a/with-tailwindcss-app/package.json +++ b/with-tailwindcss-app/package.json @@ -38,6 +38,6 @@ "postcss": "^8.4.49", "prettier": "3.x", "tailwindcss": "^3.4.16", - "typescript": "^5.7.2" + "typescript": "^5.7.0" } } diff --git a/with-tailwindcss-app/styles/parseTypes.ts b/with-tailwindcss-app/styles/parseTypes.ts index be546ff..5279ad3 100644 --- a/with-tailwindcss-app/styles/parseTypes.ts +++ b/with-tailwindcss-app/styles/parseTypes.ts @@ -1,74 +1,69 @@ export function parseTxTypes(txTypes: string[]) { - if (txTypes.length === 0) { + if (!txTypes) { return { - background: 'bg-[#e058]', - placeholder: 'Empty', + background: "bg-[#9b4569]", + placeholder: "contract creation", }; } if (txTypes.length === 1) { - if (txTypes.includes('coin_transfer')) { + if (txTypes.includes("coin_transfer")) { return { - background: 'bg-[#e05875]', - placeholder: '(coin transfer)', + background: "bg-[#e05875]", + placeholder: "(coin transfer)", }; } - if (txTypes.includes('token_transfer')) { + if (txTypes.includes("token_transfer")) { return { - background: 'bg-[#cce058]', - placeholder: '(token transfer)', + background: "bg-[#cce058]", + placeholder: "(token transfer)", }; } - if (txTypes.includes('contract_call')) { + if (txTypes.includes("contract_call")) { return { - background: 'bg-[#5888e0]', - placeholder: '(contract call)', + background: "bg-[#5888e0]", + placeholder: "(contract call)", }; } return { - background: 'bg-[#E88300]', - placeholder: '(contract creation)', + background: "bg-[#E88300]", + placeholder: "(contract creation)", }; } if (txTypes.length === 2) { if ( - txTypes.includes('contract_call') && - txTypes.includes('token_transfer') + txTypes.includes("contract_call") && + txTypes.includes("token_transfer") ) { return { - background: 'bg-[#36be56]', - placeholder: '(token transfer + contract call)', + background: "bg-[#36be56]", + placeholder: "(token transfer + contract call)", }; } if ( - txTypes.includes('contract_call') && - txTypes.includes('coin_transfer') + txTypes.includes("contract_call") && + txTypes.includes("coin_transfer") ) { return { - background: 'bg-[#FDA737]', - placeholder: '(coin transfer + contract call)', + background: "bg-[#FDA737]", + placeholder: "(coin transfer + contract call)", }; } if ( - txTypes.includes('contract_creation') && - txTypes.includes('token_transfer') + txTypes.includes("contract_creation") && + txTypes.includes("token_transfer") ) { return { - background: 'bg-[#a9c400]', - placeholder: '(contract creation + token transfer)', + background: "bg-[#a9c400]", + placeholder: "(contract creation + token transfer)", }; } } if (txTypes.length === 3) { return { - background: 'bg-[#FC05EC]', - placeholder: '(coin transfer + token_transfer + contract call)', + background: "bg-[#FC05EC]", + placeholder: "(coin transfer + token_transfer + contract call)", }; } - - return { - background: 'bg-[#e058]', - placeholder: '???', - }; } diff --git a/with-tailwindcss-app/yarn.lock b/with-tailwindcss-app/yarn.lock index 5344d87..1800d40 100644 --- a/with-tailwindcss-app/yarn.lock +++ b/with-tailwindcss-app/yarn.lock @@ -5548,7 +5548,7 @@ typed-array-length@^1.0.6: is-typed-array "^1.1.13" possible-typed-array-names "^1.0.0" -typescript@^5.7.2: +typescript@^5.7.0: version "5.7.2" resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.7.2.tgz#3169cf8c4c8a828cde53ba9ecb3d2b1d5dd67be6" integrity sha512-i5t66RHxDvVN40HfDd1PsEThGNnlMCMT3jMUuoh9/0TaqWevNontacunWyN02LA9/fIbEWlcHZcgTKb9QoaLfg==