Skip to content

Commit

Permalink
refactor: remove legacy v1 token supports in sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
swimthor committed Oct 26, 2022
1 parent 622e9d8 commit 1587efb
Show file tree
Hide file tree
Showing 84 changed files with 2,252 additions and 1,296 deletions.
2 changes: 1 addition & 1 deletion apps/scripts/src/config/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const EMPTY_MAP: TokenConfig["wrappedDetails"] = new Map();
export const DEVNET_SWIMUSD: TokenConfig = {
isDisabled: !isPoolRestructureEnabled(),
id: "devnet-swimusd",
projectId: TokenProjectId.SwimLpSolanaUsdcUsdt,
projectId: TokenProjectId.SwimUsd,
nativeEcosystemId: SOLANA_ECOSYSTEM_ID,
nativeDetails: {
address: "5ctnNpb7h1SyPqZ8t8m2kCykrtDGVZBtZgYWv6UAeDhr", // TODO: Update
Expand Down
13 changes: 9 additions & 4 deletions apps/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
"last 1 safari version"
]
},
"jest": {
"moduleNameMapper": {
"!!url-loader!.+\\.svg": "<rootDir>/src/__mocks__/base64Mock.ts"
}
},
"engines": {
"node": "^16"
},
Expand All @@ -51,13 +56,13 @@
"@solana/spl-token": "^0.3.5",
"@solana/web3.js": "^1.62.0",
"@swim-io/aptos": "^0.40.0",
"@swim-io/core": "^0.40.0",
"@swim-io/evm": "^0.40.0",
"@swim-io/core": "workspace:^",
"@swim-io/evm": "workspace:^",
"@swim-io/evm-contracts": "^0.40.0",
"@swim-io/pool-math": "^0.40.0",
"@swim-io/solana": "^0.40.0",
"@swim-io/solana": "workspace:^",
"@swim-io/solana-contracts": "^0.40.0",
"@swim-io/token-projects": "^0.40.0",
"@swim-io/token-projects": "workspace:^",
"@swim-io/utils": "^0.40.0",
"@swim-io/wormhole": "^0.40.0",
"bn.js": "^5.2.1",
Expand Down
2 changes: 2 additions & 0 deletions apps/ui/src/__mocks__/base64Mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const dataUrl = "base64";
export default dataUrl;
10 changes: 5 additions & 5 deletions apps/ui/src/components/AddForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ import {
EuiText,
} from "@elastic/eui";
import { SOLANA_ECOSYSTEM_ID } from "@swim-io/solana";
import { TOKEN_PROJECTS_BY_ID } from "@swim-io/token-projects";
import { filterMap, isEachNotNull, isNotNull } from "@swim-io/utils";
import type Decimal from "decimal.js";
import type { FormEvent, ReactElement } from "react";
import { useMemo, useState } from "react";
import { useTranslation } from "react-i18next";
import shallow from "zustand/shallow.js";

import type { EcosystemId, PoolSpec, TokenConfig } from "../config";
import {
DISABLED_ECOSYSTEMS,
ECOSYSTEMS,
ECOSYSTEM_IDS,
getTokenProject,
isEcosystemEnabled,
} from "../config";
import type { EcosystemId, PoolSpec, TokenConfig } from "../config";
import { selectConfig } from "../core/selectors";
import { useEnvironment, useNotification } from "../core/store";
import { captureAndWrapException } from "../errors";
Expand Down Expand Up @@ -86,7 +86,7 @@ const TokenAddPanel = ({
onBlur,
}: TokenAddPanelProps): ReactElement => {
const { t } = useTranslation();
const tokenProject = TOKEN_PROJECTS_BY_ID[tokenConfig.projectId];
const tokenProject = getTokenProject(tokenConfig.projectId);
const balance = useUserBalanceAmount(tokenConfig, ecosystemId);
return (
<EuiFormRow
Expand Down Expand Up @@ -283,7 +283,7 @@ export const AddForm = ({

const lpTargetEcosystemOptions: readonly EuiRadioGroupOption[] = [
lpToken.nativeEcosystemId,
...(poolSpec.isLegacyPool ? lpToken.wrappedDetails.keys() : []),
...(poolSpec.isLegacyPool ? lpToken.wrappedDetails?.keys() ?? [] : []),
].map((ecosystemId) => {
const ecosystem = ECOSYSTEMS[ecosystemId];
return {
Expand Down Expand Up @@ -499,7 +499,7 @@ export const AddForm = ({
}
};

const lpTokenProject = TOKEN_PROJECTS_BY_ID[lpToken.projectId];
const lpTokenProject = getTokenProject(lpToken.projectId);
const receiveLabel = poolSpec.isStakingPool
? t("add_token_form.choose_receive_tokens_on", {
tokenSymbol: lpTokenProject.symbol,
Expand Down
2 changes: 1 addition & 1 deletion apps/ui/src/components/EuiFieldIntlNumber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* eslint-disable react/prop-types */

import { EuiFieldNumber } from "@elastic/eui";
import type { Override } from "@swim-io/utils";
import escapeStringRegexp from "escape-string-regexp";
import type { ComponentProps } from "react";
import { forwardRef, useCallback } from "react";
Expand All @@ -17,7 +18,6 @@ const MappedEuiFieldNumber = forwardRef<
return <EuiFieldNumber {...props} inputRef={ref} />;
});

type Override<T, U> = Omit<T, keyof U> & U;
type Props = Override<
Omit<ComponentProps<typeof CurrencyInput>, "customInput" | "onChange">,
{
Expand Down
4 changes: 2 additions & 2 deletions apps/ui/src/components/PoolListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
EuiTitle,
EuiToolTip,
} from "@elastic/eui";
import { TOKEN_PROJECTS_BY_ID } from "@swim-io/token-projects";
import { chunks } from "@swim-io/utils";
import Decimal from "decimal.js";
import type { ReactElement } from "react";
Expand All @@ -17,6 +16,7 @@ import { useNavigate } from "react-router-dom";

import { atomicToCurrencyString } from "../amounts";
import type { PoolSpec, TokenConfig } from "../config";
import { getTokenProject } from "../config";
import { i18next } from "../i18n";

import { TokenIcon } from "./TokenIcon";
Expand Down Expand Up @@ -92,7 +92,7 @@ export const PoolListItem = ({
style={{ margin: flexItemMargin }}
>
<TokenIcon
{...TOKEN_PROJECTS_BY_ID[tokenConfig.projectId]}
{...getTokenProject(tokenConfig.projectId)}
ecosystemId={
!isLegacyPool && poolEcosystem !== null
? poolEcosystem
Expand Down
11 changes: 5 additions & 6 deletions apps/ui/src/components/RemoveForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
import { APTOS_ECOSYSTEM_ID } from "@swim-io/aptos";
import { EvmEcosystemId } from "@swim-io/evm";
import { SOLANA_ECOSYSTEM_ID } from "@swim-io/solana";
import { TOKEN_PROJECTS_BY_ID } from "@swim-io/token-projects";
import type { ReadonlyRecord } from "@swim-io/utils";
import {
defaultIfError,
Expand All @@ -31,7 +30,7 @@ import { useTranslation } from "react-i18next";
import shallow from "zustand/shallow.js";

import type { EcosystemId, PoolSpec, TokenConfig } from "../config";
import { DISABLED_ECOSYSTEMS, ECOSYSTEMS } from "../config";
import { DISABLED_ECOSYSTEMS, ECOSYSTEMS, getTokenProject } from "../config";
import { selectConfig } from "../core/selectors";
import { useEnvironment, useNotification } from "../core/store";
import { captureAndWrapException } from "../errors";
Expand Down Expand Up @@ -337,7 +336,7 @@ export const RemoveForm = ({

const lpSourceEcosystemOptions: readonly EuiRadioGroupOption[] = [
lpToken.nativeEcosystemId,
...(poolSpec.isLegacyPool ? lpToken.wrappedDetails.keys() : []),
...(poolSpec.isLegacyPool ? lpToken.wrappedDetails?.keys() ?? [] : []),
].map((ecosystemId) => {
const ecosystem = ECOSYSTEMS[ecosystemId];
const lpBalance = userLpBalances[ecosystemId];
Expand Down Expand Up @@ -396,7 +395,7 @@ export const RemoveForm = ({
);
return {
value: id,
text: `${TOKEN_PROJECTS_BY_ID[tokenConfig.projectId].displayName} (${
text: `${getTokenProject(tokenConfig.projectId).displayName} (${
ECOSYSTEMS[tokenConfig.nativeEcosystemId].displayName
})`,
};
Expand Down Expand Up @@ -642,7 +641,7 @@ export const RemoveForm = ({
}
};

const lpTokenProject = TOKEN_PROJECTS_BY_ID[lpToken.projectId];
const lpTokenProject = getTokenProject(lpToken.projectId);
const maximumLpBurnLabel = poolSpec.isStakingPool
? t("remove_token_form.max_required_lp_tokens", {
tokenSymbol: lpTokenProject.symbol,
Expand Down Expand Up @@ -814,7 +813,7 @@ export const RemoveForm = ({
prepend={
<EuiButtonEmpty size="xs">
<TokenIcon
{...TOKEN_PROJECTS_BY_ID[tokenConfig.projectId]}
{...getTokenProject(tokenConfig.projectId)}
/>
</EuiButtonEmpty>
}
Expand Down
4 changes: 2 additions & 2 deletions apps/ui/src/components/SwapForm/SwapForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import {
} from "@elastic/eui";
import { EvmEcosystemId } from "@swim-io/evm";
import { SOLANA_ECOSYSTEM_ID } from "@swim-io/solana";
import { TOKEN_PROJECTS_BY_ID } from "@swim-io/token-projects";
import { defaultIfError, isEachNotNull } from "@swim-io/utils";
import type Decimal from "decimal.js";
import type { FormEvent, ReactElement, ReactNode } from "react";
import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import shallow from "zustand/shallow.js";

import { getTokenProject } from "../../config";
import { selectConfig } from "../../core/selectors";
import { useEnvironment, useNotification } from "../../core/store";
import { captureAndWrapException } from "../../errors";
Expand Down Expand Up @@ -110,7 +110,7 @@ export const SwapForm = ({ maxSlippageFraction }: Props): ReactElement => {

const isLargeSwap = useIsLargeSwap(fromToken, toToken, inputAmount);
const isSmallEthSwap =
TOKEN_PROJECTS_BY_ID[fromToken.projectId].isStablecoin &&
getTokenProject(fromToken.projectId).isStablecoin &&
[fromToken.nativeEcosystemId, toToken.nativeEcosystemId].includes(
EvmEcosystemId.Ethereum,
) &&
Expand Down
5 changes: 2 additions & 3 deletions apps/ui/src/components/SwapFormV2/SwapFormV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ import {
} from "@elastic/eui";
import { EvmEcosystemId } from "@swim-io/evm";
import { SOLANA_ECOSYSTEM_ID } from "@swim-io/solana";
import { TOKEN_PROJECTS_BY_ID } from "@swim-io/token-projects";
import { defaultIfError } from "@swim-io/utils";
import Decimal from "decimal.js";
import type { FormEvent, ReactElement, ReactNode } from "react";
import { useState } from "react";
import { useTranslation } from "react-i18next";
import shallow from "zustand/shallow.js";

import { getTokenDetailsForEcosystem } from "../../config";
import { getTokenDetailsForEcosystem, getTokenProject } from "../../config";
import { selectConfig } from "../../core/selectors";
import { useEnvironment, useNotification } from "../../core/store";
import { captureAndWrapException } from "../../errors";
Expand Down Expand Up @@ -109,7 +108,7 @@ export const SwapFormV2 = ({ maxSlippageFraction }: Props): ReactElement => {
maxSlippageFraction,
);
const isSmallEthSwap =
TOKEN_PROJECTS_BY_ID[fromTokenConfig.projectId].isStablecoin &&
getTokenProject(fromTokenConfig.projectId).isStablecoin &&
[fromTokenOption.ecosystemId, toTokenOption.ecosystemId].includes(
EvmEcosystemId.Ethereum,
) &&
Expand Down
7 changes: 3 additions & 4 deletions apps/ui/src/components/TokenIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { EuiIcon } from "@elastic/eui";
import type { TokenProject } from "@swim-io/token-projects";
import { TOKEN_PROJECTS_BY_ID } from "@swim-io/token-projects";
import type { ComponentProps, ReactElement } from "react";
import { Fragment } from "react";
import { Trans } from "react-i18next";

import type { EcosystemId, TokenConfig } from "../config";
import { ECOSYSTEMS } from "../config";
import { ECOSYSTEMS, getTokenProject } from "../config";
import { useIntlListSeparators } from "../hooks";
import type { Amount } from "../models/amount";

Expand Down Expand Up @@ -117,13 +116,13 @@ export const TokenConfigIcon = ({
ecosystem,
}: TokenConfigIconProps): ReactElement => (
<TokenIcon
{...TOKEN_PROJECTS_BY_ID[token.projectId]}
{...getTokenProject(token.projectId)}
ecosystemId={ecosystem ?? token.nativeEcosystemId}
/>
);

export const TokenSearchConfigIcon = ({
token,
}: Pick<TokenConfigIconProps, "token">): ReactElement => (
<TokenIcon {...TOKEN_PROJECTS_BY_ID[token.projectId]} />
<TokenIcon {...getTokenProject(token.projectId)} />
);
10 changes: 7 additions & 3 deletions apps/ui/src/components/TokenSearchModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ import {
EuiSelectable,
} from "@elastic/eui";
import type { EuiSelectableOption } from "@elastic/eui";
import { TOKEN_PROJECTS_BY_ID } from "@swim-io/token-projects";
import { useCallback } from "react";
import type { ReactElement } from "react";
import { useTranslation } from "react-i18next";
import shallow from "zustand/shallow.js";

import type { EcosystemId, TokenConfig } from "../config";
import { ECOSYSTEM_LIST, isEcosystemEnabled, isSwimUsd } from "../config";
import {
ECOSYSTEM_LIST,
getTokenProject,
isEcosystemEnabled,
isSwimUsd,
} from "../config";
import { selectConfig } from "../core/selectors";
import { useEnvironment } from "../core/store";
import { useUserBalanceAmount } from "../hooks";
Expand Down Expand Up @@ -88,7 +92,7 @@ export const TokenSearchModal = ({
);

const options = filteredTokens.map((token) => {
const tokenProject = TOKEN_PROJECTS_BY_ID[token.projectId];
const tokenProject = getTokenProject(token.projectId);
return {
label: `${tokenProject.symbol}`,
searchableLabel: `${tokenProject.symbol} ${tokenProject.displayName}`,
Expand Down
6 changes: 3 additions & 3 deletions apps/ui/src/components/molecules/AddTransfer.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { EuiLoadingSpinner, EuiText } from "@elastic/eui";
import { TOKEN_PROJECTS_BY_ID } from "@swim-io/token-projects";
import { filterMap } from "@swim-io/utils";
import type { VFC } from "react";
import { useTranslation } from "react-i18next";

import type { EcosystemId, TokenConfig } from "../../config";
import { getTokenProject } from "../../config";
import { useIntlListFormatter } from "../../hooks";
import type { Amount } from "../../models";

Expand All @@ -29,11 +29,11 @@ export const AddTransfer: VFC<Props> = ({
const listFormatter = useIntlListFormatter();
const nonZeroInputTokens = filterMap(
(amount: Amount) => !amount.isZero(),
(amount) => TOKEN_PROJECTS_BY_ID[amount.tokenConfig.projectId].symbol,
(amount) => getTokenProject(amount.tokenConfig.projectId).symbol,
fromAmounts,
);
const inputTokenNames = listFormatter.format(nonZeroInputTokens);
const outputTokenName = TOKEN_PROJECTS_BY_ID[toToken.projectId].symbol;
const outputTokenName = getTokenProject(toToken.projectId).symbol;

return (
<EuiText size="m">
Expand Down
4 changes: 2 additions & 2 deletions apps/ui/src/components/molecules/ClaimSwimUsdOnSolana.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { EuiLoadingSpinner, EuiText } from "@elastic/eui";
import { SOLANA_ECOSYSTEM_ID } from "@swim-io/solana";
import { TOKEN_PROJECTS_BY_ID } from "@swim-io/token-projects";
import type { VFC } from "react";
import { useTranslation } from "react-i18next";

import { getTokenProject } from "../../config";
import { useSwimUsd } from "../../hooks";

import { TxEcosystemList } from "./TxList";
Expand All @@ -30,7 +30,7 @@ export const ClaimSwimUsdOnSolana: VFC<Props> = ({
{isLoading && <EuiLoadingSpinner size="m" style={{ marginRight: 8 }} />}
<span>
{t("recent_interactions.claim_token_on_solana", {
tokenName: TOKEN_PROJECTS_BY_ID[swimUsd.projectId].displayName,
tokenName: getTokenProject(swimUsd.projectId).displayName,
})}
</span>
</span>
Expand Down
6 changes: 3 additions & 3 deletions apps/ui/src/components/molecules/RemoveTransfer.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { EuiLoadingSpinner, EuiText } from "@elastic/eui";
import { TOKEN_PROJECTS_BY_ID } from "@swim-io/token-projects";
import { filterMap } from "@swim-io/utils";
import type { VFC } from "react";
import { useTranslation } from "react-i18next";

import type { EcosystemId, TokenConfig } from "../../config";
import { getTokenProject } from "../../config";
import { useIntlListFormatter } from "../../hooks";
import type { Amount } from "../../models";

Expand All @@ -29,11 +29,11 @@ export const RemoveTransfer: VFC<Props> = ({
const listFormatter = useIntlListFormatter();
const nonZeroOutputTokens = filterMap(
(amount: Amount) => !amount.isZero(),
(amount) => TOKEN_PROJECTS_BY_ID[amount.tokenConfig.projectId].symbol,
(amount) => getTokenProject(amount.tokenConfig.projectId).symbol,
toAmounts,
);
const outputTokenNames = listFormatter.format(nonZeroOutputTokens);
const inputTokenName = TOKEN_PROJECTS_BY_ID[fromToken.projectId].symbol;
const inputTokenName = getTokenProject(fromToken.projectId).symbol;

return (
<EuiText size="m">
Expand Down
8 changes: 3 additions & 5 deletions apps/ui/src/components/molecules/SwapTransfer.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { EuiLoadingSpinner, EuiText } from "@elastic/eui";
import { TOKEN_PROJECTS_BY_ID } from "@swim-io/token-projects";
import type { VFC } from "react";
import { useTranslation } from "react-i18next";

import type { EcosystemId, TokenConfig } from "../../config";
import { ECOSYSTEMS } from "../../config";
import { ECOSYSTEMS, getTokenProject } from "../../config";

import { TxEcosystemList } from "./TxList";

Expand All @@ -30,9 +29,8 @@ export const SwapTransfer: VFC<Props> = ({
{isLoading && <EuiLoadingSpinner size="m" style={{ marginRight: 8 }} />}
<span>
{t("recent_interactions.swap_token_from_x_to_y", {
fromTokenName:
TOKEN_PROJECTS_BY_ID[fromToken.projectId].displayName,
toTokenName: TOKEN_PROJECTS_BY_ID[toToken.projectId].displayName,
fromTokenName: getTokenProject(fromToken.projectId).displayName,
toTokenName: getTokenProject(toToken.projectId).displayName,
ecosystemName: ECOSYSTEMS[ecosystemId].displayName,
})}
</span>
Expand Down
Loading

0 comments on commit 1587efb

Please sign in to comment.