Skip to content

Commit

Permalink
feat: cctp withdrawals: withdraw form [OTE-855][5/n] (#1155)
Browse files Browse the repository at this point in the history
  • Loading branch information
yogurtandjam authored and rosepuppy committed Oct 24, 2024
1 parent f013a09 commit e6b8258
Show file tree
Hide file tree
Showing 10 changed files with 657 additions and 29 deletions.
23 changes: 23 additions & 0 deletions src/components/ArrowIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import styled, { css } from 'styled-components';

import { Icon, IconName } from './Icon';

export const ArrowIcon = (props: { direction: 'up' | 'down'; color: string }) => {
return <$ArrowIcon {...props} iconName={IconName.Arrow} />;
};

const $ArrowIcon = styled(Icon)<{ direction: 'up' | 'down'; color: string }>`
position: absolute;
${({ direction }) =>
({
up: css`
transform: rotate(-90deg);
`,
down: css`
transform: rotate(90deg);
`,
})[direction]}
${({ color }) => css`
color: var(${color});
`};
`;
40 changes: 33 additions & 7 deletions src/components/FormInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { WithLabel } from '@/components/WithLabel';

type StyleProps = {
className?: string;
backgroundColorOverride?: string;
};

type ElementProps = {
Expand All @@ -28,15 +29,33 @@ type ElementProps = {
export type FormInputProps = ElementProps & StyleProps & InputProps;

export const FormInput = forwardRef<HTMLInputElement, FormInputProps>(
({ id, label, slotRight, className, validationConfig, ...otherProps }, ref) => (
(
{ id, label, slotRight, className, validationConfig, backgroundColorOverride, ...otherProps },
ref
) => (
<$FormInputContainer className={className} isValidationAttached={validationConfig?.attached}>
<$InputContainer hasLabel={!!label} hasSlotRight={!!slotRight}>
{label ? (
<$WithLabel label={label} inputID={id} disabled={otherProps.disabled}>
<Input ref={ref} id={id} {...otherProps} />
<$WithLabel
label={label}
inputID={id}
disabled={otherProps.disabled}
$backgroundColorOverride={backgroundColorOverride}
>
<Input
ref={ref}
id={id}
{...otherProps}
$backgroundColorOverride={backgroundColorOverride}
/>
</$WithLabel>
) : (
<Input ref={ref} id={id} {...otherProps} />
<Input
ref={ref}
id={id}
{...otherProps}
$backgroundColorOverride={backgroundColorOverride}
/>
)}
{slotRight}
</$InputContainer>
Expand Down Expand Up @@ -65,9 +84,11 @@ const $FormInputContainer = styled.div<{ isValidationAttached?: boolean }>`
`}
`;

const $InputContainer = styled.div<{ hasLabel?: boolean; hasSlotRight?: boolean }>`
const $InputContainer = styled.div<{
hasLabel?: boolean;
hasSlotRight?: boolean;
}>`
${formMixins.inputContainer}
input {
${({ hasLabel }) =>
!hasLabel &&
Expand All @@ -89,8 +110,13 @@ const $InputContainer = styled.div<{ hasLabel?: boolean; hasSlotRight?: boolean
`}
`;

const $WithLabel = styled(WithLabel)<{ disabled?: boolean }>`
const $WithLabel = styled(WithLabel)<{ disabled?: boolean; $backgroundColorOverride?: string }>`
${formMixins.inputLabel}
${({ $backgroundColorOverride }) =>
$backgroundColorOverride &&
css`
background-color: ${$backgroundColorOverride};
`}
label {
${({ disabled }) => !disabled && 'cursor: text;'}
Expand Down
3 changes: 3 additions & 0 deletions src/components/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ import {
} from '@/icons';
import { ChaosLabsIcon } from '@/icons/chaos-labs';
import { LogoShortIcon } from '@/icons/logo-short';
import UsdcIcon from '@/icons/usdc.svg';

export enum IconName {
AddressConnector = 'AddressConnector',
Expand Down Expand Up @@ -194,6 +195,7 @@ export enum IconName {
Translate = 'Translate',
Triangle = 'Triangle',
TryAgain = 'TryAgain',
Usdc = 'Usdc',
Warning = 'Warning',
Website = 'Website',
Whitepaper = 'Whitepaper',
Expand Down Expand Up @@ -293,6 +295,7 @@ const icons = {
[IconName.Translate]: TranslateIcon,
[IconName.Triangle]: TriangleIcon,
[IconName.TryAgain]: TryAgainIcon,
[IconName.Usdc]: UsdcIcon,
[IconName.Warning]: WarningIcon,
[IconName.Website]: WebsiteIcon,
[IconName.Whitepaper]: WhitepaperIcon,
Expand Down
20 changes: 18 additions & 2 deletions src/components/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export enum InputType {

type StyleProps = {
className?: string;
$backgroundColorOverride?: string;
};

type ElementProps = {
Expand Down Expand Up @@ -81,6 +82,9 @@ export const Input = forwardRef<HTMLInputElement, InputProps>(
onFocus,
onInput,
type = InputType.Number,
// TODO: https://linear.app/dydx/issue/OTE-888/simplify-input-component-bg-styles
// simplify input component styles. backgroundColorOverride has to override styles in too many places
$backgroundColorOverride: backgroundColorOverride,
...otherProps
},
ref
Expand Down Expand Up @@ -126,6 +130,7 @@ export const Input = forwardRef<HTMLInputElement, InputProps>(
<$InputContainer className={className}>
{type === InputType.Text || type === InputType.Search ? (
<$Input
$backgroundColorOverride={backgroundColorOverride}
// React
ref={ref}
id={id}
Expand All @@ -145,6 +150,7 @@ export const Input = forwardRef<HTMLInputElement, InputProps>(
/>
) : (
<$NumericFormat
$backgroundColorOverride={backgroundColorOverride}
// React
getInputRef={ref}
id={id}
Expand Down Expand Up @@ -234,11 +240,21 @@ const InputStyle = css`
}
`;

const $NumericFormat = styled(NumericFormat)`
const $NumericFormat = styled(NumericFormat)<{ $backgroundColorOverride?: string }>`
${InputStyle}
font-feature-settings: var(--fontFeature-monoNumbers);
${({ $backgroundColorOverride }) =>
$backgroundColorOverride &&
css`
background-color: ${$backgroundColorOverride};
`}
`;

const $Input = styled.input`
const $Input = styled.input<{ $backgroundColorOverride?: string }>`
${InputStyle}
${({ $backgroundColorOverride }) =>
$backgroundColorOverride &&
css`
background-color: ${$backgroundColorOverride};
`}
`;
36 changes: 21 additions & 15 deletions src/hooks/transfers/useTransfers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,24 @@ export const useTransfers = () => {
return getDefaultTokenDenomFromAssets(assetsForSelectedChain);
}, [assetsForSelectedChain]);

const cosmosChainAddresses = useMemo(() => {
if (!dydxAddress) return {};
return {
[getOsmosisChainId()]: convertBech32Address({
address: dydxAddress,
bech32Prefix: OSMO_BECH32_PREFIX,
}),
[getNeutronChainId()]: convertBech32Address({
address: dydxAddress,
bech32Prefix: NEUTRON_BECH32_PREFIX,
}),
[getNobleChainId()]: convertBech32Address({
address: dydxAddress,
bech32Prefix: NOBLE_BECH32_PREFIX,
}),
};
}, [dydxAddress]);

const hasAllParams =
!!fromToken?.denom &&
!!toToken?.denom &&
Expand Down Expand Up @@ -204,21 +222,6 @@ export const useTransfers = () => {
amountIn: parseUnits(amount, fromToken.decimals).toString(),
};

// consider moving to useMemo outside of this query
const cosmosChainAddresses = {
[getOsmosisChainId()]: convertBech32Address({
address: dydxAddress,
bech32Prefix: OSMO_BECH32_PREFIX,
}),
[getNeutronChainId()]: convertBech32Address({
address: dydxAddress,
bech32Prefix: NEUTRON_BECH32_PREFIX,
}),
[getNobleChainId()]: convertBech32Address({
address: dydxAddress,
bech32Prefix: NOBLE_BECH32_PREFIX,
}),
};
// WITHDRAWALS
if (transferType === TransferType.Withdraw) {
return skipClient.msgsDirect({
Expand Down Expand Up @@ -261,6 +264,7 @@ export const useTransfers = () => {
});

const { route, txs } = routeQuery.data ?? {};
const routeLoading = routeQuery.isLoading;
return {
// TODO [onboarding-rewrite]: Think about trimming this list
// Right now we're exposing everything, but there's a good chance we can only expose a few properties
Expand Down Expand Up @@ -291,5 +295,7 @@ export const useTransfers = () => {
fromToken,
debouncedAmount,
debouncedAmountBN,
routeLoading,
cosmosChainAddresses,
};
};
11 changes: 11 additions & 0 deletions src/icons/usdc.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/lib/testFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ class TestFlags {
get uiRefresh() {
return !!this.queryParams.uirefresh || isDev;
}

get onboardingRewrite() {
return !!this.queryParams.onboarding_rewrite;
}
}

export const testFlags = new TestFlags();
21 changes: 16 additions & 5 deletions src/views/dialogs/WithdrawDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,33 @@ import { useStringGetter } from '@/hooks/useStringGetter';
import { layoutMixins } from '@/styles/layoutMixins';

import { Dialog, DialogPlacement } from '@/components/Dialog';
import { Icon, IconName } from '@/components/Icon';
import { WithdrawForm } from '@/views/forms/AccountManagementForms/WithdrawForm';
import { WithdrawForm as WithdrawFormV2 } from '@/views/forms/AccountManagementFormsNew/WithdrawForm/WithdrawForm';

import { testFlags } from '@/lib/testFlags';

export const WithdrawDialog = ({ setIsOpen }: DialogProps<WithdrawDialogProps>) => {
const stringGetter = useStringGetter();
const { isTablet } = useBreakpoints();

return (
<Dialog
isOpen
setIsOpen={setIsOpen}
title={stringGetter({ key: STRING_KEYS.WITHDRAW })}
title={
testFlags.onboardingRewrite ? (
<span tw="row gap-[0.5ch]">
<Icon iconName={IconName.Usdc} size="1.5em" />
{/* TODO [onboarding-rewrite]: localize */}
{stringGetter({ key: STRING_KEYS.WITHDRAW })} USDC
</span>
) : (
stringGetter({ key: STRING_KEYS.WITHDRAW })
)
}
placement={isTablet ? DialogPlacement.FullScreen : DialogPlacement.Default}
>
<$Content>
<WithdrawForm />
</$Content>
<$Content>{testFlags.onboardingRewrite ? <WithdrawFormV2 /> : <WithdrawForm />}</$Content>
</Dialog>
);
};
Expand Down
Loading

0 comments on commit e6b8258

Please sign in to comment.