Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @figmentio/elements

## 2.2.0

### Minor Changes

- Removed Babylon support

## 2.1.2

### Patch Changes
Expand Down
35 changes: 1 addition & 34 deletions demo/src/components/MainContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ export function MainContent({
}: MainContentProps) {
const [wallet, setWallet] = useState<{
address: string;
publicKey: string;
}>({
address: "",
publicKey: "",
});

const customWalletConfigMap = {
Expand Down Expand Up @@ -64,40 +62,11 @@ export function MainContent({
return signature;
},
},
babylon: {
address: wallet.address,
publicKey: wallet?.publicKey,
signMessage: async (message: string) => {
const signature = await window?.tomo_btc?.signMessage(
message,
"bip322-simple",
);
if (!signature) throw new Error("Failed to sign message");
return signature;
},
signTransaction: async (transaction: string) => {
const signedTx = await window?.tomo_btc?.signPsbt(transaction);
if (!signedTx) throw new Error("Failed to sign transaction");
return signedTx;
},
},
};

useEffect(() => {
const fetchWallet = async () => {
if (walletType === "custom" && selectedProtocol.id === "babylon") {
const tomo = window.tomo_btc;

if (!tomo) throw new Error("Failed to get tomo");

const addresses = await tomo.requestAccounts();
const publicKey = await tomo.getPublicKey();

setWallet({
address: addresses[0],
publicKey,
});
} else if (walletType === "custom" && selectedProtocol.id === "solana") {
if (walletType === "custom" && selectedProtocol.id === "solana") {
const phantom = window.phantom?.solana;

if (!phantom) throw new Error("Failed to get phantom");
Expand All @@ -106,12 +75,10 @@ export function MainContent({

setWallet({
address: resp.publicKey.toString(),
publicKey: "",
});
} else {
setWallet({
address: "",
publicKey: "",
});
}
};
Expand Down
14 changes: 0 additions & 14 deletions demo/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ import { FigmentLogo } from "./icons";
const protocols: Protocol[] = [
{ name: "ETH", id: "ethereum" },
{ name: "SOL", id: "solana" },
{
name: "Babylon",
id: "babylon",
disabled: true,
tooltip: "Protocol temporarily disabled",
},
];

const networksByProtocol: Record<Protocol["id"], Network[]> = {
Expand All @@ -23,10 +17,6 @@ const networksByProtocol: Record<Protocol["id"], Network[]> = {
{ name: "Devnet", id: "devnet" },
{ name: "Mainnet", id: "mainnet", disabled: true },
],
babylon: [
{ name: "Signet", id: "signet" },
{ name: "Mainnet", id: "mainnet", disabled: true },
],
};

const walletDescriptions: WalletDescription = {
Expand All @@ -38,10 +28,6 @@ const walletDescriptions: WalletDescription = {
default: "Uses Solana Wallet Adapter",
custom: "With own signing function.",
},
babylon: {
default: "Uses OneKey Wallet",
custom: "With own signing function.",
},
} as const;

const themeOptions = [
Expand Down
6 changes: 1 addition & 5 deletions demo/src/components/ToggleGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { cn } from "../utils";
import { Wallet, Code2, TestTubeIcon, GlobeIcon } from "lucide-react";
import { EthereumIcon, SolanaIcon, BitcoinIcon } from "./icons";
import { EthereumIcon, SolanaIcon } from "./icons";

interface ToggleGroupProps<T extends string> {
value: T | null;
Expand All @@ -23,8 +23,6 @@ const getIcon = (value: string) => {
return <Code2 className="w-4 h-4" />;
case "ethereum":
return <EthereumIcon className="w-5 h-5" />;
case "babylon":
return <BitcoinIcon className="w-5 h-5" />;
case "solana":
return <SolanaIcon className="w-5 h-5" />;
case "mainnet":
Expand All @@ -43,12 +41,10 @@ const shouldShowIcon = (value: string) => {
"default",
"custom",
"ethereum",
"babylon",
"solana",
"mainnet",
"hoodi",
"devnet",
"signet",
].includes(value);
};

Expand Down
2 changes: 1 addition & 1 deletion demo/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export interface Protocol {
name: string;
id: "ethereum" | "solana" | "babylon";
id: "ethereum" | "solana";
disabled?: boolean;
tooltip?: string;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@figmentio/elements",
"version": "2.1.2",
"version": "2.2.0",
"description": "Install and import Figment Elements directly to your project to gain access to Figment's functionality, such as staking.",
"type": "module",
"main": "./dist/index.cjs",
Expand Down
20 changes: 2 additions & 18 deletions src/elements/staking.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import React, { useEffect, useRef, useState } from "react";
import { style } from "./style";
import {
BabylonCustomWalletConfig,
PostMessageType,
StakingProps,
} from "./types";
import { PostMessageType, StakingProps } from "./types";

const Staking: React.FC<StakingProps> = ({
protocol,
Expand Down Expand Up @@ -90,26 +86,14 @@ const Staking: React.FC<StakingProps> = ({
const iframeWalletConfig = JSON.stringify({
address: wallet.address,
network,
...(protocol === "babylon"
? {
publicKey: (wallet as BabylonCustomWalletConfig).publicKey,
}
: {}),
});

sendMessageToIframe({
type: PostMessageType.FIGMENT_UPDATE_WALLET_CONFIG,
walletConfig: iframeWalletConfig,
});
}
}, [
isIframeReady,
wallet,
wallet?.address,
(wallet as BabylonCustomWalletConfig)?.publicKey,
network,
protocol,
]);
}, [isIframeReady, wallet, wallet?.address, network, protocol]);

const sendMessageToIframe = (message: any) => {
if (iframeRef.current && iframeRef.current.contentWindow) {
Expand Down
29 changes: 0 additions & 29 deletions src/elements/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
enum Protocol {
ethereum = "ethereum",
babylon = "babylon",
solana = "solana",
}

Expand All @@ -9,23 +8,11 @@ enum EthereumNetwork {
hoodi = "hoodi",
}

enum BabylonNetwork {
mainnet = "mainnet",
signet = "signet",
}

enum SolanaNetwork {
mainnet = "mainnet",
devnet = "devnet",
}

export type BabylonCustomWalletConfig = {
address: string;
publicKey: string;
signTransaction: (transaction: string) => Promise<string>;
signMessage: (message: string) => Promise<string>;
};

export type SolanaCustomWalletConfig = {
address: string;
signTransaction: (transaction: string) => Promise<string>;
Expand All @@ -34,12 +21,10 @@ export type SolanaCustomWalletConfig = {

type ProtocolToNetworkMap = {
[Protocol.ethereum]: keyof typeof EthereumNetwork;
[Protocol.babylon]: keyof typeof BabylonNetwork;
[Protocol.solana]: keyof typeof SolanaNetwork;
};

export type ProtocolToWalletConfigMap = {
[Protocol.babylon]: BabylonCustomWalletConfig;
[Protocol.solana]: SolanaCustomWalletConfig;
};

Expand All @@ -55,12 +40,6 @@ type BaseStakingProps = {
// wallet: CustomWalletConfig;
// };

type StakingPropsWithWalletBabylon = BaseStakingProps & {
protocol: "babylon";
network: ProtocolToNetworkMap[Protocol.babylon];
wallet: ProtocolToWalletConfigMap[Protocol.babylon];
};

type StakingPropsWithWalletSolana = BaseStakingProps & {
protocol: "solana";
network: ProtocolToNetworkMap[Protocol.solana];
Expand All @@ -73,12 +52,6 @@ type StakingPropsWithoutWalletEthereum = BaseStakingProps & {
wallet?: undefined;
};

type StakingPropsWithoutWalletBabylon = BaseStakingProps & {
protocol: "babylon";
network: ProtocolToNetworkMap[Protocol.babylon];
wallet?: undefined;
};

type StakingPropsWithoutWalletSolana = BaseStakingProps & {
protocol: "solana";
network: ProtocolToNetworkMap[Protocol.solana];
Expand All @@ -88,10 +61,8 @@ type StakingPropsWithoutWalletSolana = BaseStakingProps & {
export type StakingProps =
// Once we enable custom wallets for Ethereum, we can uncomment this
// | StakingPropsWithWalletEthereum
| StakingPropsWithWalletBabylon
| StakingPropsWithWalletSolana
| StakingPropsWithoutWalletEthereum
| StakingPropsWithoutWalletBabylon
| StakingPropsWithoutWalletSolana;

export enum PostMessageType {
Expand Down
Loading