diff --git a/packages/components/built/Auth.js b/packages/components/built/Auth.js index 5049ca4ca..7c98950e4 100644 --- a/packages/components/built/Auth.js +++ b/packages/components/built/Auth.js @@ -12,9 +12,9 @@ var __assign = (this && this.__assign) || function () { import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime"; import { useEffect, useState } from "react"; import { Computer } from "@bitcoin-computer/lib"; +import { initFlowbite } from "flowbite"; import { useUtilsComponents } from "./UtilsContext"; import { Modal } from "./Modal"; -import { initFlowbite } from "flowbite"; function isLoggedIn() { return !!localStorage.getItem("BIP_39_KEY"); } @@ -58,8 +58,12 @@ function getUrl(chain, network) { return getEnvVariable("REACT_APP_".concat(chain.toUpperCase(), "_").concat(network.toUpperCase(), "_URL")); } function defaultConfiguration() { - var chain = (localStorage.getItem("CHAIN") || getEnvVariable("REACT_APP_CHAIN") || "LTC"); - var network = (localStorage.getItem("NETWORK") || getEnvVariable("REACT_APP_NETWORK") || "regtest"); + var chain = (localStorage.getItem("CHAIN") || + getEnvVariable("REACT_APP_CHAIN") || + "LTC"); + var network = (localStorage.getItem("NETWORK") || + getEnvVariable("REACT_APP_NETWORK") || + "regtest"); var url = getUrl(chain, network); return { chain: chain, network: network, url: url }; } @@ -73,7 +77,7 @@ function browserConfiguration() { chain: localStorage.getItem("CHAIN"), network: localStorage.getItem("NETWORK"), path: localStorage.getItem("PATH"), - url: localStorage.getItem("URL"), + url: localStorage.getItem("URL") }; } function getComputer() { @@ -120,19 +124,10 @@ function LoginButton(_a) { var showSnackBar = useUtilsComponents().showSnackBar; var login = function (e) { e.preventDefault(); - try { - if (isLoggedIn()) - throw new Error("A user is already logged in, please log out first."); - if (mnemonic.length === 0) - throw new Error("Please don't use an empty mnemonic string."); - new Computer({ mnemonic: mnemonic, chain: chain, network: network, path: path, url: url }); - } - catch (error) { - if (error instanceof Error) { - showSnackBar(error.message, false); - } - return; - } + if (isLoggedIn()) + showSnackBar("A user is already logged in, please log out first.", false); + if (mnemonic.length === 0) + showSnackBar("Please don't use an empty mnemonic string.", false); localStorage.setItem("BIP_39_KEY", mnemonic); localStorage.setItem("CHAIN", chain); localStorage.setItem("NETWORK", network); @@ -166,5 +161,5 @@ export var Auth = { browserConfiguration: browserConfiguration, getComputer: getComputer, LoginForm: LoginForm, - LoginModal: LoginModal, + LoginModal: LoginModal }; diff --git a/packages/components/built/ComputerContext.d.ts b/packages/components/built/ComputerContext.d.ts index 0d2bf2e52..77e029d1b 100644 --- a/packages/components/built/ComputerContext.d.ts +++ b/packages/components/built/ComputerContext.d.ts @@ -1,3 +1,3 @@ /// -import { Computer } from '@bitcoin-computer/lib'; +import { Computer } from "@bitcoin-computer/lib"; export declare const ComputerContext: import("react").Context; diff --git a/packages/components/built/ComputerContext.js b/packages/components/built/ComputerContext.js index 4dc658ef0..7be1341c8 100644 --- a/packages/components/built/ComputerContext.js +++ b/packages/components/built/ComputerContext.js @@ -1,3 +1,3 @@ -import { Computer } from '@bitcoin-computer/lib'; -import { createContext } from 'react'; +import { Computer } from "@bitcoin-computer/lib"; +import { createContext } from "react"; export var ComputerContext = createContext(new Computer()); diff --git a/packages/components/built/Drawer.js b/packages/components/built/Drawer.js index 171957c44..2904ddb7d 100644 --- a/packages/components/built/Drawer.js +++ b/packages/components/built/Drawer.js @@ -20,5 +20,5 @@ function Component(_a) { } export var Drawer = { Component: Component, - ShowDrawer: ShowDrawer, + ShowDrawer: ShowDrawer }; diff --git a/packages/components/built/Error404.js b/packages/components/built/Error404.js index 126b8d91a..42afb47f2 100644 --- a/packages/components/built/Error404.js +++ b/packages/components/built/Error404.js @@ -10,6 +10,4 @@ var __assign = (this && this.__assign) || function () { return __assign.apply(this, arguments); }; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; -export var Error404 = function () { - return (_jsx("section", __assign({ className: "w-full bg-white dark:bg-gray-900" }, { children: _jsx("div", __assign({ className: "py-8 px-4 mx-auto max-w-screen-xl lg:py-16 lg:px-6" }, { children: _jsxs("div", __assign({ className: "mx-auto max-w-screen-sm text-center" }, { children: [_jsx("h1", __assign({ className: "mb-4 text-6xl tracking-tight font-extrabold text-blue-700 dark:text-blue-600" }, { children: "404" })), _jsx("p", __assign({ className: "mb-4 text-3xl tracking-tight font-bold text-gray-700 md:text-4xl dark:text-white" }, { children: "Something's missing." })), _jsxs("p", __assign({ className: "mb-4 text-lg font-light text-gray-500 dark:text-gray-400" }, { children: ["Sorry, we can't find that page. You'll find lots to explore on the home page.", " "] })), _jsx("a", __assign({ href: "/", className: "inline-flex text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:focus:ring-blue-900 my-4" }, { children: "Back to Homepage" }))] })) })) }))); -}; +export var Error404 = function () { return (_jsx("section", __assign({ className: "w-full bg-white dark:bg-gray-900" }, { children: _jsx("div", __assign({ className: "py-8 px-4 mx-auto max-w-screen-xl lg:py-16 lg:px-6" }, { children: _jsxs("div", __assign({ className: "mx-auto max-w-screen-sm text-center" }, { children: [_jsx("h1", __assign({ className: "mb-4 text-6xl tracking-tight font-extrabold text-blue-700 dark:text-blue-600" }, { children: "404" })), _jsx("p", __assign({ className: "mb-4 text-3xl tracking-tight font-bold text-gray-700 md:text-4xl dark:text-white" }, { children: "Something's missing." })), _jsxs("p", __assign({ className: "mb-4 text-lg font-light text-gray-500 dark:text-gray-400" }, { children: ["Sorry, we can't find that page. You'll find lots to explore on the home page.", " "] })), _jsx("a", __assign({ href: "/", className: "inline-flex text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:focus:ring-blue-900 my-4" }, { children: "Back to Homepage" }))] })) })) }))); }; diff --git a/packages/components/built/Gallery.d.ts b/packages/components/built/Gallery.d.ts index 81d7d2218..215cdf5e1 100644 --- a/packages/components/built/Gallery.d.ts +++ b/packages/components/built/Gallery.d.ts @@ -4,7 +4,7 @@ export type UserQuery = Partial<{ publicKey: string; limit: number; offset: number; - order: 'ASC' | 'DESC'; + order: "ASC" | "DESC"; ids: string[]; contract: { class: T; diff --git a/packages/components/built/Gallery.js b/packages/components/built/Gallery.js index bb0ffe321..11f4403d5 100644 --- a/packages/components/built/Gallery.js +++ b/packages/components/built/Gallery.js @@ -48,8 +48,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) { import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime"; import { useContext, useEffect, useState } from "react"; import { Link, useLocation } from "react-router-dom"; -import { jsonMap, strip, toObject } from "./common/utils"; import { initFlowbite } from "flowbite"; +import { jsonMap, strip, toObject } from "./common/utils"; import { useUtilsComponents } from "./UtilsContext"; import { ComputerContext } from "./ComputerContext"; function HomePageCard(_a) { @@ -121,8 +121,8 @@ export default function WithPagination(q) { case 0: showLoader(true); query = __assign(__assign({}, q), params); - query["offset"] = contractsPerPage * pageNum; - query["limit"] = contractsPerPage + 1; + query.offset = contractsPerPage * pageNum; + query.limit = contractsPerPage + 1; return [4 /*yield*/, computer.query(query)]; case 1: result = _a.sent(); @@ -158,5 +158,5 @@ export default function WithPagination(q) { } export var Gallery = { FromRevs: FromRevs, - WithPagination: WithPagination, + WithPagination: WithPagination }; diff --git a/packages/components/built/Modal.js b/packages/components/built/Modal.js index 44be4c91a..1c14b7c73 100644 --- a/packages/components/built/Modal.js +++ b/packages/components/built/Modal.js @@ -50,5 +50,5 @@ export var Modal = { ShowButton: ShowButton, HideButton: HideButton, ToggleButton: ToggleButton, - Component: Component, + Component: Component }; diff --git a/packages/components/built/SmartObject.js b/packages/components/built/SmartObject.js index 0eed6c450..7fe7bae1d 100644 --- a/packages/components/built/SmartObject.js +++ b/packages/components/built/SmartObject.js @@ -48,8 +48,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) { import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime"; import { useContext, useEffect, useState } from "react"; import { Link, useLocation, useNavigate, useParams } from "react-router-dom"; -import { capitalizeFirstLetter, toObject } from "./common/utils"; import reactStringReplace from "react-string-replace"; +import { capitalizeFirstLetter, toObject } from "./common/utils"; import { Card } from "./Card"; import { Modal } from "./Modal"; import { FunctionResultModalContent } from "./common/SmartCallExecutionResult"; @@ -82,11 +82,7 @@ var SmartObjectValues = function (_a) { return (_jsxs("div", { children: [_jsx("h3", __assign({ className: "mt-2 text-xl font-bold dark:text-white" }, { children: capitalizeFirstLetter(key) })), _jsx(ObjectValueCard, { content: toObject(value) })] }, i)); }) })); }; -var revToId = function (rev) { return rev === null || rev === void 0 ? void 0 : rev.split(":")[0]; }; -var MetaData = function (_a) { - var smartObject = _a.smartObject; - return (_jsxs(_Fragment, { children: [_jsx("h2", __assign({ className: "mb-2 text-4xl font-bold dark:text-white" }, { children: "Meta Data" })), _jsxs("table", __assign({ className: "w-full mt-4 mb-8 text-sm text-left text-gray-500 dark:text-gray-400" }, { children: [_jsx("thead", __assign({ className: "text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400" }, { children: _jsxs("tr", { children: [_jsx("th", __assign({ scope: "col", className: "px-6 py-3" }, { children: "Key" })), _jsx("th", __assign({ scope: "col", className: "px-6 py-3" }, { children: "Short" })), _jsx("th", __assign({ scope: "col", className: "px-6 py-3" }, { children: "Value" }))] }) })), _jsxs("tbody", { children: [_jsxs("tr", __assign({ className: "bg-white border-b dark:bg-gray-800 dark:border-gray-700" }, { children: [_jsx("td", __assign({ className: "px-6 py-4 break-all" }, { children: "Identity" })), _jsx("td", __assign({ className: "px-6 py-4 break-all text-sm" }, { children: _jsx("pre", { children: "_id" }) })), _jsx("td", __assign({ className: "px-6 py-4" }, { children: _jsx(Link, __assign({ to: "/objects/".concat(smartObject === null || smartObject === void 0 ? void 0 : smartObject._id), className: "font-medium text-blue-600 dark:text-blue-500 hover:underline" }, { children: smartObject === null || smartObject === void 0 ? void 0 : smartObject._id })) }))] })), _jsxs("tr", __assign({ className: "bg-white border-b dark:bg-gray-800 dark:border-gray-700" }, { children: [_jsx("td", __assign({ className: "px-6 py-4 break-all" }, { children: "Revision" })), _jsx("td", __assign({ className: "px-6 py-4 break-all" }, { children: _jsx("pre", { children: "_rev" }) })), _jsx("td", __assign({ className: "px-6 py-4" }, { children: _jsx(Link, __assign({ to: "/objects/".concat(smartObject === null || smartObject === void 0 ? void 0 : smartObject._rev), className: "font-medium text-blue-600 dark:text-blue-500 hover:underline" }, { children: smartObject === null || smartObject === void 0 ? void 0 : smartObject._rev })) }))] })), _jsxs("tr", __assign({ className: "bg-white border-b dark:bg-gray-800 dark:border-gray-700" }, { children: [_jsx("td", __assign({ className: "px-6 py-4 break-all" }, { children: "Root" })), _jsx("td", __assign({ className: "px-6 py-4 break-all" }, { children: _jsx("pre", { children: "_root" }) })), _jsx("td", __assign({ className: "px-6 py-4" }, { children: _jsx(Link, __assign({ to: "/objects/".concat(smartObject === null || smartObject === void 0 ? void 0 : smartObject._root), className: "font-medium text-blue-600 dark:text-blue-500 hover:underline" }, { children: smartObject === null || smartObject === void 0 ? void 0 : smartObject._root })) }))] })), _jsxs("tr", __assign({ className: "bg-white border-b dark:bg-gray-800 dark:border-gray-700" }, { children: [_jsx("td", __assign({ className: "px-6 py-4 break-all" }, { children: "Owners" })), _jsx("td", __assign({ className: "px-6 py-4 break-all" }, { children: _jsx("pre", { children: "_owners" }) })), _jsx("td", __assign({ className: "px-6 py-4" }, { children: _jsx("span", __assign({ className: "font-medium text-gray-900 dark:text-white" }, { children: smartObject === null || smartObject === void 0 ? void 0 : smartObject._owners })) }))] })), _jsxs("tr", __assign({ className: "bg-white border-b dark:bg-gray-800 dark:border-gray-700" }, { children: [_jsx("td", __assign({ className: "px-6 py-4 break-all" }, { children: "Amount" })), _jsx("td", __assign({ className: "px-6 py-4 break-all" }, { children: _jsx("pre", { children: "_amount" }) })), _jsx("td", __assign({ className: "px-6 py-4" }, { children: _jsx("span", __assign({ className: "font-medium text-gray-900 dark:text-white" }, { children: smartObject === null || smartObject === void 0 ? void 0 : smartObject._amount })) }))] })), _jsxs("tr", __assign({ className: "bg-white border-b dark:bg-gray-800 dark:border-gray-700" }, { children: [_jsx("td", __assign({ className: "px-6 py-4 break-all" }, { children: "Transaction" })), _jsx("td", { className: "px-6 py-4 break-all" }), _jsx("td", __assign({ className: "px-6 py-4" }, { children: _jsx(Link, __assign({ to: "/transactions/".concat(revToId(smartObject === null || smartObject === void 0 ? void 0 : smartObject._rev)), className: "font-medium text-blue-600 dark:text-blue-500 hover:underline" }, { children: revToId(smartObject === null || smartObject === void 0 ? void 0 : smartObject._rev) })) }))] }))] })] }))] })); -}; +// const revToId = (rev: string) => rev?.split(":")[0] function Component() { var _this = this; var location = useLocation(); @@ -100,7 +96,12 @@ function Component() { var options = ["object", "string", "number", "bigint", "boolean", "undefined", "symbol"]; var _d = useState(""), modalTitle = _d[0], setModalTitle = _d[1]; var setShow = function (flag) { - flag ? Modal.get(modalId).show() : Modal.get(modalId).hide(); + if (flag) { + Modal.get(modalId).show(); + } + else { + Modal.get(modalId).hide(); + } }; useEffect(function () { var fetch = function () { return __awaiter(_this, void 0, void 0, function () { @@ -131,11 +132,11 @@ function Component() { var filteredSmartObject = Object.getOwnPropertyNames(Object.getPrototypeOf(smartObject)).filter(function (key) { return key !== "constructor" && typeof Object.getPrototypeOf(smartObject)[key] === "function"; }); - for (var key in filteredSmartObject) { + Object.keys(filteredSmartObject).forEach(function (key) { if (key) { funcExist = true; } - } + }); } setFunctionsExist(funcExist); }, [smartObject]); @@ -143,5 +144,5 @@ function Component() { return (_jsxs(_Fragment, { children: [_jsxs("div", { children: [_jsx("h1", __assign({ className: "mb-2 text-5xl font-extrabold dark:text-white" }, { children: "Object" })), _jsxs("p", __assign({ className: "mb-6 text-lg font-normal text-gray-500 lg:text-xl dark:text-gray-400" }, { children: [_jsx(Link, __assign({ to: "/transactions/".concat(txId), className: "font-medium text-blue-600 dark:text-blue-500 hover:underline" }, { children: txId })), ":", outNum] })), _jsx(SmartObjectValues, { smartObject: smartObject }), _jsx(SmartObjectFunction, { smartObject: smartObject, functionsExist: functionsExist, options: options, setFunctionResult: setFunctionResult, setShow: setShow, setModalTitle: setModalTitle })] }), _jsx(Modal.Component, { title: modalTitle, content: FunctionResultModalContent, contentData: { functionResult: functionResult }, id: modalId })] })); } export var SmartObject = { - Component: Component, + Component: Component }; diff --git a/packages/components/built/SmartObjectFunction.d.ts b/packages/components/built/SmartObjectFunction.d.ts index 84be033db..2ae88b53f 100644 --- a/packages/components/built/SmartObjectFunction.d.ts +++ b/packages/components/built/SmartObjectFunction.d.ts @@ -1,4 +1,4 @@ export declare const getErrorMessage: (error: any) => string; export declare const getFnParamNames: (fn: string) => string[]; export declare const getValueForType: (type: string, stringValue: string) => string | number | true | null | undefined; -export declare const SmartObjectFunction: ({ smartObject, functionsExist, options, setFunctionResult, setShow, setModalTitle, }: any) => import("react/jsx-runtime").JSX.Element; +export declare const SmartObjectFunction: ({ smartObject, functionsExist, options, setFunctionResult, setShow, setModalTitle }: any) => import("react/jsx-runtime").JSX.Element; diff --git a/packages/components/built/SmartObjectFunction.js b/packages/components/built/SmartObjectFunction.js index 24b0a0da2..2da3feacb 100644 --- a/packages/components/built/SmartObjectFunction.js +++ b/packages/components/built/SmartObjectFunction.js @@ -57,12 +57,10 @@ export var getErrorMessage = function (error) { "mandatory-script-verify-flag-failed (Operation not valid with the current stack size)") { return "You are not authorized to make changes to this smart object"; } - else if ((_d = (_c = error === null || error === void 0 ? void 0 : error.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.error) { + if ((_d = (_c = error === null || error === void 0 ? void 0 : error.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.error) { return (_f = (_e = error === null || error === void 0 ? void 0 : error.response) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.error; } - else { - return error.message ? error.message : "Error occurred"; - } + return error.message ? error.message : "Error occurred"; }; export var getFnParamNames = function (fn) { var match = fn.toString().match(/\(.*?\)/); @@ -91,7 +89,7 @@ export var SmartObjectFunction = function (_a) { var _b = useState({}), formState = _b[0], setFormState = _b[1]; var showLoader = UtilsContext.useUtilsComponents().showLoader; var computer = useContext(ComputerContext); - var handleSmartObjectMethod = function (event, smartObject, fnName, params) { return __awaiter(void 0, void 0, void 0, function () { + var handleSmartObjectMethod = function (event, smartObj, fnName, params) { return __awaiter(void 0, void 0, void 0, function () { var revMap_1, tx, res, error_1; return __generator(this, function (_a) { switch (_a.label) { @@ -113,15 +111,17 @@ export var SmartObjectFunction = function (_a) { exp: "smartObject.".concat(fnName, "(").concat(params.map(function (param) { var key = "".concat(fnName, "-").concat(param); var paramValue = getValueForType(formState["".concat(key, "--types")], formState[key]); - return isValidRev(paramValue) - ? param - : typeof paramValue === "string" - ? "'".concat(paramValue, "'") - : paramValue; + if (isValidRev(paramValue)) { + return param; + } + if (typeof paramValue === "string") { + return "'".concat(paramValue, "'"); + } + return paramValue; }), ")"), - env: __assign({ smartObject: smartObject._rev }, revMap_1), + env: __assign({ smartObject: smartObj._rev }, revMap_1), fund: true, - sign: true, + sign: true })]; case 2: tx = (_a.sent()).tx; @@ -171,6 +171,8 @@ export var SmartObjectFunction = function (_a) { }) .map(function (key, fnIndex) { var paramList = getFnParamNames(Object.getPrototypeOf(smartObject)[key]); - return (_jsxs("div", __assign({ className: "mt-6 mb-6" }, { children: [_jsx("h3", __assign({ className: "my-2 text-xl font-bold dark:text-white" }, { children: capitalizeFirstLetter(key) })), _jsxs("form", __assign({ id: "fn-index-".concat(fnIndex) }, { children: [paramList.map(function (paramName, paramIndex) { return (_jsxs("div", __assign({ className: "mb-4" }, { children: [_jsx("div", __assign({ className: "mb-2" }, { children: _jsx("label", __assign({ htmlFor: "".concat(key, "-").concat(paramName), className: "block mb-2 text-sm font-medium text-gray-900 dark:text-white" }, { children: paramName })) })), _jsxs("div", __assign({ className: "flex items-center space-x-4" }, { children: [_jsx("input", { type: "text", id: "".concat(key, "-").concat(paramName), value: formState["".concat(key, "-").concat(paramName)] || "", onChange: function (e) { return updateFormValue(e, "".concat(key, "-").concat(paramName)); }, className: "bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500", placeholder: "Value", required: true }), _jsx(TypeSelectionDropdown, { id: "".concat(key).concat(paramName), dropdownList: options, onSelectMethod: function (option) { return updateTypes(option, "".concat(key, "-").concat(paramName)); } })] }))] }), paramIndex)); }), _jsx("button", __assign({ className: "mr-8 text-white bg-blue-700 hover:bg-blue-800 focus:outline-none focus:ring-4 focus:ring-blue-300 font-medium rounded-md text-sm px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800", onClick: function (evt) { return handleSmartObjectMethod(evt, smartObject, key, paramList); } }, { children: "Call Function" }))] }))] }), fnIndex)); + return (_jsxs("div", __assign({ className: "mt-6 mb-6" }, { children: [_jsx("h3", __assign({ className: "my-2 text-xl font-bold dark:text-white" }, { children: capitalizeFirstLetter(key) })), _jsxs("form", __assign({ id: "fn-index-".concat(fnIndex) }, { children: [paramList.map(function (paramName, paramIndex) { return (_jsxs("div", __assign({ className: "mb-4" }, { children: [_jsx("div", __assign({ className: "mb-2" }, { children: _jsx("label", __assign({ htmlFor: "".concat(key, "-").concat(paramName), className: "block mb-2 text-sm font-medium text-gray-900 dark:text-white" }, { children: paramName })) })), _jsxs("div", __assign({ className: "flex items-center space-x-4" }, { children: [_jsx("input", { type: "text", id: "".concat(key, "-").concat(paramName), value: formState["".concat(key, "-").concat(paramName)] || "", onChange: function (e) { return updateFormValue(e, "".concat(key, "-").concat(paramName)); }, className: "bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500", placeholder: "Value", required: true }), _jsx(TypeSelectionDropdown, { id: "".concat(key).concat(paramName), dropdownList: options, onSelectMethod: function (option) { + return updateTypes(option, "".concat(key, "-").concat(paramName)); + } })] }))] }), paramIndex)); }), _jsx("button", __assign({ className: "mr-8 text-white bg-blue-700 hover:bg-blue-800 focus:outline-none focus:ring-4 focus:ring-blue-300 font-medium rounded-md text-sm px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800", onClick: function (evt) { return handleSmartObjectMethod(evt, smartObject, key, paramList); } }, { children: "Call Function" }))] }))] }), fnIndex)); }) })); }; diff --git a/packages/components/built/Transaction.js b/packages/components/built/Transaction.js index e61f6ef52..84c735eac 100644 --- a/packages/components/built/Transaction.js +++ b/packages/components/built/Transaction.js @@ -55,16 +55,12 @@ function ExpressionCard(_a) { var content = _a.content, env = _a.env; var entries = Object.entries(env); var formattedContent = content; - var _loop_1 = function (entry) { - var name_1 = entry[0], rev = entry[1]; - var regExp = new RegExp("(".concat(name_1, ")"), "g"); - var replacer = function (name, i) { return (_jsx(Link, __assign({ to: "/objects/".concat(rev), className: "font-medium text-blue-600 dark:text-blue-500 hover:underline" }, { children: name }), rev)); }; + entries.forEach(function (entry) { + var name = entry[0], rev = entry[1]; + var regExp = new RegExp("(".concat(name, ")"), "g"); + var replacer = function (n) { return (_jsx(Link, __assign({ to: "/objects/".concat(rev), className: "font-medium text-blue-600 dark:text-blue-500 hover:underline" }, { children: n }), rev)); }; formattedContent = reactStringReplace(formattedContent, regExp, replacer); - }; - for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) { - var entry = entries_1[_i]; - _loop_1(entry); - } + }); return _jsx(Card, { content: formattedContent }); } function Component() { @@ -139,9 +135,7 @@ function Component() { }; var outputsComponent = function () { var _a; - return (_jsxs("div", __assign({ className: "relative overflow-x-auto" }, { children: [_jsx("h2", __assign({ className: "mb-2 text-4xl font-bold dark:text-white" }, { children: "Objects" })), _jsxs("table", __assign({ className: "w-full mt-4 mb-8 text-sm text-left text-gray-500 dark:text-gray-400" }, { children: [_jsx("thead", __assign({ className: "text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400" }, { children: _jsxs("tr", { children: [_jsx("th", __assign({ scope: "col", className: "px-6 py-3" }, { children: "Number" })), _jsx("th", __assign({ scope: "col", className: "px-6 py-3" }, { children: "Value" })), _jsx("th", __assign({ scope: "col", className: "px-6 py-3" }, { children: "Type" })), _jsx("th", __assign({ scope: "col", className: "px-6 py-3" }, { children: "Script PubKey" }))] }) })), _jsx("tbody", { children: (_a = rpcTxnData === null || rpcTxnData === void 0 ? void 0 : rpcTxnData.vout) === null || _a === void 0 ? void 0 : _a.map(function (output) { - return (_jsxs("tr", __assign({ className: "bg-white border-b dark:bg-gray-800 dark:border-gray-700" }, { children: [_jsx("td", __assign({ className: "px-6 py-4 break-all" }, { children: _jsxs(Link, __assign({ to: "/objects/".concat(txn, ":").concat(output.n), className: "font-medium text-blue-600 dark:text-blue-500 hover:underline" }, { children: ["#", output.n] })) })), _jsx("td", __assign({ className: "px-6 py-4" }, { children: output.value })), _jsx("td", __assign({ className: "px-6 py-4" }, { children: output.scriptPubKey.type })), _jsx("td", __assign({ className: "px-6 py-4 break-all" }, { children: output.scriptPubKey.asm }))] }), output.n)); - }) })] }))] }))); + return (_jsxs("div", __assign({ className: "relative overflow-x-auto" }, { children: [_jsx("h2", __assign({ className: "mb-2 text-4xl font-bold dark:text-white" }, { children: "Objects" })), _jsxs("table", __assign({ className: "w-full mt-4 mb-8 text-sm text-left text-gray-500 dark:text-gray-400" }, { children: [_jsx("thead", __assign({ className: "text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400" }, { children: _jsxs("tr", { children: [_jsx("th", __assign({ scope: "col", className: "px-6 py-3" }, { children: "Number" })), _jsx("th", __assign({ scope: "col", className: "px-6 py-3" }, { children: "Value" })), _jsx("th", __assign({ scope: "col", className: "px-6 py-3" }, { children: "Type" })), _jsx("th", __assign({ scope: "col", className: "px-6 py-3" }, { children: "Script PubKey" }))] }) })), _jsx("tbody", { children: (_a = rpcTxnData === null || rpcTxnData === void 0 ? void 0 : rpcTxnData.vout) === null || _a === void 0 ? void 0 : _a.map(function (output) { return (_jsxs("tr", __assign({ className: "bg-white border-b dark:bg-gray-800 dark:border-gray-700" }, { children: [_jsx("td", __assign({ className: "px-6 py-4 break-all" }, { children: _jsxs(Link, __assign({ to: "/objects/".concat(txn, ":").concat(output.n), className: "font-medium text-blue-600 dark:text-blue-500 hover:underline" }, { children: ["#", output.n] })) })), _jsx("td", __assign({ className: "px-6 py-4" }, { children: output.value })), _jsx("td", __assign({ className: "px-6 py-4" }, { children: output.scriptPubKey.type })), _jsx("td", __assign({ className: "px-6 py-4 break-all" }, { children: output.scriptPubKey.asm }))] }), output.n)); }) })] }))] }))); }; return (_jsx(_Fragment, { children: _jsxs("div", __assign({ className: "pt-8" }, { children: [_jsx("h1", __assign({ className: "mb-2 text-5xl font-extrabold dark:text-white" }, { children: "Transaction" })), _jsx("p", __assign({ className: "mb-6 text-lg font-normal text-gray-500 lg:text-xl dark:text-gray-400" }, { children: txn })), transition && transitionComponent(), (rpcTxnData === null || rpcTxnData === void 0 ? void 0 : rpcTxnData.vin) && inputsComponent(), (rpcTxnData === null || rpcTxnData === void 0 ? void 0 : rpcTxnData.vout) && outputsComponent()] })) })); } diff --git a/packages/components/built/UtilsContext.js b/packages/components/built/UtilsContext.js index 5d3d6d244..8caa81aba 100644 --- a/packages/components/built/UtilsContext.js +++ b/packages/components/built/UtilsContext.js @@ -38,5 +38,5 @@ export var UtilsProvider = function (_a) { }; export var UtilsContext = { UtilsProvider: UtilsProvider, - useUtilsComponents: useUtilsComponents, + useUtilsComponents: useUtilsComponents }; diff --git a/packages/components/built/Wallet.js b/packages/components/built/Wallet.js index d551bb4e7..97e1b604a 100644 --- a/packages/components/built/Wallet.js +++ b/packages/components/built/Wallet.js @@ -99,8 +99,7 @@ var Mnemonic = function (_a) { var Heading = function () { return _jsx("h6", __assign({ className: "text-lg font-bold dark:text-white" }, { children: "Mnemonic" })); }; if (showMnemonic) return (_jsxs("div", __assign({ className: "mb-4" }, { children: [_jsx(Heading, {}), _jsx("p", __assign({ className: "mb-1 font-mono text-xs text-gray-500 dark:text-gray-400 break-words" }, { children: computer.getMnemonic() })), _jsx("button", __assign({ onClick: function () { return setShowMnemonic(false); }, className: "text-sm text-gray-500 dark:text-gray-400 hover:text-blue-600 dark:hover:text-blue-500 underline" }, { children: "Hide" }))] }))); - else - return (_jsxs("div", __assign({ className: "mb-4" }, { children: [_jsx(Heading, {}), _jsx("button", __assign({ onClick: function () { return setShowMnemonic(true); }, className: "text-sm text-gray-500 dark:text-gray-400 hover:text-blue-600 dark:hover:text-blue-500 underline" }, { children: "Show" })), _jsx("br", {})] }))); + return (_jsxs("div", __assign({ className: "mb-4" }, { children: [_jsx(Heading, {}), _jsx("button", __assign({ onClick: function () { return setShowMnemonic(true); }, className: "text-sm text-gray-500 dark:text-gray-400 hover:text-blue-600 dark:hover:text-blue-500 underline" }, { children: "Show" })), _jsx("br", {})] }))); }; var Path = function (_a) { var computer = _a.computer; @@ -118,9 +117,7 @@ var Network = function (_a) { var computer = _a.computer; return (_jsxs("div", __assign({ className: "mb-4" }, { children: [_jsx("h6", __assign({ className: "text-lg font-bold dark:text-white" }, { children: "Network" })), _jsx("p", __assign({ className: "mb-4 font-mono text-xs text-gray-500 dark:text-gray-400 break-words" }, { children: computer.getNetwork() }))] }))); }; -var LogOut = function () { - return (_jsxs(_Fragment, { children: [_jsxs("div", __assign({ className: "mb-6" }, { children: [_jsx("h6", __assign({ className: "text-lg font-bold dark:text-white" }, { children: "Log out" })), _jsx("p", __assign({ className: "mb-1 text-sm text-gray-500 dark:text-gray-400" }, { children: "Logging out will delete your mnemonic. Make sure to write it down." }))] })), _jsx("div", __assign({ className: "grid grid-cols-2 gap-4" }, { children: _jsx("button", __assign({ onClick: Auth.logout, className: "rounded-lg border border-gray-200 bg-white px-4 py-2 text-center text-sm font-medium text-gray-900 hover:bg-gray-100 hover:text-blue-700 focus:z-10 focus:outline-none focus:ring-4 focus:ring-gray-200 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white dark:focus:ring-gray-700" }, { children: "Log out" })) }))] })); -}; +var LogOut = function () { return (_jsxs(_Fragment, { children: [_jsxs("div", __assign({ className: "mb-6" }, { children: [_jsx("h6", __assign({ className: "text-lg font-bold dark:text-white" }, { children: "Log out" })), _jsx("p", __assign({ className: "mb-1 text-sm text-gray-500 dark:text-gray-400" }, { children: "Logging out will delete your mnemonic. Make sure to write it down." }))] })), _jsx("div", __assign({ className: "grid grid-cols-2 gap-4" }, { children: _jsx("button", __assign({ onClick: Auth.logout, className: "rounded-lg border border-gray-200 bg-white px-4 py-2 text-center text-sm font-medium text-gray-900 hover:bg-gray-100 hover:text-blue-700 focus:z-10 focus:outline-none focus:ring-4 focus:ring-gray-200 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white dark:focus:ring-gray-700" }, { children: "Log out" })) }))] })); }; export function Wallet() { var computer = useContext(ComputerContext); var Content = function () { return (_jsxs(_Fragment, { children: [_jsx("h4", __assign({ className: "mb-8 text-2xl font-bold dark:text-white" }, { children: "Wallet" })), _jsx(Balance, { computer: computer }), _jsx(Address, { computer: computer }), _jsx(PublicKey, { computer: computer }), _jsx(Path, { computer: computer }), _jsx(Mnemonic, { computer: computer }), _jsx("hr", { className: "h-px my-6 bg-gray-200 border-0 dark:bg-gray-700" }), _jsx(Chain, { computer: computer }), _jsx(Network, { computer: computer }), _jsx(Url, { computer: computer }), _jsx("hr", { className: "h-px my-6 bg-gray-200 border-0 dark:bg-gray-700" }), _jsx(LogOut, {})] })); }; diff --git a/packages/components/built/common/SmartCallExecutionResult.js b/packages/components/built/common/SmartCallExecutionResult.js index 33022d799..fe30861c5 100644 --- a/packages/components/built/common/SmartCallExecutionResult.js +++ b/packages/components/built/common/SmartCallExecutionResult.js @@ -15,9 +15,9 @@ export function FunctionResultModalContent(_a) { var functionResult = _a.functionResult; var navigate = useNavigate(); if (functionResult && typeof functionResult === "object" && !Array.isArray(functionResult)) - return _jsx(_Fragment, { children: _jsxs("div", __assign({ className: "p-4 md:p-5" }, { children: ["You created a\u00A0", _jsx(Link, __assign({ to: "/objects/".concat(functionResult._rev), className: "font-medium text-blue-600 dark:text-blue-500 hover:underline", onClick: function () { + return (_jsx(_Fragment, { children: _jsxs("div", __assign({ className: "p-4 md:p-5" }, { children: ["You created a\u00A0", _jsx(Link, __assign({ to: "/objects/".concat(functionResult._rev), className: "font-medium text-blue-600 dark:text-blue-500 hover:underline", onClick: function () { navigate("/objects/".concat(functionResult._rev)); window.location.reload(); - } }, { children: "smart object" })), "."] })) }); - return _jsxs("p", __assign({ className: "text-base leading-relaxed text-gray-500 dark:text-gray-400" }, { children: ["You created the value below at Revision ", functionResult._rev, _jsx("pre", { children: functionResult.res.toString() })] })); + } }, { children: "smart object" })), "."] })) })); + return (_jsxs("p", __assign({ className: "text-base leading-relaxed text-gray-500 dark:text-gray-400" }, { children: ["You created the value below at Revision ", functionResult._rev, _jsx("pre", { children: functionResult.res.toString() })] }))); } diff --git a/packages/components/built/common/TypeSelectionDropdown.js b/packages/components/built/common/TypeSelectionDropdown.js index ebc47182c..b41a12607 100644 --- a/packages/components/built/common/TypeSelectionDropdown.js +++ b/packages/components/built/common/TypeSelectionDropdown.js @@ -11,11 +11,11 @@ var __assign = (this && this.__assign) || function () { }; import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime"; import { useEffect, useState } from "react"; -import { Dropdown, initFlowbite, } from "flowbite"; +import { Dropdown, initFlowbite } from "flowbite"; export var TypeSelectionDropdown = function (_a) { var id = _a.id, onSelectMethod = _a.onSelectMethod, dropdownList = _a.dropdownList, selectedType = _a.selectedType; var _b = useState(), dropDown = _b[0], setDropdown = _b[1]; - var _c = useState(selectedType ? selectedType : "Type"), type = _c[0], setType = _c[1]; + var _c = useState(selectedType || "Type"), type = _c[0], setType = _c[1]; var dropdownSelectionList = useState(dropdownList)[0]; useEffect(function () { initFlowbite(); @@ -26,17 +26,17 @@ export var TypeSelectionDropdown = function (_a) { triggerType: "click", offsetSkidding: 0, offsetDistance: 10, - delay: 300, + delay: 300 }; var instanceOptions = { id: "dropdownMenu".concat(id), - override: true, + override: true }; setDropdown(new Dropdown($targetEl, $triggerEl, options, instanceOptions)); }, [id]); - var handleClick = function (type) { - setType(type); - onSelectMethod(type); + var handleClick = function (clickType) { + setType(clickType); + onSelectMethod(clickType); if (dropDown) dropDown.hide(); }; diff --git a/packages/components/built/common/utils.js b/packages/components/built/common/utils.js index 40f4f1033..0a9d9b37b 100644 --- a/packages/components/built/common/utils.js +++ b/packages/components/built/common/utils.js @@ -56,12 +56,13 @@ export var strip = function (value) { return value; if (isJArray(value)) return value.map(strip); + // eslint-disable-next-line var _id = value._id, _root = value._root, _rev = value._rev, _amount = value._amount, _owners = value._owners, rest = __rest(value, ["_id", "_root", "_rev", "_amount", "_owners"]); return rest; }; // https://github.com/GoogleChromeLabs/jsbi/issues/30 export var toObject = function (obj) { - return JSON.stringify(obj, function (key, value) { return typeof value === 'bigint' ? value.toString() : value; }, 2); + return JSON.stringify(obj, function (key, value) { return (typeof value === "bigint" ? value.toString() : value); }, 2); }; export var capitalizeFirstLetter = function (string) { return string.charAt(0).toUpperCase() + string.slice(1); @@ -72,4 +73,5 @@ export function isValidRevString(outId) { export function isValidRev(value) { return typeof value === "string" && isValidRevString(value); } +// eslint-disable-next-line export var sleep = function (ms) { return new Promise(function (resolve) { return setTimeout(resolve, ms); }); }; diff --git a/packages/components/package.json b/packages/components/package.json index 0adb6efad..6f1bf88c2 100644 --- a/packages/components/package.json +++ b/packages/components/package.json @@ -23,7 +23,10 @@ "eslint-plugin-import": "^2.29.1", "flowbite": "^2.3.0", "react": "^18.2.0", - "react-dom": "^18.2.0" + "react-dom": "^18.2.0", + "react-icons": "^5.2.1", + "react-router-dom": "^6.23.1", + "react-string-replace": "^1.1.1" }, "devDependencies": { "@babel/preset-react": "^7.23.3", diff --git a/packages/components/src/Auth.tsx b/packages/components/src/Auth.tsx index 73e970f48..1f4e75cbc 100644 --- a/packages/components/src/Auth.tsx +++ b/packages/components/src/Auth.tsx @@ -1,8 +1,8 @@ import { Dispatch, useEffect, useState } from "react" import { Computer } from "@bitcoin-computer/lib" +import { initFlowbite } from "flowbite" import { useUtilsComponents } from "./UtilsContext" import { Modal } from "./Modal" -import { initFlowbite } from "flowbite" import type { Chain, Network } from "./common/types" function isLoggedIn(): boolean { @@ -335,18 +335,8 @@ function LoginButton({ mnemonic, chain, network, path, url }: any) { const login = (e: React.MouseEvent) => { e.preventDefault() - try { - if (isLoggedIn()) throw new Error("A user is already logged in, please log out first.") - - if (mnemonic.length === 0) throw new Error("Please don't use an empty mnemonic string.") - - new Computer({ mnemonic, chain, network, path, url }) - } catch (error) { - if (error instanceof Error) { - showSnackBar(error.message, false) - } - return - } + if (isLoggedIn()) showSnackBar("A user is already logged in, please log out first.", false) + if (mnemonic.length === 0) showSnackBar("Please don't use an empty mnemonic string.", false) localStorage.setItem("BIP_39_KEY", mnemonic) localStorage.setItem("CHAIN", chain) localStorage.setItem("NETWORK", network) diff --git a/packages/components/src/SmartObject.tsx b/packages/components/src/SmartObject.tsx index 657105cc7..8997b7f72 100644 --- a/packages/components/src/SmartObject.tsx +++ b/packages/components/src/SmartObject.tsx @@ -48,111 +48,111 @@ const SmartObjectValues = ({ smartObject }: any) => { ) } -const revToId = (rev: string) => rev?.split(":")[0] - -const MetaData = ({ smartObject }: any) => ( - <> -

Meta Data

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Key - - Short - - Value -
Identity -
_id
-
- - {smartObject?._id} - -
Revision -
_rev
-
- - {smartObject?._rev} - -
Root -
_root
-
- - {smartObject?._root} - -
Owners -
_owners
-
- - {smartObject?._owners} - -
Amount -
_amount
-
- - {smartObject?._amount} - -
Transaction - - {revToId(smartObject?._rev)} - -
- -) +// const revToId = (rev: string) => rev?.split(":")[0] + +// const MetaData = ({ smartObject }: any) => ( +// <> +//

Meta Data

+// +// +// +// +// +// +// +// +// +// +// +// +// +// + +// +// +// +// +// + +// +// +// +// +// + +// +// +// +// +// + +// +// +// +// +// + +// +// +// +// +// +// +//
+// Key +// +// Short +// +// Value +//
Identity +//
_id
+//
+// +// {smartObject?._id} +// +//
Revision +//
_rev
+//
+// +// {smartObject?._rev} +// +//
Root +//
_root
+//
+// +// {smartObject?._root} +// +//
Owners +//
_owners
+//
+// +// {smartObject?._owners} +// +//
Amount +//
_amount
+//
+// +// {smartObject?._amount} +// +//
Transaction +// +// {revToId(smartObject?._rev)} +// +//
+// +// ) function Component() { const location = useLocation() @@ -168,7 +168,11 @@ function Component() { const [modalTitle, setModalTitle] = useState("") const setShow: any = (flag: boolean) => { - flag ? Modal.get(modalId).show() : Modal.get(modalId).hide() + if (flag) { + Modal.get(modalId).show() + } else { + Modal.get(modalId).hide() + } } useEffect(() => { @@ -194,11 +198,11 @@ function Component() { key !== "constructor" && typeof Object.getPrototypeOf(smartObject)[key] === "function" ) - for (const key in filteredSmartObject) { + Object.keys(filteredSmartObject).forEach((key) => { if (key) { funcExist = true } - } + }) } setFunctionsExist(funcExist) }, [smartObject]) diff --git a/packages/components/src/SmartObjectFunction.tsx b/packages/components/src/SmartObjectFunction.tsx index 2fac153fa..2dfa79961 100644 --- a/packages/components/src/SmartObjectFunction.tsx +++ b/packages/components/src/SmartObjectFunction.tsx @@ -17,7 +17,7 @@ export const getErrorMessage = (error: any): string => { return error.message ? error.message : "Error occurred" } -export const getFnParamNames = function (fn: string) { +export const getFnParamNames = (fn: string) => { const match = fn.toString().match(/\(.*?\)/) return match ? match[0].replace(/[()]/gi, "").replace(/\s/gi, "").split(",") : [] } @@ -55,7 +55,7 @@ export const SmartObjectFunction = ({ const handleSmartObjectMethod = async ( event: any, - smartObject: any, + smartObj: any, fnName: string, params: string[] ) => { @@ -76,13 +76,16 @@ export const SmartObjectFunction = ({ exp: `smartObject.${fnName}(${params.map((param) => { const key = `${fnName}-${param}` const paramValue = getValueForType(formState[`${key}--types`], formState[key]) - return isValidRev(paramValue) - ? param - : typeof paramValue === "string" - ? `'${paramValue}'` - : paramValue + + if (isValidRev(paramValue)) { + return param + } + if (typeof paramValue === "string") { + return `'${paramValue}'` + } + return paramValue })})`, - env: { smartObject: smartObject._rev, ...revMap }, + env: { smartObject: smartObj._rev, ...revMap }, fund: true, sign: true }) diff --git a/packages/components/src/Transaction.tsx b/packages/components/src/Transaction.tsx index fae37b3d2..0c1c348ed 100644 --- a/packages/components/src/Transaction.tsx +++ b/packages/components/src/Transaction.tsx @@ -7,20 +7,20 @@ import { ComputerContext } from "./ComputerContext" function ExpressionCard({ content, env }: { content: string; env: { [s: string]: string } }) { const entries = Object.entries(env) let formattedContent = content as any - for (const entry of entries) { + entries.forEach((entry) => { const [name, rev] = entry const regExp = new RegExp(`(${name})`, "g") - const replacer = (name: string, i: number) => ( + const replacer = (n: string) => ( - {name} + {n} ) formattedContent = reactStringReplace(formattedContent, regExp, replacer) - } + }) return } diff --git a/packages/components/src/common/TypeSelectionDropdown.tsx b/packages/components/src/common/TypeSelectionDropdown.tsx index fd8d5fb2b..f2ae5b6bd 100644 --- a/packages/components/src/common/TypeSelectionDropdown.tsx +++ b/packages/components/src/common/TypeSelectionDropdown.tsx @@ -30,9 +30,9 @@ export const TypeSelectionDropdown = ({ id, onSelectMethod, dropdownList, select setDropdown(new Dropdown($targetEl, $triggerEl, options, instanceOptions)) }, [id]) - const handleClick = (type: string) => { - setType(type) - onSelectMethod(type) + const handleClick = (clickType: string) => { + setType(clickType) + onSelectMethod(clickType) if (dropDown) dropDown.hide() } diff --git a/packages/components/src/common/utils.ts b/packages/components/src/common/utils.ts index 3158bd13e..08ea09a04 100644 --- a/packages/components/src/common/utils.ts +++ b/packages/components/src/common/utils.ts @@ -1,3 +1,4 @@ +// eslint-disable-next-line type Json = JBasic | JObject | JArray type JBasic = undefined | null | boolean | number | string | symbol | bigint type JArray = Json[] @@ -43,6 +44,7 @@ export const jsonMap = export const strip = (value: Json): Json => { if (isJBasic(value)) return value if (isJArray(value)) return value.map(strip) + // eslint-disable-next-line const { _id, _root, _rev, _amount, _owners, ...rest } = value return rest } @@ -62,4 +64,5 @@ export function isValidRev(value: any): boolean { return typeof value === "string" && isValidRevString(value) } +// eslint-disable-next-line export const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)) diff --git a/packages/cra-template/src/App.tsx b/packages/cra-template/src/App.tsx index 4f97be861..f7cc56763 100644 --- a/packages/cra-template/src/App.tsx +++ b/packages/cra-template/src/App.tsx @@ -1,7 +1,6 @@ import "./App.css" -import { useContext, useEffect, useState } from "react" +import { useEffect, useState } from "react" import { BrowserRouter, Route, Routes, Navigate } from "react-router-dom" -import { Navbar } from "./components/Navbar" import { initFlowbite } from "flowbite" import { Auth, @@ -12,6 +11,7 @@ import { Transaction, ComputerContext } from "@bitcoin-computer/components" +import { Navbar } from "./components/Navbar" import Mint from "./components/Mint" import { AllAssets, MyAssets } from "./components/Assets" diff --git a/packages/cra-template/src/components/Mint.tsx b/packages/cra-template/src/components/Mint.tsx index 2d8971a53..0d18fb76c 100644 --- a/packages/cra-template/src/components/Mint.tsx +++ b/packages/cra-template/src/components/Mint.tsx @@ -1,7 +1,7 @@ import { useContext, useState } from "react" import { ComputerContext, Modal } from "@bitcoin-computer/components" -import { Counter } from "../contracts/counter" import { Link } from "react-router-dom" +import { Counter } from "../contracts/counter" function SuccessContent(rev: string) { return ( diff --git a/packages/cra-template/src/types/global.d.ts b/packages/cra-template/src/types/global.d.ts index 755cba884..89850bda3 100644 --- a/packages/cra-template/src/types/global.d.ts +++ b/packages/cra-template/src/types/global.d.ts @@ -1 +1 @@ -declare var Contract: any +declare const Contract: any diff --git a/packages/explorer/src/App.tsx b/packages/explorer/src/App.tsx index 8b18bfef7..0a921ded2 100644 --- a/packages/explorer/src/App.tsx +++ b/packages/explorer/src/App.tsx @@ -1,11 +1,6 @@ import './App.css' -import { useContext, useEffect, useState } from 'react' -import { BrowserRouter, Route, Routes, Navigate } from 'react-router-dom' -import NavBar from './components/Navbar' -import Block from './components/Block' -import Blocks from './components/Blocks' -import Module from './components/Module' -import Playground from './components/playground/Playground' +import { useEffect, useState } from 'react' +import { BrowserRouter, Route, Routes } from 'react-router-dom' import { initFlowbite } from 'flowbite' import { Auth, @@ -17,6 +12,11 @@ import { Wallet, ComputerContext } from '@bitcoin-computer/components' +import NavBar from './components/Navbar' +import Block from './components/Block' +import Blocks from './components/Blocks' +import Module from './components/Module' +import Playground from './components/playground/Playground' export default function App() { const [computer] = useState(Auth.getComputer()) diff --git a/packages/explorer/src/components/Block.tsx b/packages/explorer/src/components/Block.tsx index 4c2e495ac..e5527ccfd 100644 --- a/packages/explorer/src/components/Block.tsx +++ b/packages/explorer/src/components/Block.tsx @@ -8,21 +8,17 @@ function Block() { const params = useParams() const computer = useContext(ComputerContext) const [block] = useState(params.block) - const [isLoading, setIsLoading] = useState(false) const [blockData, setBlockData] = useState(null) const { showSnackBar, showLoader } = UtilsContext.useUtilsComponents() useEffect(() => { const fetch = async () => { try { - // setIsLoading(true) showLoader(true) const res = await computer.rpcCall('getblock', `${block} 2`) setBlockData(res.result) - // setIsLoading(false) showLoader(false) } catch (error) { - // setIsLoading(false) showLoader(false) showSnackBar('Error getting block', false) } @@ -122,32 +118,30 @@ function Block() { - {blockData?.tx?.map((txn: any) => { - return ( - ( + + - handleClick(txn.txid)} > - - - - ) - })} + {txn.txid} + + + + ))} )} - {!blockData && !isLoading && ( + {!blockData && (

Not a valid block hash {block}

diff --git a/packages/explorer/src/components/Blocks.tsx b/packages/explorer/src/components/Blocks.tsx index 584213459..1c6390130 100644 --- a/packages/explorer/src/components/Blocks.tsx +++ b/packages/explorer/src/components/Blocks.tsx @@ -36,9 +36,7 @@ export default function Blocks() { setIsNextAvailable(false) length = totalBlocks - (pageNum * blocksPerPage + blocksPerPage - 1) + blocksPerPage - 1 } - setBlocks( - Array.from({ length: length }, (_, i) => totalBlocks - (pageNum * blocksPerPage + i)) - ) + setBlocks(Array.from({ length }, (_, i) => totalBlocks - (pageNum * blocksPerPage + i))) } catch (error) { showSnackBar('Error setting blocks', false) console.log('Error setting blocks', error) @@ -74,20 +72,18 @@ export default function Blocks() { - {blocks.map((block) => { - return ( - - - - - - ) - })} + {blocks.map((block) => ( + + + + + + ))} {blocks.length > 0 && ( diff --git a/packages/explorer/src/components/Error404.tsx b/packages/explorer/src/components/Error404.tsx index 7ecc5470b..1d23f71a4 100644 --- a/packages/explorer/src/components/Error404.tsx +++ b/packages/explorer/src/components/Error404.tsx @@ -1,3 +1 @@ -export const Error404 = () => { - return <> -} +export const Error404 = () => <> diff --git a/packages/explorer/src/components/Module.tsx b/packages/explorer/src/components/Module.tsx index 5225f3da5..195344107 100644 --- a/packages/explorer/src/components/Module.tsx +++ b/packages/explorer/src/components/Module.tsx @@ -1,8 +1,8 @@ import { useContext, useEffect, useState } from 'react' import { useParams } from 'react-router-dom' +import { ComputerContext, UtilsContext } from '@bitcoin-computer/components' import { capitalizeFirstLetter } from '../utils' import { Card } from './Card' -import { ComputerContext, UtilsContext } from '@bitcoin-computer/components' function Module() { const computer = useContext(ComputerContext) diff --git a/packages/explorer/src/components/Navbar.tsx b/packages/explorer/src/components/Navbar.tsx index 6228d9c13..426c637a8 100644 --- a/packages/explorer/src/components/Navbar.tsx +++ b/packages/explorer/src/components/Navbar.tsx @@ -1,8 +1,8 @@ import { Link } from 'react-router-dom' import { Modal, Auth, UtilsContext, Drawer } from '@bitcoin-computer/components' -import { SearchBar } from './SearchBar' import { useEffect, useState } from 'react' import { initFlowbite } from 'flowbite' +import { SearchBar } from './SearchBar' import { Chain, Network } from '../types/common' const modalTitle = 'Connect to Node' @@ -146,7 +146,6 @@ function ModalContent() { function NotLoggedMenu() { const [dropDownLabel, setDropDownLabel] = useState('LTC') - const { showSnackBar } = UtilsContext.useUtilsComponents() useEffect(() => { initFlowbite() diff --git a/packages/explorer/src/components/SearchBar.tsx b/packages/explorer/src/components/SearchBar.tsx index 548af4dad..00ea98910 100644 --- a/packages/explorer/src/components/SearchBar.tsx +++ b/packages/explorer/src/components/SearchBar.tsx @@ -1,4 +1,4 @@ -import { useContext, useRef, useState } from 'react' +import { useContext, useRef } from 'react' import { useNavigate } from 'react-router-dom' import { ComputerContext } from '@bitcoin-computer/components' import { isValidHexadecimalPublicKey } from '../utils' @@ -9,12 +9,6 @@ export function SearchBar() { const computer = useContext(ComputerContext) const navigate = useNavigate() - const handleSearch = (event: React.KeyboardEvent) => { - if (event.key === 'Enter') { - search(inputRef?.current?.value) - } - } - const search = async (searchInput: string | undefined) => { if (searchInput) { if (searchInput === '') navigate('/') @@ -31,6 +25,12 @@ export function SearchBar() { } } + const handleSearch = (event: React.KeyboardEvent) => { + if (event.key === 'Enter') { + search(inputRef?.current?.value) + } + } + return ( { const [dropDown, setDropdown] = useState() - const [type, setType] = useState(selectedType ? selectedType : 'Type') + const [type, setType] = useState(selectedType || 'Type') const [dropdownSelectionList] = useState(dropdownList) useEffect(() => { @@ -26,9 +25,9 @@ export const TypeSelectionDropdown = ({ id, onSelectMethod, dropdownList, select setDropdown(new Dropdown($targetEl, $triggerEl, options, instanceOptions)) }, [id]) - const handleClick = (type: string) => { - setType(type) - onSelectMethod(type) + const handleClick = (t: string) => { + setType(t) + onSelectMethod(t) if (dropDown) dropDown.hide() } diff --git a/packages/explorer/src/components/playground/CreateNew.tsx b/packages/explorer/src/components/playground/CreateNew.tsx index aabe5c5a9..bd77cc7b4 100644 --- a/packages/explorer/src/components/playground/CreateNew.tsx +++ b/packages/explorer/src/components/playground/CreateNew.tsx @@ -1,10 +1,10 @@ import { Dispatch, SetStateAction, useEffect, useState } from 'react' -import { TypeSelectionDropdown } from '../TypeSelectionDropdown' import { IoMdRemoveCircleOutline } from 'react-icons/io' import { Computer } from '@bitcoin-computer/lib' +import { UtilsContext } from '@bitcoin-computer/components' +import { TypeSelectionDropdown } from '../TypeSelectionDropdown' import { getErrorMessage, getValueForType, isValidRev, sleep } from '../../utils' import { ModSpec } from './Modspec' -import { UtilsContext } from '@bitcoin-computer/components' interface Argument { type: string @@ -30,6 +30,7 @@ const CreateNew = (props: { useEffect(() => { const newArgumentsList = [...argumentsList] newArgumentsList.forEach((argument) => { + // eslint-disable-next-line argument.hidden = true }) if (exampleVars) { @@ -64,6 +65,7 @@ const CreateNew = (props: { const handleDeploy = async () => { try { showLoader(true) + // eslint-disable-next-line const createClassFunction = new Function(`return ${code?.trim()}`) const dynamicClass = createClassFunction() if ( @@ -89,11 +91,15 @@ const CreateNew = (props: { .filter((argument) => !argument.hidden) .map((argument, index) => { const argValue = getValueForType(argument.type, argument.value) - return isValidRev(argValue) - ? `param${index}` - : typeof argValue === 'string' - ? `'${argValue}'` - : argValue + if (isValidRev(argValue)) { + return `param${index}` + } + + if (typeof argValue === 'string') { + return `'${argValue}'` + } + + return argValue })}) `, env: { ...revMap }, @@ -101,7 +107,7 @@ const CreateNew = (props: { sign: true } if (modSpec) { - encodeObject['mod'] = modSpec + encodeObject.mod = modSpec } const { tx } = (await computer.encode(encodeObject)) as any @@ -159,6 +165,7 @@ const CreateNew = (props: { { + // eslint-disable-next-line argument.type = option }} dropdownList={options} diff --git a/packages/explorer/src/components/playground/DeployModule.tsx b/packages/explorer/src/components/playground/DeployModule.tsx index 0c014e0e1..3eb572ec3 100644 --- a/packages/explorer/src/components/playground/DeployModule.tsx +++ b/packages/explorer/src/components/playground/DeployModule.tsx @@ -1,7 +1,7 @@ import { Dispatch, SetStateAction, useEffect, useState } from 'react' import { Computer } from '@bitcoin-computer/lib' -import { getErrorMessage } from '../../utils' import { UtilsContext } from '@bitcoin-computer/components' +import { getErrorMessage } from '../../utils' const DeployModule = (props: { computer: Computer diff --git a/packages/explorer/src/components/playground/ExecuteExpression.tsx b/packages/explorer/src/components/playground/ExecuteExpression.tsx index 8e0c92118..717040dfa 100644 --- a/packages/explorer/src/components/playground/ExecuteExpression.tsx +++ b/packages/explorer/src/components/playground/ExecuteExpression.tsx @@ -1,9 +1,9 @@ import { Dispatch, SetStateAction, useEffect, useState } from 'react' import { IoMdRemoveCircleOutline } from 'react-icons/io' import { Computer } from '@bitcoin-computer/lib' +import { UtilsContext } from '@bitcoin-computer/components' import { getErrorMessage, isValidRev } from '../../utils' import { ModSpec } from './Modspec' -import { UtilsContext } from '@bitcoin-computer/components' interface ExpressionArgument { name: string @@ -57,7 +57,7 @@ const ExecuteExpression = (props: { const revMap: any = {} expressionArgumentsList .filter((argument) => !argument.hidden) - .forEach((argument, index) => { + .forEach((argument) => { const argValue = argument.value if (isValidRev(argValue)) { revMap[argument.name] = argValue @@ -71,7 +71,7 @@ const ExecuteExpression = (props: { sign: true } if (modSpec) { - encodeObject['mod'] = modSpec + encodeObject.mod = modSpec } const { tx, effect } = (await computer.encode({ diff --git a/packages/explorer/src/components/playground/Modspec.tsx b/packages/explorer/src/components/playground/Modspec.tsx index f33276b6a..8d0c39f84 100644 --- a/packages/explorer/src/components/playground/Modspec.tsx +++ b/packages/explorer/src/components/playground/Modspec.tsx @@ -1,22 +1,20 @@ -export const ModSpec = ({ modSpec, setModSpec }: { modSpec: any; setModSpec: any }) => { - return ( - <> -
-
-

- Module Specifier - Optional -

-
- setModSpec(e.target.value)} - className="sm:w-full md:w-2/3 lg:w-1/2 mr-4 bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" - placeholder="mod spec" - required - /> +export const ModSpec = ({ modSpec, setModSpec }: { modSpec: any; setModSpec: any }) => ( + <> +
+
+

+ Module Specifier + Optional +

- - ) -} + setModSpec(e.target.value)} + className="sm:w-full md:w-2/3 lg:w-1/2 mr-4 bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" + placeholder="mod spec" + required + /> +
+ +) diff --git a/packages/explorer/src/components/playground/Playground.tsx b/packages/explorer/src/components/playground/Playground.tsx index 376b2ee21..22141b670 100644 --- a/packages/explorer/src/components/playground/Playground.tsx +++ b/packages/explorer/src/components/playground/Playground.tsx @@ -1,8 +1,9 @@ import { useEffect, useState } from 'react' +import { initFlowbite } from 'flowbite' +import { Auth, Modal, FunctionResultModalContent } from '@bitcoin-computer/components' import CreateNew from './CreateNew' import ExecuteExpression from './ExecuteExpression' import DeployModule from './DeployModule' -import { initFlowbite } from 'flowbite' import { chat, chatExport, @@ -21,109 +22,104 @@ import { nftVars, tokenVars } from './examples' -import { Auth, Modal, FunctionResultModalContent } from '@bitcoin-computer/components' const modalId = 'playground-info-modal' -const Examples = ({ loadExamples, clearExamples }: { loadExamples: any; clearExamples: any }) => { - return ( - <> -
-

Load Examples

-
-
- +const Examples = ({ loadExamples, clearExamples }: { loadExamples: any; clearExamples: any }) => ( + <> +
+

Load Examples

+
+
+ + + + +
+ + +) + +const Tabs = () => ( +
+
    +
  • +
  • +
  • +
  • +
  • -
- - - ) -} - -const Tabs = () => { - return ( -
-
    -
  • - -
  • -
  • - -
  • -
  • - -
  • -
-
- ) -} + + +
+) const Playground = () => { const [computer] = useState(Auth.getComputer()) @@ -135,7 +131,11 @@ const Playground = () => { const [modalTitle, setModalTitle] = useState('') const setShow: any = (flag: boolean) => { - flag ? Modal.get(modalId).show() : Modal.get(modalId).hide() + if (flag) { + Modal.get(modalId).show() + } else { + Modal.get(modalId).hide() + } } useEffect(() => { diff --git a/packages/explorer/src/types/global.d.ts b/packages/explorer/src/types/global.d.ts index 755cba884..89850bda3 100644 --- a/packages/explorer/src/types/global.d.ts +++ b/packages/explorer/src/types/global.d.ts @@ -1 +1 @@ -declare var Contract: any +declare const Contract: any diff --git a/packages/explorer/src/utils.ts b/packages/explorer/src/utils.ts index 79738d5eb..3390dcfef 100644 --- a/packages/explorer/src/utils.ts +++ b/packages/explorer/src/utils.ts @@ -14,6 +14,7 @@ export function isValidRev(value: any): boolean { // eslint-disable-next-line export const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)) +// eslint-disable-next-line type Json = JBasic | JObject | JArray type JBasic = undefined | null | boolean | number | string | symbol | bigint type JArray = Json[] @@ -59,6 +60,7 @@ export const jsonMap = export const strip = (value: Json): Json => { if (isJBasic(value)) return value if (isJArray(value)) return value.map(strip) + // eslint-disable-next-line const { _id, _root, _rev, _amount, _owners, ...rest } = value return rest } @@ -95,7 +97,7 @@ export const capitalizeFirstLetter = (string: string) => export const isValidHexadecimalPublicKey = (publicKey: string): boolean => { if (!publicKey) return false - let trimmedPublicKey = publicKey.trim() + const trimmedPublicKey = publicKey.trim() return trimmedPublicKey.length === 64 || trimmedPublicKey.length === 66 } @@ -105,11 +107,13 @@ export const getErrorMessage = (error: any): string => { 'mandatory-script-verify-flag-failed (Operation not valid with the current stack size)' ) { return 'You are not authorised to make changes to this smart object' - } else if (error?.response?.data?.error) { + } + + if (error?.response?.data?.error) { return error?.response?.data?.error - } else { - return error.message ? error.message : 'Error occurred' } + + return error.message ? error.message : 'Error occurred' } // https://github.com/GoogleChromeLabs/jsbi/issues/30 diff --git a/packages/wallet/package.json b/packages/wallet/package.json index 624e2e49d..e9c790f88 100644 --- a/packages/wallet/package.json +++ b/packages/wallet/package.json @@ -3,6 +3,7 @@ "version": "0.19.0-beta.0", "private": true, "dependencies": { + "@bitcoin-computer/components": "^0.19.0-beta.0", "@bitcoin-computer/lib": "^0.19.0-beta.0", "@testing-library/jest-dom": "^6.4.2", "@testing-library/react": "^14.2.1", diff --git a/packages/wallet/src/App.tsx b/packages/wallet/src/App.tsx index 0dafa2f3f..ae535b29c 100644 --- a/packages/wallet/src/App.tsx +++ b/packages/wallet/src/App.tsx @@ -8,12 +8,12 @@ import { UtilsContext, ComputerContext } from "@bitcoin-computer/components" +import { useState } from "react" import { Send } from "./components/Send" import { Details } from "./components/Details" import Transactions from "./components/Transactions" import { Assets } from "./components/Assets" import { SideBar } from "./components/Sidebar" -import { useState } from "react" export default function App() { const [computer] = useState(Auth.getComputer()) diff --git a/packages/wallet/src/components/Details.tsx b/packages/wallet/src/components/Details.tsx index a66150417..d673950d9 100644 --- a/packages/wallet/src/components/Details.tsx +++ b/packages/wallet/src/components/Details.tsx @@ -5,7 +5,7 @@ import { Computer } from "@bitcoin-computer/lib" export const Details = () => { const [computer] = useState(Auth.getComputer()) - const Mnemonic = ({ computer }: any) => { + const Mnemonic = ({ computer: comp }: any) => { const [showMnemonic, setShowMnemonic] = useState(false) const Heading = () =>

Mnemonic

@@ -14,10 +14,7 @@ export const Details = () => { return (
-

- {/* @ts-ignore */} - {computer.getMnemonic()} -

+

{comp?.getMnemonic()}

) - else - return ( -
- - -
-
- ) + return ( +
+ + +
+
+ ) } return ( @@ -59,16 +55,10 @@ export const Details = () => {

{computer.getNetwork()}

Path

-

- {/* @ts-ignore */} - {computer.getPath() as any} -

+

{computer.getPath() as any}

Url

-

- {/* @ts-ignore */} - {computer.getUrl() as any} -

+

{computer.getUrl() as any}

diff --git a/packages/wallet/src/components/Navbar.tsx b/packages/wallet/src/components/Navbar.tsx index 7bf701f46..96e992681 100644 --- a/packages/wallet/src/components/Navbar.tsx +++ b/packages/wallet/src/components/Navbar.tsx @@ -1,8 +1,7 @@ import { Computer } from "@bitcoin-computer/lib" import { initFlowbite } from "flowbite" import { Dispatch, useEffect, useState } from "react" -import { useNavigate } from "react-router-dom" -import { Link } from "react-router-dom" +import { useNavigate, Link } from "react-router-dom" import { explorerURL } from "../config" import { isValidHexadecimalPrivateKey } from "../utils" @@ -22,7 +21,7 @@ export default function Navbar({ const isLoggedIn = !!localStorage.getItem("BIP_39_KEY") const search = async (event: any) => { - var code = event.keyCode || event.which + const code = event.keyCode || event.which if (code === 13) { if (searchInput === "") navigate("/") else if (searchInput.includes(":")) { diff --git a/packages/wallet/src/components/Send.tsx b/packages/wallet/src/components/Send.tsx index 3294c0a1c..a8242f93b 100644 --- a/packages/wallet/src/components/Send.tsx +++ b/packages/wallet/src/components/Send.tsx @@ -10,8 +10,7 @@ export function SentTransactions({ computer }: { computer: Computer }) { const [txs, setTxs] = useState({ sentTxs: [], receivedTxs: [] }) const updateTxs = useCallback(async () => { - // @ts-ignore - setTxs(await computer.listTxs()) + setTxs((await computer.listTxs()) as any) }, [computer]) useEffect(() => { diff --git a/packages/wallet/src/components/Transactions.tsx b/packages/wallet/src/components/Transactions.tsx index d756591e5..5c63aa078 100644 --- a/packages/wallet/src/components/Transactions.tsx +++ b/packages/wallet/src/components/Transactions.tsx @@ -1,17 +1,16 @@ import { initFlowbite } from "flowbite" import { useCallback, useContext, useEffect, useState } from "react" import { HiRefresh } from "react-icons/hi" +import { ComputerContext } from "@bitcoin-computer/components" import TransactionTable from "./TransactionTable" import { TableTxs } from "../types/common" -import { ComputerContext } from "@bitcoin-computer/components" export default function Transactions() { const computer = useContext(ComputerContext) const [txs, setTxs] = useState({ sentTxs: [], receivedTxs: [] }) const updateTxs = useCallback(async () => { - // @ts-ignore - setTxs(await computer.listTxs()) + setTxs((await computer.listTxs()) as any) }, [computer]) useEffect(() => { diff --git a/packages/wallet/src/components/TypeSelectionDropdown.tsx b/packages/wallet/src/components/TypeSelectionDropdown.tsx index 7d420dc7c..6e38cc3f9 100644 --- a/packages/wallet/src/components/TypeSelectionDropdown.tsx +++ b/packages/wallet/src/components/TypeSelectionDropdown.tsx @@ -1,11 +1,10 @@ import { Dropdown, initFlowbite } from "flowbite" -import type { DropdownOptions, DropdownInterface } from "flowbite" -import type { InstanceOptions } from "flowbite" +import type { DropdownOptions, DropdownInterface, InstanceOptions } from "flowbite" import { useEffect, useState } from "react" export const TypeSelectionDropdown = ({ id, onSelectMethod, dropdownList, selectedType }: any) => { const [dropDown, setDropdown] = useState() - const [type, setType] = useState(selectedType ? selectedType : "Type") + const [type, setType] = useState(selectedType || "Type") const [dropdownSelectionList] = useState(dropdownList) useEffect(() => { @@ -26,9 +25,9 @@ export const TypeSelectionDropdown = ({ id, onSelectMethod, dropdownList, select setDropdown(new Dropdown($targetEl, $triggerEl, options, instanceOptions)) }, []) - const handleClick = (type: string) => { - setType(type) - onSelectMethod(type) + const handleClick = (clicktType: string) => { + setType(clicktType) + onSelectMethod(clicktType) if (dropDown) dropDown.hide() } diff --git a/packages/wallet/src/components/Utils/Drawer.tsx b/packages/wallet/src/components/Utils/Drawer.tsx index 814e2c1ca..5c8b4f8fd 100644 --- a/packages/wallet/src/components/Utils/Drawer.tsx +++ b/packages/wallet/src/components/Utils/Drawer.tsx @@ -1,10 +1,8 @@ import { initFlowbite } from "flowbite" -import { useCallback, useEffect, useState } from "react" -import { HiRefresh } from "react-icons/hi" +import { useEffect, useState } from "react" import { chunk } from "../../utils" export const CustomDrawer = ({ id, computer }: any) => { - const [balance, setBalance] = useState(0) const [showMnemonic, setShowMnemonic] = useState(false) function Card({ content }: { content: string }) { @@ -23,10 +21,11 @@ export const CustomDrawer = ({ id, computer }: any) => { const mnemonicWell = () => { const mnemonicChunks = chunk(computer.getMnemonic().split(" ")) - const mnemonicChunksString = mnemonicChunks.map((chunk) => chunk.join(" ") + "\n").join(" ") + const mnemonicChunksString = mnemonicChunks.map((batch) => `${batch.join(" ")}\n`).join(" ") + return ( <> - +