@hypernetlabs/web-ui
Version:
Web ui react components for hypernet protocol
39 lines • 2.88 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const formik_1 = require("formik");
const react_1 = __importDefault(require("react"));
const components_1 = require("../../components");
const hooks_1 = require("../../hooks");
const WithdrawWidget = ({ noLabel, }) => {
var _a, _b;
const { tokenSelectorOptions, error, withdrawFunds, activeStateChannels = [], selectedStateChennel, } = (0, hooks_1.useFund)();
const handleFormSubmit = (values) => {
withdrawFunds(values.tokenAddress, values.amount, values.stateChannelAddress);
};
return (react_1.default.createElement(components_1.GovernanceCard, { title: !noLabel ? "Withdraw Funds" : undefined, description: !noLabel
? "Move tokens from your Hypernet account into your Ethereum wallet."
: undefined },
react_1.default.createElement(formik_1.Formik, { enableReinitialize: true, initialValues: {
tokenAddress: (_a = tokenSelectorOptions[0]) === null || _a === void 0 ? void 0 : _a.address,
amount: "1",
stateChannelAddress: (selectedStateChennel === null || selectedStateChennel === void 0 ? void 0 : selectedStateChennel.channelAddress) ||
((_b = activeStateChannels[0]) === null || _b === void 0 ? void 0 : _b.channelAddress),
}, onSubmit: handleFormSubmit }, ({ handleSubmit, values }) => {
return (react_1.default.createElement(formik_1.Form, { onSubmit: handleSubmit },
react_1.default.createElement(components_1.GovernanceDialogSelectField, { required: true, title: "Hypernet Account", name: "stateChannelAddress", options: activeStateChannels.map((option) => ({
primaryText: option.channelAddress,
value: option.channelAddress,
})) }),
react_1.default.createElement(components_1.GovernanceDialogSelectField, { required: true, title: "Token Selector", name: "tokenAddress", options: tokenSelectorOptions.map((option) => ({
primaryText: `${option.name} Chain ID:${option.chainId}`,
value: option.address,
})) }),
react_1.default.createElement(components_1.GovernanceField, { required: true, name: "amount", title: "Amount", type: "input", placeholder: "Type Amount" }),
react_1.default.createElement(components_1.GovernanceButton, { fullWidth: true, color: "primary", variant: "contained", onClick: handleSubmit, disabled: !(!!values.amount && !!values.tokenAddress) }, "Withdraw to your metamask wallet")));
})));
};
exports.default = WithdrawWidget;
//# sourceMappingURL=WithdrawWidget.js.map