Skip to content

Commit

Permalink
add toast message when wallet is not connected
Browse files Browse the repository at this point in the history
  • Loading branch information
ps1dr3x committed Nov 30, 2023
1 parent fd7ecde commit 7815ebd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/ui/internal/notification/toast.ts
Expand Up @@ -50,14 +50,14 @@ const colorText = {
success: "#00D615",
info: "#6259FF",
error: "#ED6855",
warning: "#FFCA28",
warning: "#F4BE4E",
};

const colorBg = {
success: "#CCFFD2",
info: "#6259FFd1",
error: "#FFD0CC",
warning: "#000000",
warning: "#FFF4CC",
};

const prettifyMessage = (message) => {
Expand Down
8 changes: 5 additions & 3 deletions src/wallet/index.ts
Expand Up @@ -4,6 +4,7 @@ import { networks, UnicrowNetwork } from "./networks";
import { CHAIN_ID } from "../helpers";
import { DefaultNetwork, IGenericTransactionCallbacks } from "typing";
import { config } from "../config";
import { toast } from "ui/internal/notification/toast";

let walletAddress: string | null = null;
let accountChangedListener: EventEmitter | null = null;
Expand Down Expand Up @@ -65,6 +66,8 @@ const registerAccountChangedListener = () => {
*/
export const connect = async (): Promise<string | null> => {
if (isWeb3WalletInstalled() && !walletAddress) {
toast.warning("Wallet not connected. Please connect your wallet.");

registerAccountChangedListener();

const _accounts = await window.ethereum.request({
Expand Down Expand Up @@ -300,9 +303,8 @@ export const isWeb3WalletInstalled = () => {
*/
export const getCurrentWalletAddress = async () => {
try {
await connect();
return await connect();
} catch (e) {
throw new Error("Wallet not connected. Please connect your wallet.");
throw new Error("Wallect connection rejected. Wallet not connected.");
}
return walletAddress;
};

0 comments on commit 7815ebd

Please sign in to comment.