-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
377 changed files
with
8,210 additions
and
2,930 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
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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 | ||
} | ||
/> | ||
); | ||
} |
Oops, something went wrong.