add wallet page

This commit is contained in:
callebtc 2023-04-04 23:18:29 +02:00 committed by Kieran
parent 701049368e
commit 0cb006816e
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
1 changed files with 68 additions and 0 deletions

View File

@ -0,0 +1,68 @@
import { useState } from "react";
import { FormattedMessage, useIntl } from "react-intl";
import { v4 as uuid } from "uuid";
import AsyncButton from "Element/AsyncButton";
import { unwrap } from "Util";
import { CashuWallet } from "Wallet/Cashu";
import { WalletConfig, WalletKind, Wallets } from "Wallet";
import { useNavigate } from "react-router-dom";
const ConnectCashu = () => {
const navigate = useNavigate();
const { formatMessage } = useIntl();
const [config, setConfig] = useState<string>();
const [error, setError] = useState<string>();
async function tryConnect(config: string) {
try {
// const connection = new CashuWallet(config);
// await connection.login();
// const info = await connection.getInfo();
// const newWallet = {
// id: uuid(),
// kind: WalletKind.LNDHub,
// active: true,
// info,
// data: config,
// } as WalletConfig;
// Wallets.add(newWallet);
// navigate("/wallet");
} catch (e) {
if (e instanceof Error) {
setError((e as Error).message);
} else {
setError(
formatMessage({
defaultMessage: "Unknown error",
})
);
}
}
}
return (
<>
<h4>
<FormattedMessage defaultMessage="Enter LNDHub config" />
</h4>
<div className="flex">
<div className="f-grow mr10">
<input
type="text"
placeholder="lndhub://username:password@lndhub.io"
className="w-max"
value={config}
onChange={e => setConfig(e.target.value)}
/>
</div>
<AsyncButton onClick={() => tryConnect(unwrap(config))} disabled={!config}>
<FormattedMessage defaultMessage="Connect" />
</AsyncButton>
</div>
{error && <b className="error p10">{error}</b>}
</>
);
};
export default ConnectCashu;