Improve walletconnect error message

This commit is contained in:
Alexis Sellier
2021-08-04 13:11:52 +02:00
parent 061a4f75fb
commit d346f164b3
4 changed files with 16 additions and 3 deletions
+1 -2
View File
@@ -51,7 +51,6 @@
{#if $walletConnectState.state === "open"}
<ConnectWallet {config} uri={$walletConnectState.uri} on:close={onModalClose} />
{:else if error}
<Error floating title="Wallet connection failed" {error}
on:close={() => error = null} />
<Error floating emoji="👛" title="Connection failed" {error} on:close={() => error = null} />
{/if}
+4
View File
@@ -7,6 +7,7 @@
export let error: Err | null = null;
export let title = "Error";
export let emoji = "";
export let subtitle = "";
export let message = "";
export let floating = false;
@@ -18,6 +19,9 @@
<Modal on:close error {floating} {subtle}>
<span slot="title">
{#if emoji}
<div>{emoji}</div>
{/if}
{title}
</span>
+2 -1
View File
@@ -3,6 +3,7 @@ import type { BigNumber } from 'ethers';
import type { TransactionReceipt, TransactionResponse } from '@ethersproject/providers';
import { Config, getConfig } from "@app/config";
import { Unreachable, assert, assertEq } from "@app/error";
import { formatNetwork } from "@app/utils";
import * as ethers from "ethers";
export enum Connection {
@@ -99,7 +100,7 @@ export const loadState = (initial: State): Store => {
if (network.chainId !== config.network.chainId) {
config.walletConnect.client.killSession();
throw new Error(
`Network mismatch. Please switch to ${config.network.name}.`
`Network mismatch. Please switch your wallet to ${formatNetwork(config.network)}.`
);
}
store.set({ connection: Connection.Connected, session });
+9
View File
@@ -71,6 +71,15 @@ export function formatSeedApi(input: string): string {
return input;
}
export function formatNetwork(input: { name: string }): string {
let name = input.name;
if (name === "homestead") {
name = "mainnet";
}
return capitalize(name);
}
export function capitalize(s: string): string {
if (s === "") return s;
return s[0].toUpperCase() + s.substr(1);