Skip to content

Commit

Permalink
Tom/updated directory names (#1434)
Browse files Browse the repository at this point in the history
* refactor: rename Bridge -> BTC

* refactor: transfer -> send and receive

* fix: rename Transfer component

* revert change to tab name

* refactor: update translation references

* update schemas

* update directory and file casing

* casing

* casing

* casing

* casing

* casing
  • Loading branch information
tomjeatt authored Jul 7, 2023
1 parent fac977e commit 9b64c30
Show file tree
Hide file tree
Showing 84 changed files with 313 additions and 343 deletions.
14 changes: 6 additions & 8 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import * as constants from './constants';
import TestnetBanner from './legacy-components/TestnetBanner';
import { FeatureFlags, useFeatureFlag } from './utils/hooks/use-feature-flag';

const Bridge = React.lazy(() => import(/* webpackChunkName: 'bridge' */ '@/pages/Bridge'));
const BTC = React.lazy(() => import(/* webpackChunkName: 'bridge' */ '@/pages/BTC'));
const Strategies = React.lazy(() => import(/* webpackChunkName: 'strategies' */ '@/pages/Strategies'));
const Transfer = React.lazy(() => import(/* webpackChunkName: 'transfer' */ '@/pages/Transfer'));
const SendAndReceive = React.lazy(() => import(/* webpackChunkName: 'transfer' */ '@/pages/SendAndReceive'));
const TX = React.lazy(() => import(/* webpackChunkName: 'tx' */ '@/pages/TX'));
const Staking = React.lazy(() => import(/* webpackChunkName: 'staking' */ '@/pages/Staking'));
const Dashboard = React.lazy(() => import(/* webpackChunkName: 'dashboard' */ '@/pages/Dashboard'));
Expand Down Expand Up @@ -184,23 +184,21 @@ const App = (): JSX.Element => {
<Route path={PAGES.TX}>
<TX />
</Route>
<Route path={PAGES.BRIDGE}>
<Bridge />
<Route path={PAGES.BTC}>
<BTC />
</Route>
<Route path={PAGES.TRANSFER}>
<Transfer />
<Route path={PAGES.SEND_AND_RECEIVE}>
<SendAndReceive />
</Route>
<Route path={PAGES.LOANS}>
<Loans />
</Route>
<Route path={PAGES.SWAP}>
<Swap />
</Route>

<Route path={PAGES.POOLS}>
<Pools />
</Route>

<Route path={PAGES.WALLET}>
<Wallet />
</Route>
Expand Down
6 changes: 3 additions & 3 deletions src/assets/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@
"locked_btc": "Locked BTC",
"issue": "Issue",
"redeem": "Redeem",
"nav_bridge": "Bridge",
"nav_btc": "BTC",
"nav_strategies": "Strategies",
"nav_transfer": "Transfer / Bridge",
"nav_send_and_receive": "Send and Receive",
"nav_lending": "Lending",
"nav_swap": "Swap",
"nav_pools": "Pools",
Expand Down Expand Up @@ -726,7 +726,7 @@
"claiming_vesting": "Claiming vesting",
"claimed_vesting": "Claimed vesting"
},
"bridge": {
"btc": {
"max_issuable": "Max issuable",
"max_redeemable": "Max redeemable",
"in_single_request": "In single request",
Expand Down
105 changes: 0 additions & 105 deletions src/lib/form/schemas/bridge.ts

This file was deleted.

105 changes: 105 additions & 0 deletions src/lib/form/schemas/btc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import i18n from 'i18next';

import yup, { AddressType, MaxAmountValidationParams, MinAmountValidationParams } from '../yup.custom';

const BTC_ISSUE_AMOUNT_FIELD = 'issue-amount';
const BTC_ISSUE_CUSTOM_VAULT_FIELD = 'issue-custom-vault';
const BTC_ISSUE_CUSTOM_VAULT_SWITCH = 'issue-custom-vault-switch';
const BTC_ISSUE_GRIEFING_COLLATERAL_TOKEN = 'issue-griefing-collateral-token';
const BTC_ISSUE_FEE_TOKEN = 'issue-fee-token';

type BTCIssueFormData = {
[BTC_ISSUE_AMOUNT_FIELD]?: string;
[BTC_ISSUE_CUSTOM_VAULT_FIELD]?: string;
[BTC_ISSUE_CUSTOM_VAULT_SWITCH]?: boolean;
[BTC_ISSUE_GRIEFING_COLLATERAL_TOKEN]?: string;
[BTC_ISSUE_FEE_TOKEN]?: string;
};

type BTCIssueValidationParams = {
[BTC_ISSUE_AMOUNT_FIELD]: MaxAmountValidationParams & MinAmountValidationParams;
};

const btcIssueSchema = (params: BTCIssueValidationParams): yup.ObjectSchema<any> =>
yup.object().shape({
[BTC_ISSUE_AMOUNT_FIELD]: yup
.string()
.requiredAmount('issue')
.maxAmount(
params[BTC_ISSUE_AMOUNT_FIELD],
'issue',
i18n.t('forms.amount_must_be_at_most', {
action: 'issue',
amount: params[BTC_ISSUE_AMOUNT_FIELD].maxAmount.toString()
})
)
.minAmount(params[BTC_ISSUE_AMOUNT_FIELD], 'issue'),
[BTC_ISSUE_CUSTOM_VAULT_FIELD]: yup.string().when([BTC_ISSUE_CUSTOM_VAULT_SWITCH], {
is: (isManualVault: string) => isManualVault,
then: (schema) => schema.required(i18n.t('forms.please_select_your_field', { field: 'issue vault' }))
}),
[BTC_ISSUE_GRIEFING_COLLATERAL_TOKEN]: yup.string().required(),
[BTC_ISSUE_FEE_TOKEN]: yup.string().required()
});

const BTC_REDEEM_AMOUNT_FIELD = 'redeem-amount';
const BTC_REDEEM_CUSTOM_VAULT_FIELD = 'redeem-custom-vault';
const BTC_REDEEM_CUSTOM_VAULT_SWITCH = 'redeem-custom-vault-switch';
const BTC_REDEEM_PREMIUM_VAULT_FIELD = 'redeem-premium-vault';
const BTC_REDEEM_ADDRESS = 'redeem-address';
const BTC_REDEEM_FEE_TOKEN = 'redeem-fee-token';

type BTCRedeemFormData = {
[BTC_REDEEM_AMOUNT_FIELD]?: string;
[BTC_REDEEM_CUSTOM_VAULT_FIELD]?: string;
[BTC_REDEEM_CUSTOM_VAULT_SWITCH]?: boolean;
[BTC_REDEEM_PREMIUM_VAULT_FIELD]?: boolean;
[BTC_REDEEM_ADDRESS]?: string;
[BTC_REDEEM_FEE_TOKEN]?: string;
};

type BTCRedeemValidationParams = {
[BTC_REDEEM_AMOUNT_FIELD]: MaxAmountValidationParams & MinAmountValidationParams;
};

const btcRedeemSchema = (params: BTCRedeemValidationParams): yup.ObjectSchema<any> =>
yup.object().shape({
[BTC_REDEEM_AMOUNT_FIELD]: yup
.string()
.requiredAmount('redeem')
.maxAmount(
params[BTC_REDEEM_AMOUNT_FIELD],
'redeem',
i18n.t('forms.amount_must_be_at_most', {
action: 'redeem',
amount: params[BTC_REDEEM_AMOUNT_FIELD].maxAmount.toString()
})
)
.minAmount(params[BTC_REDEEM_AMOUNT_FIELD], 'redeem'),
[BTC_REDEEM_CUSTOM_VAULT_FIELD]: yup.string().when([BTC_REDEEM_CUSTOM_VAULT_SWITCH], {
is: (isManualVault: string) => isManualVault,
then: (schema) => schema.required(i18n.t('forms.please_select_your_field', { field: 'redeem vault' }))
}),
[BTC_REDEEM_ADDRESS]: yup
.string()
.required(i18n.t('forms.please_enter_your_field', { field: 'BTC address' }))
.address(AddressType.BTC),
[BTC_REDEEM_FEE_TOKEN]: yup.string().required()
});

export {
BTC_ISSUE_AMOUNT_FIELD,
BTC_ISSUE_CUSTOM_VAULT_FIELD,
BTC_ISSUE_CUSTOM_VAULT_SWITCH,
BTC_ISSUE_FEE_TOKEN,
BTC_ISSUE_GRIEFING_COLLATERAL_TOKEN,
BTC_REDEEM_ADDRESS,
BTC_REDEEM_AMOUNT_FIELD,
BTC_REDEEM_CUSTOM_VAULT_FIELD,
BTC_REDEEM_CUSTOM_VAULT_SWITCH,
BTC_REDEEM_FEE_TOKEN,
BTC_REDEEM_PREMIUM_VAULT_FIELD,
btcIssueSchema,
btcRedeemSchema
};
export type { BTCIssueFormData, BTCRedeemFormData };
2 changes: 1 addition & 1 deletion src/lib/form/schemas/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './bridge';
export * from './btc';
export * from './loans';
export * from './pools';
export * from './strategy';
Expand Down
71 changes: 29 additions & 42 deletions src/lib/form/schemas/transfers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,36 @@ import { TFunction } from 'react-i18next';

import yup, { MaxAmountValidationParams, MinAmountValidationParams } from '../yup.custom';

const CROSS_CHAIN_TRANSFER_FROM_FIELD = 'transfer-from';
const CROSS_CHAIN_TRANSFER_TO_FIELD = 'transfer-to';
const CROSS_CHAIN_TRANSFER_AMOUNT_FIELD = 'transfer-amount';
const CROSS_CHAIN_TRANSFER_TOKEN_FIELD = 'transfer-token';
const CROSS_CHAIN_TRANSFER_TO_ACCOUNT_FIELD = 'transfer-account';
const BRIDGE_FROM_FIELD = 'transfer-from';
const BRIDGE_TO_FIELD = 'transfer-to';
const BRIDGE_AMOUNT_FIELD = 'transfer-amount';
const BRIDGE_TOKEN_FIELD = 'transfer-token';
const BRIDGE_TO_ACCOUNT_FIELD = 'transfer-account';

type CrossChainTransferFormData = {
[CROSS_CHAIN_TRANSFER_FROM_FIELD]?: ChainName;
[CROSS_CHAIN_TRANSFER_TO_FIELD]?: ChainName;
[CROSS_CHAIN_TRANSFER_AMOUNT_FIELD]?: string;
[CROSS_CHAIN_TRANSFER_TOKEN_FIELD]?: string;
[CROSS_CHAIN_TRANSFER_TO_ACCOUNT_FIELD]?: string;
type BridgeFormData = {
[BRIDGE_FROM_FIELD]?: ChainName;
[BRIDGE_TO_FIELD]?: ChainName;
[BRIDGE_AMOUNT_FIELD]?: string;
[BRIDGE_TOKEN_FIELD]?: string;
[BRIDGE_TO_ACCOUNT_FIELD]?: string;
};

type CrossChainTransferValidationParams = {
[CROSS_CHAIN_TRANSFER_AMOUNT_FIELD]: Partial<MaxAmountValidationParams> & Partial<MinAmountValidationParams>;
type BridgeValidationParams = {
[BRIDGE_AMOUNT_FIELD]: Partial<MaxAmountValidationParams> & Partial<MinAmountValidationParams>;
};

// MEMO: until now, only CROSS_CHAIN_TRANSFER_AMOUNT_FIELD needs validation
const crossChainTransferSchema = (params: CrossChainTransferValidationParams, t: TFunction): yup.ObjectSchema<any> =>
// MEMO: until now, only BRIDGE_AMOUNT_FIELD needs validation
const bridgeSchema = (params: BridgeValidationParams, t: TFunction): yup.ObjectSchema<any> =>
yup.object().shape({
[CROSS_CHAIN_TRANSFER_AMOUNT_FIELD]: yup
[BRIDGE_AMOUNT_FIELD]: yup
.string()
.requiredAmount('transfer')
.maxAmount(params[CROSS_CHAIN_TRANSFER_AMOUNT_FIELD] as MaxAmountValidationParams)
.minAmount(params[CROSS_CHAIN_TRANSFER_AMOUNT_FIELD] as MinAmountValidationParams, 'transfer'),
[CROSS_CHAIN_TRANSFER_FROM_FIELD]: yup
.string()
.required(t('forms.please_enter_your_field', { field: 'source chain' })),
[CROSS_CHAIN_TRANSFER_TO_FIELD]: yup
.string()
.required(t('forms.please_enter_your_field', { field: 'destination chain' })),
[CROSS_CHAIN_TRANSFER_TO_ACCOUNT_FIELD]: yup
.string()
.required(t('forms.please_enter_your_field', { field: 'destination' })),
[CROSS_CHAIN_TRANSFER_TOKEN_FIELD]: yup
.string()
.required(t('forms.please_select_your_field', { field: 'transfer token' }))
.maxAmount(params[BRIDGE_AMOUNT_FIELD] as MaxAmountValidationParams)
.minAmount(params[BRIDGE_AMOUNT_FIELD] as MinAmountValidationParams, 'transfer'),
[BRIDGE_FROM_FIELD]: yup.string().required(t('forms.please_enter_your_field', { field: 'source chain' })),
[BRIDGE_TO_FIELD]: yup.string().required(t('forms.please_enter_your_field', { field: 'destination chain' })),
[BRIDGE_TO_ACCOUNT_FIELD]: yup.string().required(t('forms.please_enter_your_field', { field: 'destination' })),
[BRIDGE_TOKEN_FIELD]: yup.string().required(t('forms.please_select_your_field', { field: 'transfer token' }))
});

const TRANSFER_RECIPIENT_FIELD = 'transfer-destination';
Expand Down Expand Up @@ -78,21 +70,16 @@ const transferSchema = (params: TransferValidationParams): yup.ObjectSchema<any>
});

export {
CROSS_CHAIN_TRANSFER_AMOUNT_FIELD,
CROSS_CHAIN_TRANSFER_FROM_FIELD,
CROSS_CHAIN_TRANSFER_TO_ACCOUNT_FIELD,
CROSS_CHAIN_TRANSFER_TO_FIELD,
CROSS_CHAIN_TRANSFER_TOKEN_FIELD,
crossChainTransferSchema,
BRIDGE_AMOUNT_FIELD,
BRIDGE_FROM_FIELD,
BRIDGE_TO_ACCOUNT_FIELD,
BRIDGE_TO_FIELD,
BRIDGE_TOKEN_FIELD,
bridgeSchema,
TRANSFER_AMOUNT_FIELD,
TRANSFER_FEE_TOKEN_FIELD,
TRANSFER_RECIPIENT_FIELD,
TRANSFER_TOKEN_FIELD,
transferSchema
};
export type {
CrossChainTransferFormData,
CrossChainTransferValidationParams,
TransferFormData,
TransferValidationParams
};
export type { BridgeFormData, BridgeValidationParams, TransferFormData, TransferValidationParams };
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const ManualIssueExecutionActionsTable = (props: ManualIssueExecutionActionsTabl
[ManualIssueExecutionActionsTableKeys.Action]: (
<CTALink
to={{
pathname: PAGES.BRIDGE,
pathname: PAGES.BTC,
search: queryString.stringify({
[QUERY_PARAMETERS.ISSUE_REQUEST_ID]: item.id,
[QUERY_PARAMETERS.ISSUE_REQUESTS_PAGE]: calculatePageNumber(TABLE_PAGE_LIMIT, issueRequestItemIndex)
Expand Down
Loading

2 comments on commit 9b64c30

@vercel
Copy link

@vercel vercel bot commented on 9b64c30 Jul 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 9b64c30 Jul 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.