Skip to content

Commit

Permalink
Update the EUR icon and name on Vortex UI (#95)
Browse files Browse the repository at this point in the history
* add EUR icon

* show fiat icons in pool selector modal

* improve code readability of SelectionModal

* implement showing FIAT

* simplify useGetIcon hook

* Simplify and streamline icon definition

* Fix bug for invalid token storage items

---------

Co-authored-by: Torsten Stüber <15174476+TorstenStueber@users.noreply.github.com>
  • Loading branch information
Sharqiewicz and TorstenStueber authored Aug 21, 2024
1 parent b54fbfe commit 12b4073
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 121 deletions.
34 changes: 34 additions & 0 deletions src/assets/coins/EUR.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 6 additions & 26 deletions src/components/AssetNumericInput/index.tsx
Original file line number Diff line number Diff line change
@@ -1,48 +1,29 @@
import { FC, useMemo } from 'preact/compat';
import { UseFormRegisterReturn } from 'react-hook-form';
import { ConnectButton } from '@rainbow-me/rainbowkit';
import { InputTokenType, OutputTokenType } from '../../constants/tokenConfig';
import { AssetButton } from '../buttons/AssetButton';
import { SwapFormValues } from '../Nabla/schema';
import { NumericInput } from '../NumericInput';

export const ChainName = () => (
<ConnectButton.Custom>
{({ account, chain, openChainModal, openConnectModal, authenticationStatus, mounted }) => {
const ready = mounted && authenticationStatus !== 'loading';
const connected =
ready && account && chain && (!authenticationStatus || authenticationStatus === 'authenticated');

return (
<button type="button" className="text-sm text-blue-700" onClick={connected ? openChainModal : openConnectModal}>
{chain?.name || ''}
</button>
);
}}
</ConnectButton.Custom>
);
import { AssetIconType } from '../../hooks/useGetIcon';

interface AssetNumericInputProps {
tokenType?: InputTokenType | OutputTokenType;
tokenSymbol?: string;
assetIcon: AssetIconType;
tokenSymbol: string;
onClick: () => void;
additionalText?: string;
disabled?: boolean;
readOnly?: boolean;
registerInput: UseFormRegisterReturn<keyof SwapFormValues>;
}

export const AssetNumericInput: FC<AssetNumericInputProps> = ({
additionalText,
tokenType,
assetIcon,
tokenSymbol,
onClick,
registerInput,
...rest
}) => {
const memoizedAssetButton = useMemo(
() => <AssetButton tokenType={tokenType} tokenSymbol={tokenSymbol} onClick={onClick} />,
[tokenType, tokenSymbol, onClick],
() => <AssetButton assetIcon={assetIcon} tokenSymbol={tokenSymbol} onClick={onClick} />,
[assetIcon, tokenSymbol, onClick],
);

return (
Expand All @@ -55,7 +36,6 @@ export const AssetNumericInput: FC<AssetNumericInputProps> = ({
<div className="flex items-center justify-between">
{memoizedAssetButton}
<div className="w-2"></div>
{additionalText ? <p className="text-sm text-blue-700">{additionalText}</p> : <ChainName />}
</div>

<NumericInput
Expand Down
16 changes: 8 additions & 8 deletions src/components/ExchangeRate/index.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { FC } from 'preact/compat';
import { InputTokenDetails, OutputTokenDetails } from '../../constants/tokenConfig';
import { InputTokenDetails } from '../../constants/tokenConfig';
import { UseTokenOutAmountResult } from '../../hooks/nabla/useTokenAmountOut';

interface ExchangeRateProps {
fromToken?: InputTokenDetails;
toToken?: OutputTokenDetails;
fromToken: InputTokenDetails;
toTokenSymbol: string;
tokenOutData: UseTokenOutAmountResult;
}

export const ExchangeRate: FC<ExchangeRateProps> = ({ tokenOutData, fromToken, toToken }) => {
export const ExchangeRate: FC<ExchangeRateProps> = ({ tokenOutData, fromToken, toTokenSymbol }) => {
const exchangeRate =
fromToken !== undefined && toToken !== undefined && !tokenOutData.isLoading && tokenOutData.data ? (
<>{`1 ${fromToken.assetSymbol} = ${Number(tokenOutData.data.effectiveExchangeRate).toFixed(2)} ${
toToken.stellarAsset.code.string
}`}</>
fromToken !== undefined && !tokenOutData.isLoading && tokenOutData.data ? (
<>{`1 ${fromToken.assetSymbol} = ${Number(tokenOutData.data.effectiveExchangeRate).toFixed(
2,
)} ${toTokenSymbol}`}</>
) : (
`-`
);
Expand Down
8 changes: 3 additions & 5 deletions src/components/FeeCollapse/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ function calculateFeesUSD(fromAmount: string): string {
interface CollapseProps {
fromAmount?: string;
toAmount?: string;
toCurrency?: OutputTokenType;
toTokenSymbol: string;
}

export const FeeCollapse: FC<CollapseProps> = ({ fromAmount, toAmount, toCurrency }) => {
export const FeeCollapse: FC<CollapseProps> = ({ fromAmount, toAmount, toTokenSymbol }) => {
const [isOpen, setIsOpen] = useState(false);
const { trackEvent } = useEventsContext();

Expand All @@ -35,8 +35,6 @@ export const FeeCollapse: FC<CollapseProps> = ({ fromAmount, toAmount, toCurrenc
setIsOpen((state) => !state);
};

const outputToken = toCurrency ? OUTPUT_TOKEN_CONFIG[toCurrency] : undefined;

const chevron = isOpen ? (
<ChevronUpIcon className="w-8 text-blue-700" />
) : (
Expand All @@ -52,7 +50,7 @@ export const FeeCollapse: FC<CollapseProps> = ({ fromAmount, toAmount, toCurrenc
<div className="flex items-center justify-between">
<p>
<strong className="font-bold">
{totalReceive} {outputToken?.stellarAsset.code.string}
{totalReceive} {toTokenSymbol}
</strong>
&nbsp;is what you will receive, after fees
</p>
Expand Down
6 changes: 4 additions & 2 deletions src/components/InputKeys/PoolListItem/index.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import { Avatar, AvatarProps, Button } from 'react-daisyui';
import { CheckIcon } from '@heroicons/react/20/solid';
import { useGetIcon } from '../../../hooks/useGetIcon';
import { AssetIconType, useGetIcon } from '../../../hooks/useGetIcon';
import { InputTokenType, OutputTokenType } from '../../../constants/tokenConfig';

interface PoolListItemProps<T extends InputTokenType | OutputTokenType> {
tokenType: T;
tokenSymbol: string;
isSelected?: boolean;
onSelect: (tokenType: T) => void;
assetIcon: AssetIconType;
}

export function PoolListItem<T extends InputTokenType | OutputTokenType>({
tokenType,
tokenSymbol,
isSelected,
onSelect,
assetIcon,
}: PoolListItemProps<T>) {
const tokenIcon = useGetIcon(tokenType);
const tokenIcon = useGetIcon(assetIcon);

return (
<Button
Expand Down
12 changes: 7 additions & 5 deletions src/components/InputKeys/SelectionModal.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Input } from 'react-daisyui';
import { ChangeEvent, useState } from 'preact/compat';
import { InputTokenType, OutputTokenType } from '../../constants/tokenConfig';
import { Fiat, InputTokenType, OutputTokenType } from '../../constants/tokenConfig';
import { Dialog } from '../Dialog';
import { Skeleton } from '../Skeleton';
import { PoolListItem } from './PoolListItem';
import { AssetIconType } from '../../hooks/useGetIcon';

interface PoolSelectorModalProps<T extends InputTokenType | OutputTokenType> extends PoolListProps<T> {
isLoading?: boolean;
Expand All @@ -12,9 +13,9 @@ interface PoolSelectorModalProps<T extends InputTokenType | OutputTokenType> ext
}

interface PoolListProps<T extends InputTokenType | OutputTokenType> {
definitions: { assetSymbol: string; type: T }[];
definitions: { assetSymbol: string; type: T; assetIcon: AssetIconType }[];
onSelect: (tokenType: InputTokenType | OutputTokenType) => void;
selected: InputTokenType | OutputTokenType | undefined;
selected: InputTokenType | OutputTokenType;
}

export function PoolSelectorModal<T extends InputTokenType | OutputTokenType>({
Expand Down Expand Up @@ -45,13 +46,14 @@ function PoolList<T extends InputTokenType | OutputTokenType>({ onSelect, defini
placeholder="Find by name or address"
/>
<div className="flex flex-col gap-1">
{definitions.map(({ assetSymbol, type }) => (
{definitions.map(({ assetIcon, assetSymbol, type }) => (
<PoolListItem
key={type}
isSelected={selected === assetSymbol}
isSelected={selected === type}
onSelect={onSelect}
tokenType={type}
tokenSymbol={assetSymbol}
assetIcon={assetIcon}
/>
))}
</div>
Expand Down
8 changes: 6 additions & 2 deletions src/components/Nabla/useSwapForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ export const useSwapForm = () => {

const initialState = useMemo(() => {
const storageValues = storageService.getParsed<SwapSettings>(storageKeys.SWAP_SETTINGS);

const storedFromTokenIsValid = INPUT_TOKEN_CONFIG[storageValues?.from as InputTokenType] !== undefined;
const storedToTokenIsValid = OUTPUT_TOKEN_CONFIG[storageValues?.to as OutputTokenType] !== undefined;

return {
from: (storageValues?.from ?? 'usdc') as InputTokenType,
to: (storageValues?.to ?? 'eurc') as OutputTokenType,
from: (storedFromTokenIsValid ? storageValues?.from : 'usdc') as InputTokenType,
to: (storedToTokenIsValid ? storageValues?.to : 'eurc') as OutputTokenType,
taxNumber: '',
bankAccount: '',
};
Expand Down
15 changes: 7 additions & 8 deletions src/components/buttons/AssetButton/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { InputTokenType, OutputTokenType } from '../../../constants/tokenConfig';
import { useGetIcon } from '../../../hooks/useGetIcon';
import { AssetIconType, useGetIcon } from '../../../hooks/useGetIcon';

interface AssetButtonProps {
tokenType?: InputTokenType | OutputTokenType;
tokenSymbol?: string;
assetIcon: AssetIconType;
tokenSymbol: string;
onClick: () => void;
}
export function AssetButton({ tokenType, tokenSymbol, onClick }: AssetButtonProps) {
const icon = useGetIcon(tokenType);
export function AssetButton({ assetIcon, tokenSymbol, onClick }: AssetButtonProps) {
const icon = useGetIcon(assetIcon);

return (
<button
Expand All @@ -16,9 +15,9 @@ export function AssetButton({ tokenType, tokenSymbol, onClick }: AssetButtonProp
type="button"
>
<span className="h-full p-px mr-1 rounded-full">
{tokenType && <img src={icon} alt={tokenType} className="w-auto h-full" />}
<img src={icon} alt={assetIcon} className="w-auto h-full" />
</span>
<strong className="font-bold text-black">{tokenSymbol || 'Select'}</strong>
<strong className="font-bold text-black">{tokenSymbol}</strong>
</button>
);
}
21 changes: 14 additions & 7 deletions src/constants/tokenConfig.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import UsdcIcon from '../assets/coins/USDC.png';
import EurcIcon from '../assets/coins/EURC.png';
import { AssetIconType } from '../hooks/useGetIcon';

export interface InputTokenDetails {
assetSymbol: string;
Expand All @@ -9,15 +8,21 @@ export interface InputTokenDetails {
pendulumCurrencyId: { XCM: number };
pendulumAssetSymbol: string;
};
polygonAssetIcon: AssetIconType;
decimals: number;
icon: string;
}

export type InputTokenType = 'usdc' | 'usdce';

export interface Fiat {
assetIcon: AssetIconType;
symbol: string;
}

export interface OutputTokenDetails {
tomlFileUrl: string;
decimals: number;
fiat: Fiat;
stellarAsset: {
code: {
hex: string;
Expand All @@ -32,7 +37,6 @@ export interface OutputTokenDetails {
minWithdrawalAmountRaw: string;
maxWithdrawalAmountRaw: string;
erc20WrapperAddress: string;
icon: string;
}
export const INPUT_TOKEN_CONFIG: Record<InputTokenType, InputTokenDetails> = {
usdc: {
Expand All @@ -43,8 +47,8 @@ export const INPUT_TOKEN_CONFIG: Record<InputTokenType, InputTokenDetails> = {
pendulumCurrencyId: { XCM: 12 },
pendulumAssetSymbol: 'USDC.axl',
},
polygonAssetIcon: 'polygonUSDC',
decimals: 6,
icon: UsdcIcon,
},
usdce: {
assetSymbol: 'USDC.e',
Expand All @@ -54,8 +58,8 @@ export const INPUT_TOKEN_CONFIG: Record<InputTokenType, InputTokenDetails> = {
pendulumCurrencyId: { XCM: 12 },
pendulumAssetSymbol: 'USDC.axl',
},
polygonAssetIcon: 'polygonUSDC',
decimals: 6,
icon: UsdcIcon,
},
};

Expand All @@ -64,6 +68,10 @@ export const OUTPUT_TOKEN_CONFIG: Record<OutputTokenType, OutputTokenDetails> =
eurc: {
tomlFileUrl: 'https://mykobo.co/.well-known/stellar.toml',
decimals: 12,
fiat: {
assetIcon: 'eur',
symbol: 'EUR',
},
stellarAsset: {
code: {
hex: '0x45555243',
Expand All @@ -78,7 +86,6 @@ export const OUTPUT_TOKEN_CONFIG: Record<OutputTokenType, OutputTokenDetails> =
erc20WrapperAddress: '6fA9DRKJ12oTXfSAU7ZZGZ9gEQ92YnyRXeJzW1wXekPzeXZC',
minWithdrawalAmountRaw: '10000000000000',
maxWithdrawalAmountRaw: '10000000000000000',
icon: EurcIcon,
},
};

Expand Down
Loading

0 comments on commit 12b4073

Please sign in to comment.