Skip to content

Commit

Permalink
feat: integrated multiple wallets (#818)
Browse files Browse the repository at this point in the history
  • Loading branch information
Teja2045 authored Oct 24, 2023
2 parents d7f4d03 + 0b79771 commit d675f21
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 8 deletions.
20 changes: 16 additions & 4 deletions frontend/src/components/TopNav.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
'use client'
"use client";
import Image from "next/image";
import React from "react";
import NetworksMenu from "./NetworksMenu";
import { useRouter } from "next/navigation";

const TopNav = ({pathname}:{pathname:string}) => {
const TopNav = ({ pathname }: { pathname: string }) => {
const router = useRouter();
return (
<div className="topNav">
<div className="topNav__title">
<h2>{pathname}</h2>
</div>
<div className="topNav__options">
<NetworksMenu />
<NetworksMenu />
<div className="topNav__options__logout">
<Image src="./logout-icon.svg" width={40} height={40} alt="Logout" />
<Image
onClick={() => {
window.location.reload();
router.push("/");
}}
className="cursor-pointer"
src="./logout-icon.svg"
width={40}
height={40}
alt="Logout"
/>
</div>
</div>
</div>
Expand Down
27 changes: 23 additions & 4 deletions frontend/src/services/walletService.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
export const isWalletInstalled = (walletName) => {
switch (walletName) {
case "keplr":
if (!window.keplr) return false;
window.wallet = window.keplr;
return true;
case "leap":
if (!window.leap) return false;
window.wallet = window.leap;
return true;
case "cosmostation":
if (!window.cosmostation?.providers?.keplr) return false;
window.wallet = window?.cosmostation?.providers?.keplr;
return true;
default:
return false;
}
};

export const connectWalletV1 = async (data) => {
const walletName = data.walletName;
const mainnets = data.mainnets;
const testnets = data.testnets;
console.log("connect wallet called...", data);
if (!window.keplr) {
alert("keplr not connected");
if (!isWalletInstalled(walletName)) {
alert("wallet is not connected");
return;
} else {
window.wallet = window.keplr;
window.wallet.defaultOptions = {
sign: {
preferNoSetMemo: true,
Expand Down Expand Up @@ -84,7 +103,7 @@ export const connectWalletV1 = async (data) => {
if (chainInfos.length === 0) {
alert("Permission denied for all the networks");
}

data.setIsConnected(true);
}
};
Expand Down

0 comments on commit d675f21

Please sign in to comment.