-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(wallet-dashboard): style send entry screen (#3807)
* feat(wallet-dashboard): style send entry screen WIP * feat(wallet-dashboard): style send entry screen WIP * fix(wallet-dashboard): sort the dependencies * feat(wallet-dashboard): includes icon coin in coin selector * fix(wallet-dashboard): prettier * fix(wallet-dashboard): update schema validation and share gas budget estimation logic * fix(wallet-dashboard): some fixes * fix(wallet-dashboard): some build errors * fix(wallet-dashboard): fix change amount in send token input * fix(wallet-dashboard): linter * fix(wallet-dashboard): linter * fix(wallet-dashboard): core prettier * fix(wallet-dashboard): include interface with props and some fixes * fix(wallet-dashboard): fixes * fix(wallet-dashboard): fixes * fix(wallet-dashboard): move FormInputs to a standalone component * fix(wallet-dashboard): improve AddressInputs props * fix(wallet-dashboard): linter * fix(wallet-dashboard): format core * fix(wallet-dashboard): clean debris * fix(wallet-dashboard): bring back the validation field * fix(wallet-dashboard): bad merge removing duplicated image components * fix(wallet-dashboard): remove unnecesary InputForm component * fix(wallet-dashboard): adjust to full height the dialog body * fix(wallet-dashboard): prettier * fix(wallet-dashboard): max button disabled * feat(wallet-dashboard): improvements * fix(wallet-dashboard): improve formik props * fix(wallet-dashboard): improvements * refactor: Simplify SendTokenFormInput * refactor: prettier:fix * refactor: prettier:fix on apps/core * refactor: Add missing license header to token.ts * fix: linter * fix(wallet-dashboard): linter * fix(wallet-dashboard): linter * feat: Improve validation flow of sent screen * fmt * fix(wallet-dashboard): fixes * fix(wallet-dashboard): linter * fix(wallet-dashboard): error to click max button * fix(wallet-dashboard): add setFieldValue in useEffect * fix(wallet-dashboard): remove default exports * fix(wallet-dashboard): lint * fix(wallet-dashboard): build --------- Co-authored-by: marc2332 <[email protected]> Co-authored-by: Bran <[email protected]>
- Loading branch information
1 parent
47fd999
commit bacfda4
Showing
49 changed files
with
903 additions
and
807 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// Modifications Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { Input, InputType } from '@iota/apps-ui-kit'; | ||
import { Close } from '@iota/ui-icons'; | ||
import { useIotaAddressValidation } from '../../hooks'; | ||
import React, { useCallback } from 'react'; | ||
import { useField, useFormikContext } from 'formik'; | ||
|
||
export interface AddressInputProps { | ||
name: string; | ||
disabled?: boolean; | ||
placeholder?: string; | ||
label?: string; | ||
} | ||
|
||
export function AddressInput({ | ||
name, | ||
disabled, | ||
placeholder = '0x...', | ||
label = 'Enter Recipient Address', | ||
}: AddressInputProps) { | ||
const { validateField } = useFormikContext(); | ||
const [field, meta, helpers] = useField<string>(name); | ||
const iotaAddressValidation = useIotaAddressValidation(); | ||
|
||
const formattedValue = iotaAddressValidation.cast(field.value); | ||
|
||
const handleOnChange = useCallback( | ||
async (e: React.ChangeEvent<HTMLInputElement>) => { | ||
const address = e.currentTarget.value; | ||
await helpers.setValue(iotaAddressValidation.cast(address)); | ||
validateField(name); | ||
}, | ||
[name, iotaAddressValidation], | ||
); | ||
|
||
const clearAddress = () => { | ||
helpers.setValue(''); | ||
}; | ||
|
||
return ( | ||
<Input | ||
type={InputType.Text} | ||
disabled={disabled} | ||
placeholder={placeholder} | ||
value={formattedValue} | ||
name={field.name} | ||
onBlur={field.onBlur} | ||
label={label} | ||
onChange={handleOnChange} | ||
errorMessage={meta.error} | ||
trailingElement={ | ||
formattedValue ? ( | ||
<button | ||
onClick={clearAddress} | ||
type="button" | ||
className="flex items-center justify-center" | ||
> | ||
<Close /> | ||
</button> | ||
) : undefined | ||
} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { ButtonPill, Input, InputType } from '@iota/apps-ui-kit'; | ||
import { CoinStruct } from '@iota/iota-sdk/client'; | ||
import { useGasBudgetEstimation } from '../../hooks'; | ||
import { useEffect } from 'react'; | ||
import { useField, useFormikContext } from 'formik'; | ||
import { TokenForm } from '../../forms'; | ||
|
||
export interface SendTokenInputProps { | ||
coins: CoinStruct[]; | ||
symbol: string; | ||
coinDecimals: number; | ||
activeAddress: string; | ||
to: string; | ||
onActionClick: () => Promise<void>; | ||
isMaxActionDisabled?: boolean; | ||
name: string; | ||
} | ||
|
||
export function SendTokenFormInput({ | ||
coins, | ||
to, | ||
symbol, | ||
coinDecimals, | ||
activeAddress, | ||
onActionClick, | ||
isMaxActionDisabled, | ||
name, | ||
}: SendTokenInputProps) { | ||
const { values, setFieldValue, isSubmitting, validateField } = useFormikContext<TokenForm>(); | ||
const gasBudgetEstimation = useGasBudgetEstimation({ | ||
coinDecimals, | ||
coins: coins ?? [], | ||
activeAddress, | ||
to: to, | ||
amount: values.amount, | ||
isPayAllIota: values.isPayAllIota, | ||
}); | ||
|
||
const [field, meta, helpers] = useField<string>(name); | ||
const errorMessage = meta.error; | ||
const isActionButtonDisabled = isSubmitting || isMaxActionDisabled; | ||
|
||
const renderAction = () => ( | ||
<ButtonPill disabled={isActionButtonDisabled} onClick={onActionClick}> | ||
Max | ||
</ButtonPill> | ||
); | ||
|
||
// gasBudgetEstimation should change when the amount above changes | ||
useEffect(() => { | ||
setFieldValue('gasBudgetEst', gasBudgetEstimation, false); | ||
}, [gasBudgetEstimation, setFieldValue, values.amount]); | ||
|
||
return ( | ||
<Input | ||
type={InputType.NumericFormat} | ||
name={field.name} | ||
onBlur={field.onBlur} | ||
value={field.value} | ||
caption="Est. Gas Fees:" | ||
placeholder="0.00" | ||
label="Send Amount" | ||
suffix={` ${symbol}`} | ||
prefix={values.isPayAllIota ? '~ ' : undefined} | ||
allowNegative={false} | ||
errorMessage={errorMessage} | ||
amountCounter={!errorMessage ? (coins ? gasBudgetEstimation : '--') : undefined} | ||
trailingElement={renderAction()} | ||
decimalScale={coinDecimals ? undefined : 0} | ||
thousandSeparator | ||
onValueChange={async (values) => { | ||
await helpers.setValue(values.value); | ||
validateField(name); | ||
}} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export * from './AddressInput'; | ||
export * from './SendTokenFormInput'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { IOTA_TYPE_ARG } from '@iota/iota-sdk/utils'; | ||
import { Select, SelectOption } from '@iota/apps-ui-kit'; | ||
import { CoinBalance } from '@iota/iota-sdk/client'; | ||
import { useFormatCoin } from '../../hooks'; | ||
import { CoinIcon } from './CoinIcon'; | ||
import { ImageIconSize } from '../icon'; | ||
|
||
interface CoinSelectorProps { | ||
activeCoinType: string; | ||
coins: CoinBalance[]; | ||
onClick: (coinType: string) => void; | ||
} | ||
|
||
export function CoinSelector({ | ||
activeCoinType = IOTA_TYPE_ARG, | ||
coins, | ||
onClick, | ||
}: CoinSelectorProps) { | ||
const activeCoin = coins?.find(({ coinType }) => coinType === activeCoinType) ?? coins?.[0]; | ||
const initialValue = activeCoin?.coinType; | ||
const coinsOptions: SelectOption[] = | ||
coins?.map((coin) => ({ | ||
id: coin.coinType, | ||
renderLabel: () => <CoinSelectOption coin={coin} />, | ||
})) || []; | ||
|
||
return ( | ||
<Select | ||
label="Select Coins" | ||
value={initialValue} | ||
options={coinsOptions} | ||
onValueChange={(coinType) => { | ||
onClick(coinType); | ||
}} | ||
/> | ||
); | ||
} | ||
|
||
function CoinSelectOption({ coin: { coinType, totalBalance } }: { coin: CoinBalance }) { | ||
const [formatted, symbol, { data: coinMeta }] = useFormatCoin(totalBalance, coinType); | ||
const isIota = coinType === IOTA_TYPE_ARG; | ||
|
||
return ( | ||
<div className="flex w-full flex-row items-center justify-between"> | ||
<div className="flex flex-row items-center gap-x-md"> | ||
<div className="flex h-6 w-6 items-center justify-center"> | ||
<CoinIcon size={ImageIconSize.Small} coinType={coinType} rounded /> | ||
</div> | ||
<span className="text-body-lg text-neutral-10"> | ||
{isIota ? (coinMeta?.name || '').toUpperCase() : coinMeta?.name || symbol} | ||
</span> | ||
</div> | ||
<span className="text-label-lg text-neutral-60"> | ||
{formatted} {symbol} | ||
</span> | ||
</div> | ||
); | ||
} |
3 changes: 2 additions & 1 deletion
3
...nents/Popup/Popups/SendCoinPopup/index.ts → apps/core/src/components/coin/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export { default as SendCoinPopup } from './SendCoinPopup'; | ||
export * from './CoinIcon'; | ||
export * from './CoinSelector'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export * from './ImageIcon'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export * from './token'; |
Oops, something went wrong.