From 8d931ab6511b7e3a586d9e2d784c84807a2a8d72 Mon Sep 17 00:00:00 2001 From: Dani Somoza Date: Tue, 30 Nov 2021 17:46:56 +0100 Subject: [PATCH] New Approach of AddressInput Component (#174) * Added load address from QR code in AddressInput Component * Updated AddressInput Storybook * Added push tag event to trigger the storybook deployment on release * Added 0.9.1 version to package.json --- .github/workflows/deploy-storybook.yml | 5 +- package.json | 3 +- .../AddressInput/AddressInput.stories.tsx | 502 ++++++++++----- src/inputs/AddressInput/index.tsx | 171 +++-- .../__snapshots__/fixedIcon.stories.storyshot | 4 +- .../Icon/__snapshots__/icon.stories.storyshot | 150 ++--- .../AddressInput.stories.storyshot | 602 ++++++++++++------ .../__snapshots__/button.stories.storyshot | 10 +- .../__snapshots__/index.stories.storyshot | 2 +- .../TextFieldInput.stories.storyshot | 2 +- yarn.lock | 34 + 11 files changed, 1002 insertions(+), 483 deletions(-) diff --git a/.github/workflows/deploy-storybook.yml b/.github/workflows/deploy-storybook.yml index 8f2bf412..e6a5e062 100644 --- a/.github/workflows/deploy-storybook.yml +++ b/.github/workflows/deploy-storybook.yml @@ -4,8 +4,9 @@ on: # Pull request hook without any config. Launches for every pull request pull_request: # Launches build when release is published - release: - types: [published] + push: + tags: + - 'v*' env: REPO_NAME_ALPHANUMERIC: safereactcomponents diff --git a/package.json b/package.json index 1f13c288..b498c69f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@gnosis.pm/safe-react-components", - "version": "0.9.0", + "version": "0.9.1", "description": "Gnosis UI components", "main": "dist/index.min.js", "typings": "dist/index.d.ts", @@ -53,6 +53,7 @@ "@typescript-eslint/eslint-plugin": "^4.31.0", "@typescript-eslint/parser": "^4.31.0", "copy-webpack-plugin": "^6.3.0", + "react-qr-reader": "2.2.1", "eslint": "^7.32.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-prettier": "^4.0.0", diff --git a/src/inputs/AddressInput/AddressInput.stories.tsx b/src/inputs/AddressInput/AddressInput.stories.tsx index 68ed328f..92c0f544 100644 --- a/src/inputs/AddressInput/AddressInput.stories.tsx +++ b/src/inputs/AddressInput/AddressInput.stories.tsx @@ -1,12 +1,21 @@ -import React, { useState, useEffect } from 'react'; -import { InputAdornment } from '@material-ui/core'; +import React, { useState, useEffect, useCallback } from 'react'; +import { + Dialog, + DialogContent, + DialogTitle, + InputAdornment, + Typography, + IconButton, + CircularProgress, +} from '@material-ui/core'; import styled from 'styled-components'; import CheckCircle from '@material-ui/icons/CheckCircle'; -import { Typography } from '@material-ui/core'; +import QrReader from 'react-qr-reader'; import AddressInput from './index'; -import { isValidAddress } from '../../utils/address'; -import { Switch } from '..'; +import { isValidAddress, isValidEnsName } from '../../utils/address'; +import { Select, Switch, TextFieldInput } from '..'; +import { Icon } from '../..'; export default { title: 'Inputs/AddressInput', @@ -14,172 +23,239 @@ export default { parameters: { componentSubtitle: 'Address field input with several variants', }, + argTypes: { + showNetworkPrefix: { + control: { type: 'boolean' }, + defaultValue: true, + }, + + hiddenLabel: { + control: { type: 'boolean' }, + defaultValue: true, + }, + disabled: { + control: { type: 'boolean' }, + defaultValue: false, + }, + isLoading: { + control: { type: 'boolean' }, + defaultValue: false, + }, + showErrors: { + control: { type: 'boolean' }, + defaultValue: true, + }, + }, }; const onSubmit = (e: React.FormEvent) => e.preventDefault(); -export const SimpleAddressInput = (): React.ReactElement => { - const [address, setAddress] = useState( - '0x83eC7B0506556a7749306D69681aDbDbd08f0769' - ); - const [showNetworkPrefix, setShowNetworkPrefix] = useState(true); - +const networks = [ + { id: 'eth', label: 'Mainnet (eth:)' }, + { id: 'rin', label: 'Rinkeby (rin:)' }, + { id: 'vt', label: 'Volta (vt:)' }, +]; + +export const SimpleAddressInput = ({ + hiddenLabel, + isDisabled, + isLoading, + showNetworkPrefix, + showErrors, +}: { + hiddenLabel: boolean; + isDisabled: boolean; + isLoading: boolean; + showNetworkPrefix: boolean; + showErrors: boolean; +}): React.ReactElement => { + const [address, setAddress] = useState(''); + const onChangeAddress = useCallback((address) => setAddress(address), []); + + const [currentNetworkPrefix, setCurrentNetworkPrefix] = useState('rin'); + + const [openQRModal, setOpenQRModal] = useState(false); + + const inValidAddressError = !isValidAddress(address) ? 'Invalid Address' : ''; + const inValidNetworkError = address.includes(':') + ? 'The chain prefix must match the current network' + : ''; + + const error = + address && showErrors ? inValidNetworkError || inValidAddressError : ''; + + // fake ENS Resolution const getAddressFromDomain = () => new Promise((resolve) => { setTimeout( () => resolve('0x83eC7B0506556a7749306D69681aDbDbd08f0769'), - 1200 + 2000 ); }); return ( -
- - - Show Network Prefix (rin) - - setAddress(address)} - getAddressFromDomain={getAddressFromDomain} - /> - - Address value in the State:{' '} - -
-        {address || ' '}
-      
- - You can use ENS names (like safe.test) with the getAddressFromDomain - prop - - - ); -}; - -export const AddressInputWithNetworkPrefix = (): React.ReactElement => { - const [address, setAddress] = useState( - '0x83eC7B0506556a7749306D69681aDbDbd08f0769' - ); - - return ( -
- setAddress(address)} +
+ Network Settings: + + + + + + + + + Simulate an error in the resolver ENS Network call +

+
+
+ +
+ +
+

+ Type safe.test to check ENS resolution! +

+
+
+
+ +
+ +
+

+ Customize your throttle delay for ENS resolution! +

+
+
+

+ Address In the State: +

+
+     
+  
`; @@ -226,7 +342,7 @@ exports[`Storyshots Inputs/AddressInput Address Input With Errors 1`] = ` spellCheck={false} >

Invalid Address @@ -265,65 +380,18 @@ exports[`Storyshots Inputs/AddressInput Address Input With Errors 1`] = ` `; -exports[`Storyshots Inputs/AddressInput Address Input With Network Prefix 1`] = ` -

-
- -
- -
-
-
-    Address in the state: 
-    0x83eC7B0506556a7749306D69681aDbDbd08f0769
-  
-
-`; - -exports[`Storyshots Inputs/AddressInput Address Input With Validation 1`] = ` +exports[`Storyshots Inputs/AddressInput Address Input With Simple Address Validation 1`] = `
+

+ Address In the State: +

+
+     
+  
`; @@ -366,7 +443,7 @@ exports[`Storyshots Inputs/AddressInput Address Input Without Prefix 1`] = ` spellCheck={false} >