Skip to content

Commit

Permalink
feat: Integrate Wagmi (#3280)
Browse files Browse the repository at this point in the history
* feat: add wagmi and start refactoring wallet select

* feat: display eth wallets in wallet select and create basic multi wallet network selection arch

* feat: add wallet select modal new layout type

* feat: display evm wallets in a simpler list

* feat: handle evm wallet connection

* fix: build

* improvement: mark old evm observable wallets as deprecated

* fix: build
  • Loading branch information
JoseRFelix committed May 30, 2024
1 parent f09deb3 commit a6e02a8
Show file tree
Hide file tree
Showing 48 changed files with 2,728 additions and 1,349 deletions.
6 changes: 3 additions & 3 deletions packages/stores/src/account/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ import { TxTracer } from "../tx";
import { aminoConverters } from "./amino-converters";
import {
AccountStoreWallet,
CosmosRegistryWallet,
DeliverTxResponse,
OneClickTradingInfo,
RegistryWallet,
SignOptions,
TxEvent,
TxEvents,
Expand Down Expand Up @@ -374,7 +374,7 @@ export class AccountStore<Injects extends Record<string, any>[] = []> {
walletWithAccountSet[key] = injectedAccountsForChain[key];
}

const walletInfo = wallet.walletInfo as RegistryWallet;
const walletInfo = wallet.walletInfo as CosmosRegistryWallet;

walletWithAccountSet.txTypeInProgress = txInProgress ?? "";
walletWithAccountSet.isReadyToSendTx =
Expand Down Expand Up @@ -483,7 +483,7 @@ export class AccountStore<Injects extends Record<string, any>[] = []> {
// If the wallet isn't found, return the error
if (!wallet) return new Error(errorMessage);

const walletInfo = wallet.walletInfo as RegistryWallet;
const walletInfo = wallet.walletInfo as CosmosRegistryWallet;

// If the wallet has a custom error matcher, use it
if (walletInfo?.matchError) {
Expand Down
6 changes: 3 additions & 3 deletions packages/stores/src/account/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export interface DeliverTxResponse {
readonly gasWanted: string;
}

export type RegistryWallet = Omit<Wallet, "logo"> & {
export type CosmosRegistryWallet = Omit<Wallet, "logo"> & {
logo: string;
lazyInstall: () => any;
stakeUrl?: string;
Expand Down Expand Up @@ -84,8 +84,8 @@ export type AccountStoreWallet<Injects extends Record<string, any>[] = []> =
UnionToIntersection<Injects[number]> & {
txTypeInProgress: string;
isReadyToSendTx: boolean;
supportsChain: Required<RegistryWallet>["supportsChain"];
walletInfo: RegistryWallet;
supportsChain: Required<CosmosRegistryWallet>["supportsChain"];
walletInfo: CosmosRegistryWallet;
};

export interface TxEvents {
Expand Down
13 changes: 11 additions & 2 deletions packages/stores/src/tests/test-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,22 @@ export class MockKeplrClient implements WalletClient {
signer: string,
signDoc: DirectSignDoc,
signOptions?: SignOptions
): ReturnType<MockKeplrWithFee["signDirect"]> {
return await this.client.signDirect(
): ReturnType<Required<WalletClient>["signDirect"]> {
const response = await this.client.signDirect(
chainId,
signer,
signDoc as any,
signOptions
);

// Convert Long to bigint
return {
signed: {
...response.signed,
accountNumber: BigInt(response.signed.accountNumber.toString()),
},
signature: response.signature,
};
}

async sendTx(chainId: string, tx: Uint8Array, mode: BroadcastMode) {
Expand Down
2 changes: 1 addition & 1 deletion packages/web/__tests__/test-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { ReactNode } from "react";
import { TestWallet, testWalletInfo } from "~/__tests__/test-wallet";
import { MultiLanguageProvider } from "~/hooks/language/context";
import { AvailableFlags } from "~/hooks/use-feature-flags";
import { WalletSelectProvider } from "~/hooks/wallet-select";
import { WalletSelectProvider } from "~/hooks/use-wallet-select";
import { AppRouter } from "~/server/api/root-router";
import { storeContext, StoreProvider } from "~/stores";
import { RootStore } from "~/stores/root";
Expand Down
44 changes: 37 additions & 7 deletions packages/web/components/bridge/immersive/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import { PropsWithChildren, useState } from "react";

import { StepProgress } from "~/components/stepper/progress-bar";
import { Button } from "~/components/ui/button";
import { useWalletSelect } from "~/hooks";
import {
useDisconnectEvmWallet,
useEvmWalletAccount,
} from "~/hooks/evm-wallet";
import { FiatRampKey } from "~/integrations";

import { BridgeFlowProvider } from "../flow";
Expand All @@ -12,34 +17,37 @@ export const ImmersiveBridgeFlow = ({
children,
}: PropsWithChildren<BridgeFlowProvider>) => {
// TODO: state will be encapsulated in a state hook
const [isShowing, setIsShowing] = useState(false);
const [isVisible, setIsVisible] = useState(false);
const [step, setStep] = useState<0 | 1 | 2 | 3 | 4>(0);
const { isConnected, address } = useEvmWalletAccount();
const { onOpenWalletSelect } = useWalletSelect();
const { disconnect } = useDisconnectEvmWallet();

return (
<Provider
value={{
// globally received events
startBridge: (direction: "deposit" | "withdraw") => {
setIsShowing(true);
setIsVisible(true);
console.log("startBridge", direction);
},
bridgeAsset: (anyDenom: string, direction: "deposit" | "withdraw") => {
setIsShowing(true);
setIsVisible(true);
console.log("bridgeAsset", anyDenom, direction);
},
fiatRamp: (fiatRampKey: FiatRampKey, assetKey: string) => {
setIsShowing(true);
setIsVisible(true);
console.log("fiatRamp", fiatRampKey, assetKey);
},
fiatRampSelection: () => {
setIsShowing(true);
setIsVisible(true);
console.log("fiatRampSelection");
},
}}
>
{children}
<Transition
show={isShowing}
show={isVisible}
className="fixed inset-0 z-[999] flex items-center justify-center bg-osmoverse-900"
enter="transition-opacity duration-300"
enterFrom="opacity-0"
Expand Down Expand Up @@ -78,7 +86,29 @@ export const ImmersiveBridgeFlow = ({
</Button>
</div>
<h6>I will fade in and out</h6>
<Button onClick={() => setIsShowing(false)}>Close</Button>
<Button onClick={() => setIsVisible(false)}>Close</Button>

{isConnected ? (
<div>
<p>Evm Address: {address}</p>
<Button onClick={() => disconnect()}>Disconnect</Button>
</div>
) : (
<Button
onClick={() =>
onOpenWalletSelect({
walletOptions: [
{
walletType: "evm",
},
],
layout: "list",
})
}
>
Connect EVM Wallet
</Button>
)}
</div>
</Transition>
</Provider>
Expand Down
6 changes: 4 additions & 2 deletions packages/web/components/cards/stake-learn-more.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from "~/components/stepper";
import { Button } from "~/components/ui/button";
import { useTranslation } from "~/hooks";
import { useWalletSelect } from "~/hooks/wallet-select";
import { useWalletSelect } from "~/hooks/use-wallet-select";
import { useStore } from "~/stores";

const BuildStakeSquadButton: React.FC<StakeLearnMoreProps> = ({
Expand All @@ -26,7 +26,9 @@ const BuildStakeSquadButton: React.FC<StakeLearnMoreProps> = ({
if (isWalletConnected) {
setShowValidatorModal();
} else {
onOpenWalletSelect(osmosisChainId);
onOpenWalletSelect({
walletOptions: [{ walletType: "cosmos", chainId: osmosisChainId }],
});
}
}, [
isWalletConnected,
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/complex/add-conc-liquidity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { CustomClasses } from "~/components/types";
import { Button } from "~/components/ui/button";
import { ChartButton } from "~/components/ui/button";
import { Checkbox } from "~/components/ui/checkbox";
import { EventName } from "~/config";
import { EventName } from "~/config/analytics-events";
import {
ObservableAddConcentratedLiquidityConfig,
useAmplitudeAnalytics,
Expand Down
6 changes: 5 additions & 1 deletion packages/web/components/complex/portfolio-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,11 @@ const GetStartedWithOsmosis: FunctionComponent = () => {
<Button
className="flex !h-11 w-fit items-center gap-2 !rounded-full !py-1"
onClick={() => {
onOpenWalletSelect(chainStore.osmosis.chainId);
onOpenWalletSelect({
walletOptions: [
{ walletType: "cosmos", chainId: chainStore.osmosis.chainId },
],
});
}}
>
{t("connectWallet")}
Expand Down
6 changes: 4 additions & 2 deletions packages/web/components/navbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { useAmplitudeAnalytics, useDisclosure } from "~/hooks";
import { useOneClickTradingSession } from "~/hooks/one-click-trading/use-one-click-trading-session";
import { useICNSName } from "~/hooks/queries/osmosis/use-icns-name";
import { useFeatureFlags } from "~/hooks/use-feature-flags";
import { useWalletSelect } from "~/hooks/wallet-select";
import { useWalletSelect } from "~/hooks/use-wallet-select";
import {
NotifiContextProvider,
NotifiModal,
Expand Down Expand Up @@ -394,7 +394,9 @@ const WalletInfo: FunctionComponent<
size="md"
onClick={() => {
logEvent([EventName.Topnav.connectWalletClicked]);
onOpenWalletSelect(chainId);
onOpenWalletSelect({
walletOptions: [{ walletType: "cosmos", chainId: chainId }],
});
}}
>
<span className="button mx-auto">{t("connectWallet")}</span>
Expand Down
4 changes: 3 additions & 1 deletion packages/web/components/swap-tool/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ export const SwapTool: FunctionComponent<SwapToolProps> = observer(
const sendSwapTx = () => {
// prompt to select wallet insteaad of swapping
if (account?.walletStatus !== WalletStatus.Connected) {
return onOpenWalletSelect(chainId);
return onOpenWalletSelect({
walletOptions: [{ walletType: "cosmos", chainId: chainId }],
});
}

if (!swapState.inAmountInput.amount) return;
Expand Down
13 changes: 11 additions & 2 deletions packages/web/components/transactions/no-transactions-splash.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { FunctionComponent } from "react";

import { Button } from "~/components/ui/button";
import { useTranslation } from "~/hooks";
import { useWalletSelect } from "~/hooks/wallet-select";
import { useWalletSelect } from "~/hooks/use-wallet-select";
import { useStore } from "~/stores";

export const NoTransactionsSplash: FunctionComponent<{
Expand Down Expand Up @@ -43,7 +43,16 @@ export const NoTransactionsSplash: FunctionComponent<{
</div>
{variant === "connect" && (
<div className="max-w-56">
<Button onClick={() => onOpenWalletSelect(osmosisChainId)} size="md">
<Button
onClick={() =>
onOpenWalletSelect({
walletOptions: [
{ walletType: "cosmos", chainId: osmosisChainId },
],
})
}
size="md"
>
{t("transactions.connectWallet")}
</Button>
</div>
Expand Down
35 changes: 35 additions & 0 deletions packages/web/components/wallet-states/connecting-wallet-state.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { isNil } from "@osmosis-labs/utils";
import React from "react";

interface ConnectingWalletStateProps {
walletLogo?: string;
title?: string;
desc?: string;
}

const ConnectingWalletState = ({
walletLogo,
title,
desc,
}: ConnectingWalletStateProps) => {
return (
<div className="mx-auto flex h-full max-w-sm flex-col items-center justify-center gap-12 pt-3">
<div className="flex h-16 w-16 items-center justify-center after:absolute after:h-32 after:w-32 after:animate-spin-slow after:rounded-full after:border-2 after:border-b-transparent after:border-l-wosmongton-300 after:border-r-wosmongton-300 after:border-t-transparent">
{!!walletLogo && typeof walletLogo === "string" && (
<img width={64} height={64} src={walletLogo} alt="Wallet logo" />
)}
</div>

<div className="flex flex-col gap-2">
{!isNil(title) && (
<h1 className="text-center text-h6 font-h6">{title}</h1>
)}
{!isNil(desc) && (
<p className="body2 text-center text-wosmongton-100">{desc}</p>
)}
</div>
</div>
);
};

export default ConnectingWalletState;
41 changes: 41 additions & 0 deletions packages/web/components/wallet-states/error-wallet-state.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { isNil } from "@osmosis-labs/utils";
import React, { ReactNode } from "react";

interface ErrorWalletStateProps {
walletLogo?: string;
title?: string;
desc?: string;
actions?: ReactNode;
}

const ErrorWalletState = ({
walletLogo,
title,
desc,
actions,
}: ErrorWalletStateProps) => {
return (
<div className="mx-auto flex h-full max-w-sm flex-col items-center justify-center gap-12 pt-6">
<div className="flex h-16 w-16 items-center justify-center after:absolute after:h-32 after:w-32 after:rounded-full after:border-2 after:border-error">
{!!walletLogo && typeof walletLogo === "string" && (
<img width={64} height={64} src={walletLogo} alt="Wallet logo" />
)}
</div>

<div className="flex flex-col gap-6">
<div className="flex flex-col gap-2">
{!isNil(title) && (
<h1 className="text-center text-h6 font-h6">{title}</h1>
)}
{!isNil(desc) && (
<p className="body2 text-center text-wosmongton-100">{desc}</p>
)}
</div>

{actions}
</div>
</div>
);
};

export default ErrorWalletState;
2 changes: 2 additions & 0 deletions packages/web/components/wallet-states/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./connecting-wallet-state";
export * from "./error-wallet-state";
8 changes: 6 additions & 2 deletions packages/web/components/your-balance/your-balance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ const BalanceStats = observer(({ denom }: YourBalanceProps) => {
const { ibcBalances } = assetsStore;
const account = accountStore.getWallet(chainStore.osmosis.chainId);
const tokenChain = chainStore.getChainFromCurrency(denom);
const chainName = tokenChain?.chainName;
const chainId = tokenChain?.chainId;

const { data, isLoading: isCoinDataLoading } =
api.edge.assets.getUserMarketAsset.useQuery({
Expand Down Expand Up @@ -464,7 +464,11 @@ const BalanceStats = observer(({ denom }: YourBalanceProps) => {
</SkeletonLoader>
) : (
<button
onClick={() => onOpenWalletSelect(chainName!)}
onClick={() =>
onOpenWalletSelect({
walletOptions: [{ walletType: "cosmos", chainId: chainId! }],
})
}
className="text-subtitle1 font-subtitle1 leading-6 text-wosmongton-300 transition-colors duration-200 ease-in-out hover:text-wosmongton-200"
>
{t("connectWallet")}
Expand Down
4 changes: 2 additions & 2 deletions packages/web/config/generate-cosmos-kit-wallet-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ async function generateCosmosKitWalletList() {

const content = `
import {Wallet} from "@cosmos-kit/core"
export enum AvailableWallets {${CosmosKitWalletList.map(
export enum AvailableCosmosWallets {${CosmosKitWalletList.map(
(wallet) => `${wallet.prettyName.replace(/\s/g, "")} = "${wallet.name}"`
).join(",")}}
export const CosmosKitWalletList: Record<AvailableWallets, Wallet> = ${getStringifiedWallet(
export const CosmosKitWalletList: Record<AvailableCosmosWallets, Wallet> = ${getStringifiedWallet(
registryObject
)}
`;
Expand Down
2 changes: 1 addition & 1 deletion packages/web/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* This file is autogenerated by `generate-wallet-registry.ts`.
*/
export { AvailableWallets } from "./generated/cosmos-kit-wallet-list";
export { AvailableCosmosWallets as AvailableWallets } from "./generated/cosmos-kit-wallet-list";
/**
* This file is autogenerated by `generate-sprite-ids.ts`.
*/
Expand Down
Loading

0 comments on commit a6e02a8

Please sign in to comment.