Skip to content

Commit

Permalink
Merge branch '459-encapsulate-all-wallet-functionalities-within-a-cla…
Browse files Browse the repository at this point in the history
…ss-that-adheres-to-the-new-wallet-interface-next' into 'dev'

refactor: Update all wallet functionalities and the associated logic within the Rosen App

Closes #459

See merge request ergo/rosen-bridge/ui!385
  • Loading branch information
zargarzadehm committed Dec 11, 2024
2 parents e2f0377 + db9031b commit 1bf7129
Show file tree
Hide file tree
Showing 157 changed files with 993 additions and 1,859 deletions.
5 changes: 5 additions & 0 deletions .changeset/cyan-eagles-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rosen-bridge/icons': major
---

Drop the Flint wallet icon
6 changes: 6 additions & 0 deletions .changeset/pink-boats-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@rosen-bridge/rosen-app': minor
---

- Discontinue support for Flint and Vespr wallets
- Revise the wallet-related logic to align with the latest updates in the wallet packages
8 changes: 8 additions & 0 deletions .changeset/sharp-adults-raise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@rosen-network/ethereum': major
'@rosen-network/bitcoin': major
'@rosen-network/cardano': major
'@rosen-network/ergo': major
---

Eliminate the reliance on the @rosen-ui/wallet-api package and remove any unrelated type definitions
10 changes: 10 additions & 0 deletions .changeset/two-lizards-smell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@rosen-ui/metamask-wallet': major
'@rosen-ui/nautilus-wallet': major
'@rosen-ui/okx-wallet': major
'@rosen-ui/eternl-wallet': major
'@rosen-ui/lace-wallet': major
'@rosen-ui/nami-wallet': major
---

Encapsulate wallet functionalities into a single class following a unified interface to simplify maintenance and enable quick addition of new wallet types by implementing the interface.
5 changes: 5 additions & 0 deletions .changeset/unlucky-pens-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rosen-bridge/rosen-app': major
---

Discontinue support for the Flint and Vespr wallets
12 changes: 6 additions & 6 deletions apps/rosen/app/_hooks/useTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ export const useTransaction = () => {
tokenMap.getSignificantDecimals(tokenValue.tokenId) || 0,
),
);
const txId = await selectedWallet?.transfer(
tokenValue as RosenChainToken,
amountValueWrapped,
targetValue,
selectedTarget.toSafeAddress(walletAddressValue),
const txId = await selectedWallet?.transfer({
token: tokenValue as RosenChainToken,
amount: amountValueWrapped,
toChain: targetValue,
address: selectedTarget.toSafeAddress(walletAddressValue),
bridgeFee,
networkFee,
lockAddress,
);
});
openSnackbar(`Transaction submitted with id [${txId}]`, 'success');
} catch (error) {
/**
Expand Down
10 changes: 4 additions & 6 deletions apps/rosen/app/_hooks/useWallet.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useContext, useCallback, useRef } from 'react';

import { useLocalStorageManager } from '@rosen-ui/common-hooks';
import { Wallet, WalletBase } from '@rosen-ui/wallet-api';
import { Wallet } from '@rosen-ui/wallet-api';

import { WalletContext } from '@/_contexts/walletContext';

Expand All @@ -15,7 +15,7 @@ interface WalletDescriptor {
/**
* generates and return the wallet object to save in the local storage
*/
const toWalletDescriptor = (wallet: WalletBase): WalletDescriptor => {
const toWalletDescriptor = (wallet: Wallet): WalletDescriptor => {
let expDate = new Date();
return {
name: wallet.name,
Expand Down Expand Up @@ -80,11 +80,9 @@ export const useWallet = () => {
const setSelectedWallet = useCallback(
async (wallet: Wallet) => {
const prevWallet = getCurrentWallet();
const status = await wallet.connectWallet();
const status = await wallet.connect();

if (typeof status === 'boolean' && status) {
prevWallet?.onDisconnect && prevWallet.onDisconnect();
wallet.onConnect && wallet.onConnect();
set<WalletDescriptor>(selectedSource!.name, toWalletDescriptor(wallet));
walletGlobalContext?.dispatch({ type: 'set', wallet });
}
Expand All @@ -98,7 +96,7 @@ export const useWallet = () => {
selectedWallet?.name !== walletGlobalContext?.state.selectedWallet?.name
) {
if (selectedWallet) {
const status = await selectedWallet.connectWallet();
const status = await selectedWallet.connect();
if (typeof status === 'boolean' && status) {
walletGlobalContext?.dispatch({
type: 'set',
Expand Down
4 changes: 2 additions & 2 deletions apps/rosen/app/_networks/bitcoin/client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BitcoinIcon } from '@rosen-bridge/icons';
import { NETWORK_LABELS, NETWORKS } from '@rosen-ui/constants';
import { okxWalletCreator } from '@rosen-ui/okx-wallet';
import { OKXWallet } from '@rosen-ui/okx-wallet';

import { unwrap } from '@/_safeServerAction';
import { getTokenMap } from '@/_tokenMap/getClientTokenMap';
Expand Down Expand Up @@ -31,7 +31,7 @@ export const BitcoinNetwork: BitcoinNetworkType = {
name: NETWORKS.BITCOIN,
label: NETWORK_LABELS.BITCOIN,
logo: BitcoinIcon,
wallets: [okxWalletCreator(config)],
wallets: [new OKXWallet(config)],
nextHeightInterval: 1,
lockAddress: process.env.NEXT_PUBLIC_BITCOIN_LOCK_ADDRESS!,
getMaxTransfer: unwrap(getMaxTransfer),
Expand Down
14 changes: 6 additions & 8 deletions apps/rosen/app/_networks/cardano/client.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { CardanoIcon } from '@rosen-bridge/icons';
import { NETWORK_LABELS, NETWORKS } from '@rosen-ui/constants';
import { eternlWalletCreator } from '@rosen-ui/eternl-wallet';
import { flintWalletCreator } from '@rosen-ui/flint-wallet';
import { laceWalletCreator } from '@rosen-ui/lace-wallet';
import { namiWalletCreator } from '@rosen-ui/nami-wallet';
import { EtrnlWallet } from '@rosen-ui/eternl-wallet';
import { LaceWallet } from '@rosen-ui/lace-wallet';
import { NamiWallet } from '@rosen-ui/nami-wallet';

import { unwrap } from '@/_safeServerAction';
import { getTokenMap } from '@/_tokenMap/getClientTokenMap';
Expand Down Expand Up @@ -34,10 +33,9 @@ export const CardanoNetwork: CardanoNetworkType = {
name: NETWORKS.CARDANO,
label: NETWORK_LABELS.CARDANO,
wallets: [
eternlWalletCreator(config),
flintWalletCreator(config),
laceWalletCreator(config),
namiWalletCreator(config),
new EtrnlWallet(config),
new LaceWallet(config),
new NamiWallet(config),
],
nextHeightInterval: 25,
logo: CardanoIcon,
Expand Down
4 changes: 2 additions & 2 deletions apps/rosen/app/_networks/ergo/client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ErgoIcon } from '@rosen-bridge/icons';
import { NETWORK_LABELS, NETWORKS } from '@rosen-ui/constants';
import { nautilusWalletCreator } from '@rosen-ui/nautilus-wallet';
import { NautilusWallet } from '@rosen-ui/nautilus-wallet';

import { unwrap } from '@/_safeServerAction';
import { getTokenMap } from '@/_tokenMap/getClientTokenMap';
Expand All @@ -22,7 +22,7 @@ const config = {
export const ErgoNetwork: ErgoNetworkType = {
name: NETWORKS.ERGO,
label: NETWORK_LABELS.ERGO,
wallets: [nautilusWalletCreator(config)],
wallets: [new NautilusWallet(config)],
logo: ErgoIcon,
nextHeightInterval: 5,
lockAddress: process.env.NEXT_PUBLIC_ERGO_LOCK_ADDRESS!,
Expand Down
4 changes: 2 additions & 2 deletions apps/rosen/app/_networks/ethereum/client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EthereumIcon } from '@rosen-bridge/icons';
import { NETWORK_LABELS, NETWORKS } from '@rosen-ui/constants';
import { metaMaskWalletCreator } from '@rosen-ui/metamask-wallet';
import { MetaMaskWallet } from '@rosen-ui/metamask-wallet';

import { unwrap } from '@/_safeServerAction';
import { getTokenMap } from '@/_tokenMap/getClientTokenMap';
Expand All @@ -18,7 +18,7 @@ export const EthereumNetwork: EthereumNetworkType = {
name: NETWORKS.ETHEREUM,
label: NETWORK_LABELS.ETHEREUM,
wallets: [
metaMaskWalletCreator({
new MetaMaskWallet({
getTokenMap,
generateLockData: unwrap(generateLockData),
generateTxParameters: unwrap(generateTxParameters),
Expand Down
2 changes: 0 additions & 2 deletions apps/rosen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"@rosen-ui/common-hooks": "^0.1.1",
"@rosen-ui/constants": "^0.0.5",
"@rosen-ui/eternl-wallet": "^1.0.3",
"@rosen-ui/flint-wallet": "^1.0.3",
"@rosen-ui/lace-wallet": "^1.0.3",
"@rosen-ui/metamask-wallet": "^0.1.4",
"@rosen-ui/nami-wallet": "^1.0.3",
Expand All @@ -48,7 +47,6 @@
"@rosen-ui/swr-helpers": "^0.2.0",
"@rosen-ui/types": "^0.3.1",
"@rosen-ui/utils": "^0.4.2",
"@rosen-ui/vespr-wallet": "^0.0.11",
"@rosen-ui/wallet-api": "^1.0.3",
"@upstash/ratelimit": "^1.2.1",
"@vercel/kv": "^2.0.0",
Expand Down
14 changes: 6 additions & 8 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ npm run build --workspace networks/bitcoin
npm run build --workspace networks/cardano
npm run build --workspace networks/ergo
npm run build --workspace networks/ethereum
npm run build --workspace wallets/nami-wallet
npm run build --workspace wallets/lace-wallet
npm run build --workspace wallets/metamask-wallet
npm run build --workspace wallets/eternl-wallet
npm run build --workspace wallets/flint-wallet
npm run build --workspace wallets/vespr-wallet
npm run build --workspace wallets/nautilus-wallet
npm run build --workspace wallets/okx-wallet
npm run build --workspace wallets/eternl
npm run build --workspace wallets/lace
npm run build --workspace wallets/metamask
npm run build --workspace wallets/nami
npm run build --workspace wallets/nautilus
npm run build --workspace wallets/okx
1 change: 0 additions & 1 deletion networks/bitcoin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"@rosen-bridge/address-codec": "^0.3.0",
"@rosen-bridge/bitcoin-utxo-selection": "^0.2.0",
"@rosen-ui/constants": "^0.0.5",
"@rosen-ui/wallet-api": "^1.0.3",
"axios": "^1.7.2",
"bitcoinjs-lib": "^6.1.6"
},
Expand Down
20 changes: 0 additions & 20 deletions networks/bitcoin/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
import { TokenMap } from '@rosen-bridge/tokens';
import { Wallet } from '@rosen-ui/wallet-api';

import { generateUnsignedTx } from './generateUnsignedTx';
import type {
generateOpReturnData,
getAddressBalance,
submitTransaction,
} from './utils';

export interface Status {
confirmed: boolean;
block_height?: number;
Expand Down Expand Up @@ -69,13 +59,3 @@ export interface UnsignedPsbtData {
};
inputSize: number;
}

export type WalletCreator = (config: WalletCreatorConfig) => Wallet;

export type WalletCreatorConfig = {
getTokenMap(): Promise<TokenMap>;
generateOpReturnData: typeof generateOpReturnData;
generateUnsignedTx: ReturnType<typeof generateUnsignedTx>;
submitTransaction: typeof submitTransaction;
getAddressBalance: typeof getAddressBalance;
};
3 changes: 1 addition & 2 deletions networks/cardano/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
"dependencies": {
"@emurgo/cardano-serialization-lib-nodejs": "^11.5.0",
"@rosen-bridge/cardano-utxo-selection": "^1.1.0",
"@rosen-clients/cardano-koios": "^2.0.3",
"@rosen-ui/wallet-api": "^1.0.3"
"@rosen-clients/cardano-koios": "^2.0.3"
},
"devDependencies": {
"typescript": "^5.0.0"
Expand Down
35 changes: 0 additions & 35 deletions networks/cardano/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
import { TokenMap } from '@rosen-bridge/tokens';
import { CipWalletApi, Wallet } from '@rosen-ui/wallet-api';

import { generateUnsignedTx } from './generateUnsignedTx';
import {
decodeWasmValue,
generateLockAuxiliaryData,
setTxWitnessSet,
} from './utils';

export interface CardanoProtocolParams {
min_fee_a: number;
min_fee_b: number;
Expand All @@ -19,28 +9,3 @@ export interface CardanoProtocolParams {
}

export const ADA_POLICY_ID = '';

export type WalletCreator = (config: WalletCreatorConfig) => Wallet;

export type WalletCreatorConfig = {
getTokenMap(): Promise<TokenMap>;
decodeWasmValue: typeof decodeWasmValue;
generateLockAuxiliaryData: typeof generateLockAuxiliaryData;
generateUnsignedTx: ReturnType<typeof generateUnsignedTx>;
setTxWitnessSet: typeof setTxWitnessSet;
};

export interface ConnectorAPI {
enable(): Promise<CipWalletApi>;
isEnabled(): Promise<boolean>;
experimental?: unknown;
}

/**
* global type augmentation for wallets
*/
declare global {
interface Window {
cardano: { [key: string]: ConnectorAPI };
}
}
1 change: 0 additions & 1 deletion networks/ergo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
},
"dependencies": {
"@rosen-clients/ergo-explorer": "^1.1.1",
"@rosen-ui/wallet-api": "^1.0.3",
"ergo-lib-wasm-nodejs": "^0.24.1"
},
"devDependencies": {
Expand Down
19 changes: 1 addition & 18 deletions networks/ergo/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { TokenMap } from '@rosen-bridge/tokens';
import { EipWalletApi, ErgoBoxProxy, Wallet } from '@rosen-ui/wallet-api';

import { generateUnsignedTx } from './generateUnsignedTx';
import { ErgoBoxProxy } from '@rosen-ui/wallet-api';

export interface TokenInfo {
id: string;
Expand All @@ -22,17 +19,3 @@ export interface CoveringBoxes {
covered: boolean;
boxes: Array<ErgoBoxProxy>;
}

export type WalletCreator = (config: WalletCreatorConfig) => Wallet;

export type WalletCreatorConfig = {
getTokenMap(): Promise<TokenMap>;
generateUnsignedTx: ReturnType<typeof generateUnsignedTx>;
};

/**
* global type augmentation for nautilus wallet
*/
declare global {
let ergo: EipWalletApi;
}
1 change: 0 additions & 1 deletion networks/ethereum/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"dependencies": {
"@rosen-bridge/address-codec": "^0.3.0",
"@rosen-bridge/tokens": "^1.2.1",
"@rosen-ui/wallet-api": "^1.0.3",
"ethers": "^6.13.2"
},
"devDependencies": {
Expand Down
1 change: 0 additions & 1 deletion networks/ethereum/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './constants';
export * from './generateTxParameters';
export * from './types';
export * from './utils';
13 changes: 0 additions & 13 deletions networks/ethereum/src/types.ts

This file was deleted.

Loading

0 comments on commit 1bf7129

Please sign in to comment.