-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(minifront): #1211: remove swap restrictions #1337
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! A lot of little notes here and there, but they're all relatively small things, so feel free to merge after addressing.
return false; | ||
}; | ||
|
||
const mergeBalancesAndAssets = (balances: BalancesResponse[] = [], assets: Metadata[] = []) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (non-blocking): add a return type to make it clear what this function does
const mergeBalancesAndAssets = (balances: BalancesResponse[] = [], assets: Metadata[] = []) => { | |
const mergeBalancesAndAssets = (balances: BalancesResponse[] = [], assets: Metadata[] = []): (BalancesResponse | Metadata)[] => { |
@@ -9,19 +9,101 @@ import { getAddressIndex } from '@penumbra-zone/getters/address-view'; | |||
import { getDisplayDenomFromView, getSymbolFromValueView } from '@penumbra-zone/getters/value-view'; | |||
import { Box } from '@repo/ui/components/ui/box'; | |||
import { motion } from 'framer-motion'; | |||
import { Metadata } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/asset/v1/asset_pb'; | |||
import { filterMetadataBySearch } from './asset-selector'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: importing a helper from inside another component is a little messy.
suggestion: how about putting it in a ./helpers.ts
file?
|
||
const bySearch = (search: string) => (balancesResponse: BalancesResponse) => | ||
const isMetadata = (asset: BalancesResponse | Metadata): asset is Metadata => { | ||
return Boolean('symbol' in asset && 'name' in asset && 'display' in asset); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: I believe you can use asset.getType()
to canonically get the message type.
e.g.,
return Boolean('symbol' in asset && 'name' in asset && 'display' in asset); | |
return asset.getType() === Metadata |
This is provided by the bufbuild tooling, although I can't find docs for getType()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, didn't know about this! Got to modify the suggestion a little to return asset.getType().typeName === Metadata.typeName;
to make it work
}; | ||
|
||
const isBalance = (asset: BalancesResponse | Metadata): asset is BalancesResponse => { | ||
return 'balanceView' in asset && 'accountAddress' in asset; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same note here
onSelect: (value: BalancesResponse | Metadata) => void; | ||
} | ||
|
||
const BalanceItem = ({ asset, value, onSelect }: BalanceItemProps) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: could we move this into its own file?
This file is quite long. I'm generally opposed to having two components in the same file unless one is very small. But this one has its own helpers, etc., so the two are a bit tangled up.
I'd move BalanceSelector
to shared/balance-selector/index.tsx
, and BalanceItem
to shared/balance-selector/balance-item.tsx
icon, | ||
placeholder, | ||
}: { | ||
interface IconInputProps extends Omit<InputProps, 'onChange'> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: we shouldn't be allowing all props to pass through to underlying components in our component design system
This is part of a bigger discussion*, but in short, we've had issues with our component system becoming quite messy because any props can be passed through. For example, this change to the props interface now allows children
, className
, etc. to be passed to <IconInput />
. children
doesn't make sense to pass to it, and className
allows consumers to drastically change the appearance of <IconInput />
in ways they shouldn't be able to.
Instead, please just add autoFocus
as a prop; we can keep adding more props as we need them, rather than allowing all props by default.
* I'm soon going to be converting #432 to a tracking issue so that we can gradually shift our design system components away from our current model.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the detailed explanation, it really helped me understand the idea! Changed this to only add autoFocus
@@ -31,6 +34,7 @@ import { divideAmounts } from '@penumbra-zone/types/amount'; | |||
import { bech32mAssetId } from '@penumbra-zone/bech32m/passet'; | |||
import { SwapSlice } from '.'; | |||
import { sendSimulateTradeRequest } from './helpers'; | |||
import { amountMoreThanBalance } from '../send'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since amountMoreThanBalance
is now used by multiple slices, please extract it to the ./helpers.ts
file, so that slices aren't reaching into each other's code.
if (!assetIn) throw new Error('`assetIn` is undefined'); | ||
if (!assetOut) throw new Error('`assetOut` is undefined'); | ||
if (!isValidAmount(amount, assetIn)) throw new Error('Invalid amount'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch 👍🏻
@@ -15,6 +15,7 @@ import { | |||
InstantSwapSlice, | |||
createInstantSwapSlice, | |||
instantSwapSubmitButtonDisabledSelector, | |||
isValidAmount, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please extract isValidAmount
to ./helpers.ts
, so that slices aren't reaching into each other's code.
setAssetIn: (asset?: BalancesResponse) => void; | ||
setAmount: (amount: string) => void; | ||
setAssetOut: (metadata: Metadata) => void; | ||
setAssetOut: (metadata?: Metadata) => void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these changes necessary? Won't they always be defined if these methods are being called?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see why they're needed from the swap loader.
I have a PR (#1316) to remove this loader, so I guess it's up to you whether to rebase on that once it's merged and then change this requirement, or just change this requirement now and tweak the loader which is going to be removed soon anyway... if that makes sense 😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noticed the removal of swap loader. I added some changes to the zquery fetchers of swappableAssets and balancesResponses, so this code with optional parameters is irrelevant now
# Conflicts: # apps/minifront/src/components/shared/balance-selector.tsx # apps/minifront/src/components/swap/swap-form/token-swap-input.tsx # apps/minifront/src/components/swap/swap-loader.ts # apps/minifront/src/state/swap/index.ts
Closes #1211
What's done:
BalanceSelector
to show not only assets with balances but all available assetsBalanceSelecor
andAssetSelector
to90dvh
BalanceSelecor
andAssetSelector
The balance selector now looks like this: