Skip to content

Commit

Permalink
Clot mobile wallet support (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
codingki authored May 29, 2024
2 parents 309101f + a69e8d7 commit e44137b
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 1 deletion.
3 changes: 3 additions & 0 deletions example/next/ui/connect-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ export const ConnectButton: FC = () => {
{wallets.wc_cosmostation_mobile ? (
<Button onClick={() => handleConnect(WalletType.WC_COSMOSTATION_MOBILE)}>Cosmostation Mobile</Button>
) : null}
{wallets.wc_clot_mobile ? (
<Button onClick={() => handleConnect(WalletType.WC_CLOT_MOBILE)}>Clot Mobile</Button>
) : null}
{wallets.station ? <Button onClick={() => handleConnect(WalletType.STATION)}>Station</Button> : null}
{wallets.metamask_snap_leap ? (
<Button onClick={() => handleConnect(WalletType.METAMASK_SNAP_LEAP)}>Metamask Snap Leap</Button>
Expand Down
4 changes: 4 additions & 0 deletions packages/graz/src/actions/wallet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { getWalletConnect } from "./wallet-connect";
import { getWCCosmostation } from "./wallet-connect/cosmostation";
import { getWCKeplr } from "./wallet-connect/keplr";
import { getWCLeap } from "./wallet-connect/leap";
import { getWCClot } from "./wallet-connect/clot";
import { getXDefi } from "./xdefi";

/**
Expand Down Expand Up @@ -79,6 +80,9 @@ export const getWallet = (type: WalletType = useGrazInternalStore.getState().wal
case WalletType.WC_COSMOSTATION_MOBILE: {
return getWCCosmostation();
}
case WalletType.WC_CLOT_MOBILE: {
return getWCClot();
}
case WalletType.METAMASK_SNAP_LEAP: {
return getMetamaskSnapLeap();
}
Expand Down
36 changes: 36 additions & 0 deletions packages/graz/src/actions/wallet/wallet-connect/clot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { useGrazInternalStore } from "../../../store";
import type { Wallet } from "../../../types/wallet";
import { WalletType } from "../../../types/wallet";
import { isMobile } from "../../../utils/os";
import { getWalletConnect } from ".";
import type { GetWalletConnectParams } from "./types";

export const getWCClot = (): Wallet => {
if (!useGrazInternalStore.getState().walletConnect?.options?.projectId?.trim()) {
throw new Error("walletConnect.options.projectId is not defined");
}

if (!isMobile()) throw new Error("WalletConnect Clot mobile is only supported in mobile");

const params: GetWalletConnectParams = {
encoding: "base64",
appUrl: {
mobile: {
ios: "clot://",
},
},
walletType: WalletType.WC_CLOT_MOBILE,
formatNativeUrl: (appUrl, wcUri, os) => {
const plainAppUrl = appUrl.replaceAll("/", "").replaceAll(":", "");
const encoded = encodeURIComponent(wcUri);
switch (os) {
case "ios":
return `${plainAppUrl}://wcV2?${encoded}`;
default:
return `${plainAppUrl}://wc?uri=${encoded}`;
}
},
};

return getWalletConnect(params);
};
2 changes: 1 addition & 1 deletion packages/graz/src/actions/wallet/wallet-connect/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface WalletConnectSignDirectResponse {

export interface GetWalletConnectParams {
encoding: BufferEncoding;
walletType: WalletType.WC_KEPLR_MOBILE | WalletType.WC_LEAP_MOBILE | WalletType.WC_COSMOSTATION_MOBILE;
walletType: WalletType.WC_KEPLR_MOBILE | WalletType.WC_LEAP_MOBILE | WalletType.WC_COSMOSTATION_MOBILE | WalletType.WC_CLOT_MOBILE;
appUrl: {
mobile: {
ios: string;
Expand Down
3 changes: 3 additions & 0 deletions packages/graz/src/types/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export enum WalletType {
// eslint-disable-next-line @typescript-eslint/naming-convention
WC_COSMOSTATION_MOBILE = "wc_cosmostation_mobile",
// eslint-disable-next-line @typescript-eslint/naming-convention
WC_CLOT_MOBILE = "wc_clot_mobile",
// eslint-disable-next-line @typescript-eslint/naming-convention
METAMASK_SNAP_LEAP = "metamask_snap_leap",
// eslint-disable-next-line @typescript-eslint/naming-convention
METAMASK_SNAP_COSMOS = "metamask_snap_cosmos",
Expand All @@ -31,6 +33,7 @@ export const WALLET_TYPES = [
WalletType.WC_KEPLR_MOBILE,
WalletType.WC_LEAP_MOBILE,
WalletType.WC_COSMOSTATION_MOBILE,
WalletType.WC_CLOT_MOBILE,
WalletType.METAMASK_SNAP_LEAP,
WalletType.STATION,
WalletType.XDEFI,
Expand Down

0 comments on commit e44137b

Please sign in to comment.