Skip to content

Commit

Permalink
Merge branch '429-enhance-the-rosen-app-s-source-code-by-reorganizing…
Browse files Browse the repository at this point in the history
…-relocating-and-renaming-certain-files-and' into 'dev'

Resolve "Enhance the Rosen app's source code by reorganizing, relocating, and renaming certain files and methods"

Closes #429

See merge request ergo/rosen-bridge/ui!356
  • Loading branch information
vorujack committed Nov 18, 2024
2 parents da29ec3 + 86281c1 commit 1890323
Show file tree
Hide file tree
Showing 27 changed files with 193 additions and 208 deletions.
5 changes: 5 additions & 0 deletions .changeset/strange-lobsters-greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rosen-bridge/rosen-app': patch
---

Enhance the Rosen app's source code by reorganizing, relocating, and renaming certain files and methods
4 changes: 1 addition & 3 deletions apps/rosen/app/_backend/assets/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import {
} from '@rosen-ui/asset-calculator';
import { Network } from '@rosen-ui/types';

import { NotFoundError } from '@/_errors/NotFoundError';

import { dataSource } from '../dataSource';
import '../initialize-datasource-if-needed';

Expand Down Expand Up @@ -41,7 +39,7 @@ export const getAsset = async (id: string) => {
});

if (!token) {
throw new NotFoundError(`Token with id [${id}] not found`);
throw new ReferenceError(`Token with id [${id}] not found`);
}

const bridged: Pick<
Expand Down
6 changes: 2 additions & 4 deletions apps/rosen/app/_backend/assets/services.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { TokenMap } from '@rosen-bridge/tokens';

import { getRosenTokens } from '@/_backend/utils';
import { getTokenMap } from '@/_tokenMap/getServerTokenMap';

import {
AssetFilters,
getAsset as repositoryGetAsset,
getAllAssets as repositoryGetAllAssets,
} from './repository';

const tokenMap = new TokenMap(getRosenTokens());
const tokenMap = getTokenMap();

/**
* return asset details
Expand Down
5 changes: 2 additions & 3 deletions apps/rosen/app/_backend/events/services.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { TokenMap } from '@rosen-bridge/tokens';
import { Network } from '@rosen-ui/types';

import { getRosenTokens } from '@/_backend/utils';
import { getTokenMap } from '@/_tokenMap/getServerTokenMap';

import { UNSUPPORTED_TOKEN_NAME } from '../constants';
import { getEvents } from './repository';

const tokenMap = new TokenMap(getRosenTokens());
const tokenMap = getTokenMap();

/**
* get full token data associated with a tokenId and a chain
Expand Down
1 change: 0 additions & 1 deletion apps/rosen/app/_errors/NotFoundError.ts

This file was deleted.

2 changes: 1 addition & 1 deletion apps/rosen/app/_hooks/useTokenMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useEffect, useState, useTransition } from 'react';

import { TokenMap } from '@rosen-bridge/tokens';

import { getTokenMap } from '@/_networks/getTokenMap.client';
import { getTokenMap } from '@/_tokenMap/getClientTokenMap';

/**
* return TokenMap instance
Expand Down
39 changes: 39 additions & 0 deletions apps/rosen/app/_networks/bitcoin/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { BitcoinIcon } from '@rosen-bridge/icons';
import { NETWORK_LABELS, NETWORKS } from '@rosen-ui/constants';
import { xdefiWalletCreator } from '@rosen-ui/xdefi-wallet';

import { unwrap } from '@/_safeServerAction';
import { getTokenMap } from '@/_tokenMap/getClientTokenMap';
import { BitcoinNetwork as BitcoinNetworkType } from '@/_types';

import { getMaxTransfer } from './getMaxTransfer';
import {
generateOpReturnData,
generateUnsignedTx,
submitTransaction,
getAddressBalance,
} from './server';

const config = {
getTokenMap,
generateOpReturnData: unwrap(generateOpReturnData),
generateUnsignedTx: unwrap(generateUnsignedTx),
getAddressBalance: unwrap(getAddressBalance),
submitTransaction: unwrap(submitTransaction),
};

/**
* the main object for Bitcoin network
* providing access to network info and wallets and network specific
* functionality
*/
export const BitcoinNetwork: BitcoinNetworkType = {
name: NETWORKS.BITCOIN,
label: NETWORK_LABELS.BITCOIN,
logo: BitcoinIcon,
wallets: [xdefiWalletCreator(config)],
nextHeightInterval: 1,
lockAddress: process.env.NEXT_PUBLIC_BITCOIN_LOCK_ADDRESS!,
getMaxTransfer: unwrap(getMaxTransfer),
toSafeAddress: (address) => address,
};
5 changes: 2 additions & 3 deletions apps/rosen/app/_networks/bitcoin/getMaxTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import {
import { NATIVE_TOKENS, NETWORKS } from '@rosen-ui/constants';

import { wrap } from '@/_safeServerAction';
import { getTokenMap } from '@/_tokenMap/getServerTokenMap';
import { BitcoinNetwork } from '@/_types';

import { getTokenMap } from '../getTokenMap.server';

/**
* get max transfer for bitcoin
*/
Expand Down Expand Up @@ -47,7 +46,7 @@ const getMaxTransferCore: BitcoinNetwork['getMaxTransfer'] = async ({
const estimatedFee = Math.ceil((estimatedTxWeight / 4) * feeRatio);
const minSatoshi = await getMinimumMeaningfulSatoshi(feeRatio);

const tokenMap = await getTokenMap();
const tokenMap = getTokenMap();

const offset = tokenMap.wrapAmount(
NATIVE_TOKENS.BITCOIN,
Expand Down
40 changes: 1 addition & 39 deletions apps/rosen/app/_networks/bitcoin/index.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1 @@
import { BitcoinIcon } from '@rosen-bridge/icons';
import { NETWORK_LABELS, NETWORKS } from '@rosen-ui/constants';
import { xdefiWalletCreator } from '@rosen-ui/xdefi-wallet';

import { unwrap } from '@/_safeServerAction';
import { BitcoinNetwork as BitcoinNetworkType } from '@/_types';

import { getTokenMap } from '../getTokenMap.client';
import { getMaxTransfer } from './getMaxTransfer';
import {
generateOpReturnData,
generateUnsignedTx,
submitTransaction,
getAddressBalance,
} from './server';

const config = {
getTokenMap,
generateOpReturnData: unwrap(generateOpReturnData),
generateUnsignedTx: unwrap(generateUnsignedTx),
getAddressBalance: unwrap(getAddressBalance),
submitTransaction: unwrap(submitTransaction),
};

/**
* the main object for Bitcoin network
* providing access to network info and wallets and network specific
* functionality
*/
export const BitcoinNetwork: BitcoinNetworkType = {
name: NETWORKS.BITCOIN,
label: NETWORK_LABELS.BITCOIN,
logo: BitcoinIcon,
wallets: [xdefiWalletCreator(config)],
nextHeightInterval: 1,
lockAddress: process.env.NEXT_PUBLIC_BITCOIN_LOCK_ADDRESS!,
getMaxTransfer: unwrap(getMaxTransfer),
toSafeAddress: (address) => address,
};
export * from './client';
12 changes: 4 additions & 8 deletions apps/rosen/app/_networks/bitcoin/server.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
'use server';

import { TokenMap } from '@rosen-bridge/tokens';
import {
generateOpReturnData as generateOpReturnDataCore,
generateUnsignedTx as generateUnsignedTxCore,
getAddressBalance as getAddressBalanceCore,
submitTransaction as submitTransactionCore,
} from '@rosen-network/bitcoin';

import { getRosenTokens } from '@/_backend/utils';
import { wrap } from '@/_safeServerAction';
import { getTokenMap } from '@/_tokenMap/getServerTokenMap';

export const generateOpReturnData = wrap(generateOpReturnDataCore, {
traceKey: 'generateOpReturnData',
});

export const generateUnsignedTx = wrap(
generateUnsignedTxCore(new TokenMap(getRosenTokens())),
{
traceKey: 'generateUnsignedTx',
},
);
export const generateUnsignedTx = wrap(generateUnsignedTxCore(getTokenMap()), {
traceKey: 'generateUnsignedTx',
});

export const getAddressBalance = wrap(getAddressBalanceCore, {
cache: 3000,
Expand Down
47 changes: 47 additions & 0 deletions apps/rosen/app/_networks/cardano/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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 { unwrap } from '@/_safeServerAction';
import { getTokenMap } from '@/_tokenMap/getClientTokenMap';
import { CardanoNetwork as CardanoNetworkType } from '@/_types';

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

const config = {
getTokenMap,
decodeWasmValue: unwrap(decodeWasmValue),
generateLockAuxiliaryData: unwrap(generateLockAuxiliaryData),
generateUnsignedTx: unwrap(generateUnsignedTx),
setTxWitnessSet: unwrap(setTxWitnessSet),
};

/**
* the main object for Cardano network
* providing access to network info and wallets and network specific
* functionality
*/
export const CardanoNetwork: CardanoNetworkType = {
name: NETWORKS.CARDANO,
label: NETWORK_LABELS.CARDANO,
wallets: [
eternlWalletCreator(config),
flintWalletCreator(config),
laceWalletCreator(config),
namiWalletCreator(config),
],
nextHeightInterval: 25,
logo: CardanoIcon,
lockAddress: process.env.NEXT_PUBLIC_CARDANO_LOCK_ADDRESS!,
getMaxTransfer: unwrap(getMaxTransfer),
toSafeAddress: (address) => address,
};
5 changes: 2 additions & 3 deletions apps/rosen/app/_networks/cardano/getMaxTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@ import { feeAndMinBoxValue } from '@rosen-network/cardano/dist/src/constants';
import { NATIVE_TOKENS, NETWORKS } from '@rosen-ui/constants';

import { wrap } from '@/_safeServerAction';
import { getTokenMap } from '@/_tokenMap/getServerTokenMap';
import { CardanoNetwork } from '@/_types';

import { getTokenMap } from '../getTokenMap.server';

/**
* get max transfer for cardano
*/
const getMaxTransferCore: CardanoNetwork['getMaxTransfer'] = async ({
balance,
isNative,
}) => {
const tokenMap = await getTokenMap();
const tokenMap = getTokenMap();
const feeAndMinBoxValueWrapped = tokenMap.wrapAmount(
NATIVE_TOKENS.CARDANO,
feeAndMinBoxValue,
Expand Down
48 changes: 1 addition & 47 deletions apps/rosen/app/_networks/cardano/index.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1 @@
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 { unwrap } from '@/_safeServerAction';
import { CardanoNetwork as CardanoNetworkType } from '@/_types';

import { getTokenMap } from '../getTokenMap.client';
import { getMaxTransfer } from './getMaxTransfer';
import {
decodeWasmValue,
generateLockAuxiliaryData,
generateUnsignedTx,
setTxWitnessSet,
} from './server';

const config = {
getTokenMap,
decodeWasmValue: unwrap(decodeWasmValue),
generateLockAuxiliaryData: unwrap(generateLockAuxiliaryData),
generateUnsignedTx: unwrap(generateUnsignedTx),
setTxWitnessSet: unwrap(setTxWitnessSet),
};

/**
* the main object for Cardano network
* providing access to network info and wallets and network specific
* functionality
*/
export const CardanoNetwork: CardanoNetworkType = {
name: NETWORKS.CARDANO,
label: NETWORK_LABELS.CARDANO,
wallets: [
eternlWalletCreator(config),
flintWalletCreator(config),
laceWalletCreator(config),
namiWalletCreator(config),
],
nextHeightInterval: 25,
logo: CardanoIcon,
lockAddress: process.env.NEXT_PUBLIC_CARDANO_LOCK_ADDRESS!,
getMaxTransfer: unwrap(getMaxTransfer),
toSafeAddress: (address) => address,
};
export * from './client';
12 changes: 4 additions & 8 deletions apps/rosen/app/_networks/cardano/server.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
'use server';

import { TokenMap } from '@rosen-bridge/tokens';
import {
decodeWasmValue as decodeWasmValueCore,
generateLockAuxiliaryData as generateLockAuxiliaryDataCore,
generateUnsignedTx as generateUnsignedTxCore,
setTxWitnessSet as setTxWitnessSetCore,
} from '@rosen-network/cardano';

import { getRosenTokens } from '@/_backend/utils';
import { wrap } from '@/_safeServerAction';
import { getTokenMap } from '@/_tokenMap/getServerTokenMap';

export const decodeWasmValue = wrap(decodeWasmValueCore, {
cache: Infinity,
Expand All @@ -20,12 +19,9 @@ export const generateLockAuxiliaryData = wrap(generateLockAuxiliaryDataCore, {
traceKey: 'generateLockAuxiliaryData',
});

export const generateUnsignedTx = wrap(
generateUnsignedTxCore(new TokenMap(getRosenTokens())),
{
traceKey: 'generateUnsignedTx',
},
);
export const generateUnsignedTx = wrap(generateUnsignedTxCore(getTokenMap()), {
traceKey: 'generateUnsignedTx',
});

export const setTxWitnessSet = wrap(setTxWitnessSetCore, {
traceKey: 'setTxWitnessSet',
Expand Down
31 changes: 31 additions & 0 deletions apps/rosen/app/_networks/ergo/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { ErgoIcon } from '@rosen-bridge/icons';
import { NETWORK_LABELS, NETWORKS } from '@rosen-ui/constants';
import { nautilusWalletCreator } from '@rosen-ui/nautilus-wallet';

import { unwrap } from '@/_safeServerAction';
import { getTokenMap } from '@/_tokenMap/getClientTokenMap';
import { ErgoNetwork as ErgoNetworkType } from '@/_types';

import { getMaxTransfer } from './getMaxTransfer';
import { generateUnsignedTx } from './server';

const config = {
getTokenMap,
generateUnsignedTx: unwrap(generateUnsignedTx),
};

/**
* the main object for Ergo network
* providing access to network info and wallets and network specific
* functionality
*/
export const ErgoNetwork: ErgoNetworkType = {
name: NETWORKS.ERGO,
label: NETWORK_LABELS.ERGO,
wallets: [nautilusWalletCreator(config)],
logo: ErgoIcon,
nextHeightInterval: 5,
lockAddress: process.env.NEXT_PUBLIC_ERGO_LOCK_ADDRESS!,
getMaxTransfer: unwrap(getMaxTransfer),
toSafeAddress: (address) => address,
};
Loading

0 comments on commit 1890323

Please sign in to comment.