Skip to content

Commit

Permalink
Merge branch '423-refactor-default-exports-to-named-exports-in-javasc…
Browse files Browse the repository at this point in the history
…ript-modules-for-enhanced-code-clarity-and' into 'dev'

Resolve "Refactor default exports to named exports in JavaScript modules for enhanced code clarity and maintainability"

Closes #423

See merge request ergo/rosen-bridge/ui!351
  • Loading branch information
vorujack committed Nov 17, 2024
2 parents 1829c3a + 6d08df5 commit 0eb3223
Show file tree
Hide file tree
Showing 36 changed files with 86 additions and 99 deletions.
5 changes: 5 additions & 0 deletions .changeset/curly-bobcats-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rosen-bridge/rosen-app': patch
---

Refactor default exports to named exports in JavaScript modules for enhanced code clarity and maintainability
8 changes: 4 additions & 4 deletions apps/rosen/app/(bridge)/BridgeForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import {
import { NETWORKS } from '@rosen-ui/constants';
import { getDecimalString } from '@rosen-ui/utils';

import useBridgeForm from '@/_hooks/useBridgeForm';
import { useBridgeForm } from '@/_hooks/useBridgeForm';
import { useMaxTransfer } from '@/_hooks/useMaxTransfer';
import { useNetwork } from '@/_hooks/useNetwork';
import useTokenBalance from '@/_hooks/useTokenBalance';
import { useTokenBalance } from '@/_hooks/useTokenBalance';
import { useTokenMap } from '@/_hooks/useTokenMap';
import useTransactionFormData from '@/_hooks/useTransactionFormData';
import useWallet from '@/_hooks/useWallet';
import { useTransactionFormData } from '@/_hooks/useTransactionFormData';
import { useWallet } from '@/_hooks/useWallet';
import { getTokenNameAndId } from '@/_utils';

import { UseAllAmount } from './UseAllAmount';
Expand Down
6 changes: 3 additions & 3 deletions apps/rosen/app/(bridge)/BridgeTransaction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import {

import { useNetwork } from '@/_hooks/useNetwork';
import { useTokenMap } from '@/_hooks/useTokenMap';
import useTransactionFees from '@/_hooks/useTransactionFees';
import useTransactionFormData from '@/_hooks/useTransactionFormData';
import useWallet from '@/_hooks/useWallet';
import { useTransactionFees } from '@/_hooks/useTransactionFees';
import { useTransactionFormData } from '@/_hooks/useTransactionFormData';
import { useWallet } from '@/_hooks/useWallet';
import { getTokenNameAndId } from '@/_utils';

import { ChooseWalletModal } from './ChooseWalletModal';
Expand Down
6 changes: 3 additions & 3 deletions apps/rosen/app/(bridge)/ConnectOrSubmitButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import {
import { useNetwork } from '@/_hooks/useNetwork';
import { useTokenMap } from '@/_hooks/useTokenMap';
import { useTransaction } from '@/_hooks/useTransaction';
import useTransactionFees from '@/_hooks/useTransactionFees';
import useTransactionFormData from '@/_hooks/useTransactionFormData';
import useWallet from '@/_hooks/useWallet';
import { useTransactionFees } from '@/_hooks/useTransactionFees';
import { useTransactionFormData } from '@/_hooks/useTransactionFormData';
import { useWallet } from '@/_hooks/useWallet';
import { getTokenNameAndId } from '@/_utils';

interface ConnectOrSubmitButtonProps {
Expand Down
6 changes: 2 additions & 4 deletions apps/rosen/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { theme } from '@/_theme/theme';

import { WalletContextProvider } from './_contexts/walletContext';
import { SideBar } from './SideBar';
import Toolbar from './Toolbar';
import { Toolbar } from './Toolbar';

const Root = styled('div')(({ theme }) => ({
width: '100vw',
Expand All @@ -44,7 +44,7 @@ interface AppProps {
children?: React.ReactNode;
}

const App = ({ children }: AppProps) => {
export const App = ({ children }: AppProps) => {
return (
<NoSsr>
<ThemeProvider theme={theme}>
Expand All @@ -67,5 +67,3 @@ const App = ({ children }: AppProps) => {
</NoSsr>
);
};

export default App;
4 changes: 1 addition & 3 deletions apps/rosen/app/Toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const pageTitleMap: Record<string, string> = {
/**
* render toolbar containing page title and some actions
*/
const Toolbar = () => {
export const Toolbar = () => {
const page = useSelectedLayoutSegment();

return (
Expand All @@ -28,5 +28,3 @@ const Toolbar = () => {
/>
);
};

export default Toolbar;
4 changes: 2 additions & 2 deletions apps/rosen/app/_backend/assets/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import {
} from '@rosen-ui/asset-calculator';
import { Network } from '@rosen-ui/types';

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

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

const bridgedAssetRepository = dataSource.getRepository(BridgedAssetEntity);
Expand Down
4 changes: 1 addition & 3 deletions apps/rosen/app/_backend/dataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
migrations as assetCalculatorMigrations,
} from '@rosen-ui/asset-calculator';

const dataSource = new DataSource({
export const dataSource = new DataSource({
type: 'postgres',
url: process.env.POSTGRES_URL,
ssl: process.env.POSTGRES_USE_SSL === 'true',
Expand All @@ -39,5 +39,3 @@ const dataSource = new DataSource({
...assetCalculatorMigrations.postgres,
],
});

export default dataSource;
2 changes: 1 addition & 1 deletion apps/rosen/app/_backend/events/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { BlockEntity } from '@rosen-bridge/scanner';
import { EventTriggerEntity } from '@rosen-bridge/watcher-data-extractor';
import { Network } from '@rosen-ui/types';

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

const blockRepository = dataSource.getRepository(BlockEntity);
Expand Down
2 changes: 1 addition & 1 deletion apps/rosen/app/_backend/initialize-datasource-if-needed.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import dataSource from './dataSource';
import { dataSource } from './dataSource';

if (!dataSource.isInitialized) {
await dataSource.initialize();
Expand Down
4 changes: 1 addition & 3 deletions apps/rosen/app/_errors/NotFoundError.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
class NotFoundError extends Error {}

export default NotFoundError;
export class NotFoundError extends Error {}
6 changes: 2 additions & 4 deletions apps/rosen/app/_hooks/useBridgeForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import { unwrap } from '@/_safeServerAction';
import { getMaxTransfer, getMinTransfer } from '@/_utils';

import { useTokenMap } from './useTokenMap';
import useTransactionFormData from './useTransactionFormData';
import { useTransactionFormData } from './useTransactionFormData';

/**
* handles the form field registrations and form state changes
* and validations
*/

const useBridgeForm = () => {
export const useBridgeForm = () => {
const { control, resetField, reset, setValue, formState, setFocus } =
useTransactionFormData();

Expand Down Expand Up @@ -141,5 +141,3 @@ const useBridgeForm = () => {
formState,
};
};

export default useBridgeForm;
6 changes: 3 additions & 3 deletions apps/rosen/app/_hooks/useMaxTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { RosenAmountValue } from '@rosen-ui/types';
import { getMaxTransfer } from '@/_utils';

import { useNetwork } from './useNetwork';
import useTokenBalance from './useTokenBalance';
import useTransactionFormData from './useTransactionFormData';
import useWallet from './useWallet';
import { useTokenBalance } from './useTokenBalance';
import { useTransactionFormData } from './useTransactionFormData';
import { useWallet } from './useWallet';

/**
* a hook version of `getMaxTransfer` util
Expand Down
2 changes: 1 addition & 1 deletion apps/rosen/app/_hooks/useNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Network } from '@rosen-ui/types';

import { AvailableNetworks, availableNetworks } from '@/_networks';

import useBridgeForm from './useBridgeForm';
import { useBridgeForm } from './useBridgeForm';
import { useTokenMap } from './useTokenMap';

type BlackList = {
Expand Down
8 changes: 3 additions & 5 deletions apps/rosen/app/_hooks/useTokenBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { TokenInfo } from '@rosen-ui/types';
import { RosenAmountValue } from '@rosen-ui/types';
import { Wallet } from '@rosen-ui/wallet-api';

import useBridgeForm from './useBridgeForm';
import useWallet from './useWallet';
import { useBridgeForm } from './useBridgeForm';
import { useWallet } from './useWallet';

interface UseTokenBalance {
isLoading: boolean;
Expand All @@ -18,7 +18,7 @@ interface UseTokenBalance {
* returns the amount of currently selected asset
* @returns CONTAINS A WRAPPED-VALUE
*/
const useTokenBalance = () => {
export const useTokenBalance = () => {
const [balanceState, setBalanceState] = useState<UseTokenBalance>({
isLoading: false,
amount: 0n,
Expand Down Expand Up @@ -65,5 +65,3 @@ const useTokenBalance = () => {

return balanceState;
};

export default useTokenBalance;
4 changes: 2 additions & 2 deletions apps/rosen/app/_hooks/useTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { getNonDecimalString } from '@rosen-ui/utils';

import { useNetwork } from './useNetwork';
import { useTokenMap } from './useTokenMap';
import useTransactionFormData from './useTransactionFormData';
import useWallet from './useWallet';
import { useTransactionFormData } from './useTransactionFormData';
import { useWallet } from './useWallet';

/**
* a react hook to create and sign and submit transactions
Expand Down
4 changes: 1 addition & 3 deletions apps/rosen/app/_hooks/useTransactionFees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { useTokenMap } from './useTokenMap';
* calculates the fees for a token swap between
* two networks
*/
const useTransactionFees = (
export const useTransactionFees = (
sourceChain: Network | null,
targetChain: Network | null,
token: RosenChainToken | null,
Expand Down Expand Up @@ -167,5 +167,3 @@ const useTransactionFees = (

return transactionFees;
};

export default useTransactionFees;
4 changes: 1 addition & 3 deletions apps/rosen/app/_hooks/useTransactionFormData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { BridgeForm } from '@/(bridge)/page';
* provide access to the bridge form context and current form values
*/

const useTransactionFormData = () => {
export const useTransactionFormData = () => {
const { control, ...rest } = useFormContext<FieldValues, BridgeForm>();

const sourceValue = useWatch({ control, name: 'source' }) as Network | null;
Expand All @@ -27,5 +27,3 @@ const useTransactionFormData = () => {
...rest,
};
};

export default useTransactionFormData;
4 changes: 1 addition & 3 deletions apps/rosen/app/_hooks/useWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const toWalletDescriptor = (wallet: WalletBase): WalletDescriptor => {
* handles the wallet connections for all the networks
* and reconnect to the wallet on app startup
*/
const useWallet = () => {
export const useWallet = () => {
const walletGlobalContext = useContext(WalletContext);
const isConnecting = useRef<boolean>(false);
const { get, set } = useLocalStorageManager();
Expand Down Expand Up @@ -127,5 +127,3 @@ const useWallet = () => {
}
: {};
};

export default useWallet;
4 changes: 1 addition & 3 deletions apps/rosen/app/_networks/bitcoin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const config = {
* providing access to network info and wallets and network specific
* functionality
*/
const BitcoinNetwork: BitcoinNetworkType = {
export const BitcoinNetwork: BitcoinNetworkType = {
name: NETWORKS.BITCOIN,
label: NETWORK_LABELS.BITCOIN,
logo: BitcoinIcon,
Expand All @@ -37,5 +37,3 @@ const BitcoinNetwork: BitcoinNetworkType = {
getMaxTransfer: unwrap(getMaxTransfer),
toSafeAddress: (address) => address,
};

export default BitcoinNetwork;
4 changes: 1 addition & 3 deletions apps/rosen/app/_networks/cardano/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const config = {
* providing access to network info and wallets and network specific
* functionality
*/
const CardanoNetwork: CardanoNetworkType = {
export const CardanoNetwork: CardanoNetworkType = {
name: NETWORKS.CARDANO,
label: NETWORK_LABELS.CARDANO,
wallets: [
Expand All @@ -45,5 +45,3 @@ const CardanoNetwork: CardanoNetworkType = {
getMaxTransfer: unwrap(getMaxTransfer),
toSafeAddress: (address) => address,
};

export default CardanoNetwork;
4 changes: 1 addition & 3 deletions apps/rosen/app/_networks/ergo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const config = {
* providing access to network info and wallets and network specific
* functionality
*/
const ErgoNetwork: ErgoNetworkType = {
export const ErgoNetwork: ErgoNetworkType = {
name: NETWORKS.ERGO,
label: NETWORK_LABELS.ERGO,
wallets: [nautilusWalletCreator(config)],
Expand All @@ -29,5 +29,3 @@ const ErgoNetwork: ErgoNetworkType = {
getMaxTransfer: unwrap(getMaxTransfer),
toSafeAddress: (address) => address,
};

export default ErgoNetwork;
4 changes: 1 addition & 3 deletions apps/rosen/app/_networks/ethereum/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { generateLockData, generateTxParameters } from './server';
* providing access to network info and wallets and network specific
* functionality
*/
const EthereumNetwork: EthereumNetworkType = {
export const EthereumNetwork: EthereumNetworkType = {
name: NETWORKS.ETHEREUM,
label: NETWORK_LABELS.ETHEREUM,
wallets: [
Expand All @@ -30,5 +30,3 @@ const EthereumNetwork: EthereumNetworkType = {
getMaxTransfer: unwrap(getMaxTransfer),
toSafeAddress: (address) => address.toLowerCase(),
};

export default EthereumNetwork;
8 changes: 4 additions & 4 deletions apps/rosen/app/_networks/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { NETWORKS } from '@rosen-ui/constants';

import BitcoinNetwork from './bitcoin';
import CardanoNetwork from './cardano';
import ErgoNetwork from './ergo';
import EthereumNetwork from './ethereum';
import { BitcoinNetwork } from './bitcoin';
import { CardanoNetwork } from './cardano';
import { ErgoNetwork } from './ergo';
import { EthereumNetwork } from './ethereum';

export const availableNetworks = {
[NETWORKS.ERGO]: ErgoNetwork,
Expand Down
2 changes: 1 addition & 1 deletion apps/rosen/app/api/v1/assets/detail/[id]/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getAsset } from '@/_backend/assets';

import withValidation from '../../../withValidation';
import { withValidation } from '../../../withValidation';
import { validateGet } from './validations';

export const GET = withValidation(validateGet, (value) => getAsset(value.id));
2 changes: 1 addition & 1 deletion apps/rosen/app/api/v1/assets/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { pick } from 'lodash-es';

import { getAllAssets } from '@/_backend/assets';

import withValidation from '../withValidation';
import { withValidation } from '../withValidation';
import { validateGet } from './validations';

export const GET = withValidation(validateGet, (value) =>
Expand Down
6 changes: 3 additions & 3 deletions apps/rosen/app/api/v1/events/route.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { getEventsWithFullTokenData } from '@/_backend/events';

import withValidation from '../withValidation';
import EventsValidations from './validations';
import { withValidation } from '../withValidation';
import { validateGet } from './validations';

export const GET = withValidation(EventsValidations.GET, (value) =>
export const GET = withValidation(validateGet, (value) =>
getEventsWithFullTokenData(value.offset, value.limit),
);
8 changes: 1 addition & 7 deletions apps/rosen/app/api/v1/events/validations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ const getQueryParamsSchema = Joi.object<GETQueryParams>().keys({
* validate get requests
* @param request
*/
const validateGet = ({ nextUrl: { searchParams } }: NextRequest) => {
export const validateGet = ({ nextUrl: { searchParams } }: NextRequest) => {
return getQueryParamsSchema.validate(Object.fromEntries(searchParams));
};

const EventsValidations = {
GET: validateGet,
};

export default EventsValidations;
Loading

0 comments on commit 0eb3223

Please sign in to comment.