forked from MystenLabs/sui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wallet-ext: dogfooding fixes (MystenLabs#2511)
* wallet-ext: improve import mnemonic validation * use formik & yup * validate on change instead on blur to instantly enable/disable submit * on blur transform the value of the textarea * wallet-ext: css modules show original class name in dev mode * also convert dashes to camelCase for exports * wallet-ext: fix error message overflowing the container * wallet-ext: link to explorer for account details * from settings and active account label * reuse components for explorer and external links * wallet-ext: various ui fixes * button color always black even for anchor elements * wallet container stop expanding to full screen if not necessary * coin type ellipsis text overflow (to avoid overflowing) * coin type title * wallet-ext: allow localhost and sui.io gateway host permissions * to bypass cors when the api does not append the header for the extension origin * wallet-ext: send coins format amount input
- Loading branch information
1 parent
dab176c
commit a7ec54b
Showing
30 changed files
with
707 additions
and
297 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
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
11 changes: 11 additions & 0 deletions
11
wallet/src/ui/app/components/account-address/AccountAddress.module.scss
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,5 +1,16 @@ | ||
.address-container { | ||
display: inline-flex; | ||
flex-direction: row; | ||
align-items: center; | ||
} | ||
|
||
.address { | ||
font-size: 15px; | ||
font-weight: 700; | ||
color: #404040; | ||
} | ||
|
||
.explorer-link { | ||
color: inherit; | ||
margin-left: 5px; | ||
} |
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,55 @@ | ||
// Copyright (c) 2022, Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { memo, useCallback, useMemo } from 'react'; | ||
|
||
import { SUI_ADDRESS_VALIDATION } from './validation'; | ||
|
||
import type { SuiAddress } from '@mysten/sui.js'; | ||
import type { FieldProps } from 'formik'; | ||
import type { ChangeEventHandler } from 'react'; | ||
|
||
export interface AddressInputProps<Values> | ||
extends FieldProps<SuiAddress, Values> { | ||
disabled?: boolean; | ||
placeholder?: string; | ||
className?: string; | ||
} | ||
|
||
function AddressInput<FormValues>({ | ||
disabled: forcedDisabled, | ||
placeholder = '0x...', | ||
className, | ||
form: { isSubmitting, setFieldValue }, | ||
field: { onBlur, name, value }, | ||
}: AddressInputProps<FormValues>) { | ||
const disabled = | ||
forcedDisabled !== undefined ? forcedDisabled : isSubmitting; | ||
const handleOnChange = useCallback<ChangeEventHandler<HTMLInputElement>>( | ||
(e) => { | ||
const address = e.currentTarget.value; | ||
setFieldValue(name, SUI_ADDRESS_VALIDATION.cast(address)); | ||
}, | ||
[setFieldValue, name] | ||
); | ||
const formattedValue = useMemo( | ||
() => SUI_ADDRESS_VALIDATION.cast(value), | ||
[value] | ||
); | ||
return ( | ||
<input | ||
type="text" | ||
{...{ | ||
disabled, | ||
placeholder, | ||
className, | ||
onBlur, | ||
value: formattedValue, | ||
name, | ||
onChange: handleOnChange, | ||
}} | ||
/> | ||
); | ||
} | ||
|
||
export default memo(AddressInput); |
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,22 @@ | ||
// Copyright (c) 2022, Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { isValidSuiAddress } from '@mysten/sui.js'; | ||
import * as Yup from 'yup'; | ||
|
||
export const SUI_ADDRESS_VALIDATION = Yup.string() | ||
.ensure() | ||
.trim() | ||
.required() | ||
.transform((value: string) => | ||
value.startsWith('0x') || value === '' || value === '0' | ||
? value | ||
: `0x${value}` | ||
) | ||
.test( | ||
'is-sui-address', | ||
// eslint-disable-next-line no-template-curly-in-string | ||
'${value} is not a valid Sui address', | ||
(value) => isValidSuiAddress(value) | ||
) | ||
.label("Recipient's address"); |
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 |
---|---|---|
|
@@ -24,4 +24,5 @@ $error-color: #8b1111; | |
|
||
.message { | ||
margin-left: 12px; | ||
overflow-wrap: anywhere; | ||
} |
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
8 changes: 8 additions & 0 deletions
8
wallet/src/ui/app/components/explorer-link/ExplorerLinkType.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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Copyright (c) 2022, Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export enum ExplorerLinkType { | ||
address, | ||
object, | ||
transaction, | ||
} |
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,73 @@ | ||
// Copyright (c) 2022, Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { memo, useMemo } from 'react'; | ||
|
||
import { Explorer } from './Explorer'; | ||
import { ExplorerLinkType } from './ExplorerLinkType'; | ||
import BsIcon from '_components/bs-icon'; | ||
import ExternalLink from '_components/external-link'; | ||
import { useAppSelector } from '_hooks'; | ||
import { activeAccountSelector } from '_redux/slices/account'; | ||
|
||
import type { ObjectId, SuiAddress, TransactionDigest } from '@mysten/sui.js'; | ||
import type { ReactNode } from 'react'; | ||
|
||
export type ExplorerLinkProps = ( | ||
| { | ||
type: ExplorerLinkType.address; | ||
address: SuiAddress; | ||
useActiveAddress?: false; | ||
} | ||
| { | ||
type: ExplorerLinkType.address; | ||
useActiveAddress: true; | ||
} | ||
| { type: ExplorerLinkType.object; objectID: ObjectId } | ||
| { type: ExplorerLinkType.transaction; transactionID: TransactionDigest } | ||
) & { children?: ReactNode; className?: string; title?: string }; | ||
|
||
function useAddress(props: ExplorerLinkProps) { | ||
const { type } = props; | ||
const isAddress = type === ExplorerLinkType.address; | ||
const isProvidedAddress = isAddress && !props.useActiveAddress; | ||
const activeAddress = useAppSelector(activeAccountSelector); | ||
return isProvidedAddress ? props.address : activeAddress; | ||
} | ||
|
||
function ExplorerLink(props: ExplorerLinkProps) { | ||
const { type, children, className, title } = props; | ||
const address = useAddress(props); | ||
const objectID = type === ExplorerLinkType.object ? props.objectID : null; | ||
const transactionID = | ||
type === ExplorerLinkType.transaction ? props.transactionID : null; | ||
const explorerHref = useMemo(() => { | ||
switch (type) { | ||
case ExplorerLinkType.address: | ||
return address && Explorer.getAddressUrl(address); | ||
case ExplorerLinkType.object: | ||
return objectID && Explorer.getObjectUrl(objectID); | ||
case ExplorerLinkType.transaction: | ||
return ( | ||
transactionID && Explorer.getTransactionUrl(transactionID) | ||
); | ||
} | ||
}, [type, address, objectID, transactionID]); | ||
if (!explorerHref) { | ||
return null; | ||
} | ||
return ( | ||
<ExternalLink | ||
href={explorerHref} | ||
className={className} | ||
title={title} | ||
showIcon={false} | ||
> | ||
<> | ||
{children} <BsIcon icon="box-arrow-up-right" /> | ||
</> | ||
</ExternalLink> | ||
); | ||
} | ||
|
||
export default memo(ExplorerLink); |
Oops, something went wrong.