Merge pull request #67 from cosmos/show-connected-address

Show signer address when connected
This commit is contained in:
Simon Warta 2022-06-20 20:46:31 +02:00 committed by GitHub
commit fd6fc2f0a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -26,7 +26,7 @@ const TransactionSigning = (props: Props) => {
const [walletAccount, setWalletAccount] = useState<WalletAccount>();
const [sigError, setSigError] = useState("");
const [hasSigned, setHasSigned] = useState(false);
const [walletType, setWalletType] = useState("");
const [walletType, setWalletType] = useState<"Keplr" | "Ledger">();
const [ledgerSigner, setLedgerSigner] = useState({});
const connectKeplr = async () => {
@ -40,7 +40,7 @@ const TransactionSigning = (props: Props) => {
);
setWalletAccount(tempWalletAccount);
setHasSigned(tempHasSigned);
setWalletType("keplr");
setWalletType("Keplr");
} catch (e) {
console.log("enable err: ", e);
}
@ -72,14 +72,14 @@ const TransactionSigning = (props: Props) => {
setWalletAccount(tempWalletAccount);
setHasSigned(tempHasSigned);
setLedgerSigner(offlineSigner);
setWalletType("ledger");
setWalletType("Ledger");
};
const signTransaction = async () => {
assert(state.chain.chainId, "chainId missing");
const offlineSigner =
walletType === "keplr" ? window.getOfflineSignerOnlyAmino(state.chain.chainId) : ledgerSigner;
walletType === "Keplr" ? window.getOfflineSignerOnlyAmino(state.chain.chainId) : ledgerSigner;
const signerAddress = walletAccount?.bech32Address;
assert(signerAddress, "Missing signer address");
@ -134,14 +134,22 @@ const TransactionSigning = (props: Props) => {
) : (
<>
<h2>Sign this transaction</h2>
{walletAccount ? (
<Button label="Sign transaction" onClick={signTransaction} />
) : (
<>
<Button label="Connect Keplr" onClick={connectKeplr} />
<Button label="Connect Ledger" onClick={connectLedger} />
</>
)}
<StackableContainer lessPadding lessMargin lessRadius>
{walletAccount ? (
<>
<p>
Connected signer {walletAccount.bech32Address} (
{walletType ?? "Unknown wallet type"}).
</p>
<Button label="Sign transaction" onClick={signTransaction} />
</>
) : (
<>
<Button label="Connect Keplr" onClick={connectKeplr} />
<Button label="Connect Ledger (WebUSB)" onClick={connectLedger} />
</>
)}
</StackableContainer>
</>
)}
{sigError && (