Skip to content

Commit

Permalink
refactor: send step 1/summary
Browse files Browse the repository at this point in the history
  • Loading branch information
stackchain committed Dec 18, 2023
1 parent 94adaf9 commit 5e15c7c
Show file tree
Hide file tree
Showing 35 changed files with 768 additions and 546 deletions.
5 changes: 3 additions & 2 deletions apps/wallet-mobile/.storybook/storybook.requires.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apps/wallet-mobile/src/WalletInit/WalletForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export const WalletForm = ({onSubmit}: Props) => {
onChangeText={setPassword}
errorText={passwordErrorText}
returnKeyType="next"
helperText={strings.passwordStrengthRequirement({
helper={strings.passwordStrengthRequirement({
requiredPasswordLength: REQUIRED_PASSWORD_LENGTH,
})}
right={!passwordErrors.passwordIsWeak ? <Checkmark /> : undefined}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ storiesOf('TextInput', module)
autoFocus
label="with helper text"
onChangeText={action('onChangeText')}
helperText="This is what helper text looks like"
helper="This is what helper text looks like"
autoComplete="off"
/>
))
Expand All @@ -92,7 +92,7 @@ storiesOf('TextInput', module)
autoFocus
label="with helper text and error text"
onChangeText={action('onChangeText')}
helperText="This is what helper text looks like"
helper="This is what helper text looks like"
errorText="This is what an error looks likes"
autoComplete="off"
/>
Expand Down
26 changes: 19 additions & 7 deletions apps/wallet-mobile/src/components/TextInput/TextInput.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {isString} from '@yoroi/common'
import React, {ForwardedRef} from 'react'
import {
StyleSheet,
Expand All @@ -18,7 +19,7 @@ export type TextInputProps = RNTextInputProps &
Omit<React.ComponentProps<typeof RNPTextInput>, 'theme'> & {
containerStyle?: ViewStyle
renderComponentStyle?: ViewStyle
helperText?: string
helper?: string | React.ReactNode
errorText?: string
disabled?: boolean
errorOnMount?: boolean
Expand Down Expand Up @@ -52,7 +53,7 @@ export const TextInput = React.forwardRef((props: TextInputProps, ref: Forwarded
containerStyle,
renderComponentStyle,
secureTextEntry,
helperText,
helper,
errorText,
errorOnMount,
errorDelay,
Expand All @@ -75,6 +76,20 @@ export const TextInput = React.forwardRef((props: TextInputProps, ref: Forwarded
value,
errorDelay,
)
const showError = errorTextEnabled && !isEmptyString(errorText)
const showHelperComponent = helper != null && !isString(helper)

const helperToShow = showError ? (
<HelperText type="error" visible>
{errorText}
</HelperText>
) : showHelperComponent ? (
helper
) : (
<HelperText type="info" visible>
{helper}
</HelperText>
)

return (
<View style={containerStyle}>
Expand Down Expand Up @@ -129,11 +144,7 @@ export const TextInput = React.forwardRef((props: TextInputProps, ref: Forwarded
{...restProps}
/>

{!noHelper && (
<HelperText type={errorTextEnabled && !isEmptyString(errorText) ? 'error' : 'info'} visible>
{errorTextEnabled && !isEmptyString(errorText) ? errorText : helperText}
</HelperText>
)}
{!noHelper && helperToShow}
</View>
)
})
Expand All @@ -151,6 +162,7 @@ export const HelperText = ({
visible?: boolean
}) => (
<HelperTextRNP
style={{paddingHorizontal: 0}}
theme={{
roundness: 8,
colors: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {StyleSheet, View} from 'react-native'
import {ButtonGroup} from './ButtonGroup'

const WithInitial = ({initial}: {initial: number}) => {
const handleActive = (label: string) => {
action(`onSelect ${label}`)
const handleActive = (index: number, label: string) => {
action(`onSelect ${index}:${label}`)
}
return (
<View>
Expand All @@ -17,8 +17,8 @@ const WithInitial = ({initial}: {initial: number}) => {
}

const NoInitial = () => {
const handleActive = (label: string) => {
action(`onSelect ${label}`)
const handleActive = (index: number, label: string) => {
action(`onSelect ${index}:${label}`)
}
return (
<View>
Expand Down
4 changes: 2 additions & 2 deletions apps/wallet-mobile/src/features/Send/common/SendContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ const targetsReducer = (state: SendState, action: TargetAction) => {
if (addressRecords !== undefined) {
const keys = Object.keys(addressRecords).filter(isNameServer)
const nameServer = keys.length === 1 ? keys[0] : undefined
target.receiver.selectedNameServer =nameServer
target.receiver.selectedNameServer = nameServer
if (nameServer !== undefined) {
target.entry.address = addressRecords[nameServer] ?? ''
}
Expand Down Expand Up @@ -273,7 +273,7 @@ export const initialState: SendState = {
},
},
],
}
}

export const useTokenQuantities = (tokenId: string) => {
const wallet = useSelectedWallet()
Expand Down
1 change: 1 addition & 0 deletions apps/wallet-mobile/src/features/Send/common/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const memoMaxLenght = 256
2 changes: 2 additions & 0 deletions apps/wallet-mobile/src/features/Send/common/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export class AddressErrorWrongNetwork extends Error {}
export class AddressErrorInvalid extends Error {}
34 changes: 31 additions & 3 deletions apps/wallet-mobile/src/features/Send/common/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ export const useStrings = () => {
const intl = useIntl()

return {
addressInputErrorInvalidAddress: intl.formatMessage(messages.addressInputErrorInvalidAddress),
addressInputErrorInvalidDomain: intl.formatMessage(messages.addressInputErrorInvalidDomain),
addressInputLabel: intl.formatMessage(messages.addressInputLabel),
addressReaderQrText: intl.formatMessage(messages.addressReaderQrText),
all: intl.formatMessage(globalMessages.all),
Expand Down Expand Up @@ -36,8 +34,14 @@ export const useStrings = () => {
feeLabel: intl.formatMessage(messages.feeLabel),
feeNotAvailable: intl.formatMessage(messages.feeNotAvailable),
found: intl.formatMessage(messages.found),
helperAddressErrorInvalid: intl.formatMessage(messages.helperAddressErrorInvalid),
helperAddressErrorWrongNetwork: intl.formatMessage(messages.helperAddressErrorWrongNetwork),
helperMemoErrorTooLong: intl.formatMessage(messages.helperMemoErrorTooLong),
helperMemoInstructions: intl.formatMessage(messages.helperMemoInstructions),
helperResolverErrorUnsupportedDomain: intl.formatMessage(messages.helperResolverErrorUnsupportedDomain),
manyNameServersWarning: intl.formatMessage(messages.manyNameServersWarning),
max: intl.formatMessage(globalMessages.max),
memoLabel: intl.formatMessage(messages.memoLabel),
minPrimaryBalanceForTokens: intl.formatMessage(amountInputErrorMessages.minPrimaryBalanceForTokens),
next: intl.formatMessage(globalMessages.next),
nfts: (qty: number) => intl.formatMessage(globalMessages.nfts, {qty}),
Expand Down Expand Up @@ -279,7 +283,31 @@ export const messages = defineMessages({
defaultMessage: '!!!Yoroi Supports Name Resolution',
},
manyNameServersWarning: {
id: 'send.resolver.manyNameServersWarning',
id: 'send.warning.resolver.manyNameServers',
defaultMessage: '!!!Multiple name servers found. Please select one.',
},
helperAddressErrorInvalid: {
id: 'send.helper.addressError.invalid',
defaultMessage: '!!!Please enter valid address',
},
helperAddressErrorWrongNetwork: {
id: 'send.helper.addressError.wrongNetwork',
defaultMessage: '!!!Please enter valid domain',
},
helperResolverErrorUnsupportedDomain: {
id: 'send.helper.resolverError.unsupportedDomain',
defaultMessage: '!!!Domain is not supported',
},
memoLabel: {
id: 'components.send.memofield.label',
defaultMessage: '!!!Memo',
},
helperMemoInstructions: {
id: 'components.send.memofield.message',
defaultMessage: '!!!(Optional) Memo is stored locally',
},
helperMemoErrorTooLong: {
id: 'components.send.memofield.error',
defaultMessage: '!!!Memo is too long',
},
})
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {useQuery, UseQueryOptions} from 'react-query'

import {useSelectedWallet} from '../../../SelectedWallet'
import {normalizeToAddress, toCardanoNetworkId} from '../../../yoroi-wallets/cardano/utils'
import {AddressErrorInvalid, AddressErrorWrongNetwork} from './errors'
import {useSend} from './SendContext'

export const useSendAddress = () => {
Expand Down Expand Up @@ -58,10 +59,10 @@ const useValidateAddress = (
// NOTE: should be a wallet function from address manager
const validateAddress = async (address: string, chainId: number) => {
const chainAddress = await normalizeToAddress(address)
if (!chainAddress) throw new Error('Invalid address')
if (!chainAddress) throw new AddressErrorInvalid()

const chainAddressChainId = await chainAddress.networkId()
if (chainAddressChainId !== chainId) throw new Error('Wrong network')
if (chainAddressChainId !== chainId) throw new AddressErrorWrongNetwork()

return true
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import {isNameServer, useResolverCryptoAddresses} from '@yoroi/resolver'
import {isDomain, isNameServer, isResolvableDomain, useResolverCryptoAddresses} from '@yoroi/resolver'
import {Resolver} from '@yoroi/types'
import * as React from 'react'
import {useQueryClient} from 'react-query'

import {debounceMaker} from '../../../utils/debounceMaker'
import {useSend} from './SendContext'

export const useSendInputReceiver = () => {
export const useSendReceiver = () => {
const queryClient = useQueryClient()

const {targets, selectedTargetIndex, receiverResolveChanged, addressRecordsFetched} = useSend()
const receiver = targets[selectedTargetIndex].receiver
const isUnsupportedDomain = !isResolvableDomain(receiver.resolve) && isDomain(receiver.resolve)

const {
error: receiverError,
Expand Down Expand Up @@ -59,18 +60,13 @@ export const useSendInputReceiver = () => {
},
undefined,
)
// TODO: revisit
// addressRecordsFetched(records)
console.log(records)
addressRecordsFetched({
handle: 'addr1vxggvx6uq9mtf6e0tyda2mahg84w8azngpvkwr5808ey6qsy2ww7d',
cns: 'addr1qywgh46dqu7lq6mp5c6tzldpmzj6uwx335ydrpq8k7rru4q6yhkfqn5pc9f3z76e4cr64e5mf98aaeht6zwf8xl2nc9qr66sqg',
})
addressRecordsFetched(records)
}
}, [addressRecordsFetched, cryptoAddresses, isSuccess])

return {
isResolvingAddressess,
isUnsupportedDomain,
receiverError,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ export const ConfirmTxScreen = () => {
<Spacer height={16} />

{targets.map((target, index) => (
// TODO: revisit
<ReceiverInfo key={index} receiver={target.receiver.resolve} />
<ReceiverInfo key={`${target.receiver.resolve}:${index}`} target={target} />
))}
</View>

Expand All @@ -103,15 +102,13 @@ export const ConfirmTxScreen = () => {
<SecondaryTotals yoroiUnsignedTx={yoroiUnsignedTx} />

{!wallet.isEasyConfirmationEnabled && !wallet.isHW && (
<>
<ValidatedTextInput
secureTextEntry
value={password}
label={strings.password}
onChangeText={setPassword}
testID="spendingPasswordInput"
/>
</>
<ValidatedTextInput
secureTextEntry
value={password}
label={strings.password}
onChangeText={setPassword}
testID="spendingPasswordInput"
/>
)}

<KeyboardSpacer />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,33 @@
import {nameServerName} from '@yoroi/resolver'
import * as React from 'react'
import {View} from 'react-native'

import {Spacer} from '../../../../../components/Spacer'
import {Text} from '../../../../../components/Text'
import {YoroiTarget} from '../../../../../yoroi-wallets/types'
import {useStrings} from '../../../common/strings'
// import {Service} from '../../StartMultiTokenTx/InputReceiver/ResolveAddress'

type Props = {
receiver: string
target: YoroiTarget
}
export const ReceiverInfo = ({receiver}: Props) => {
export const ReceiverInfo = ({target}: Props) => {
const strings = useStrings()

// const {resolvedAddressSelected} = useResolver()

// TODO: revisit
const isResolved = true
// !isEmptyString(resolvedAddressSelected?.address) && !isEmptyString(resolvedAddressSelected?.service)
const {receiver, entry} = target

return (
<View>
<Text>{strings.receiver}:</Text>

<Spacer height={12} />

{isResolved ? (
{target.receiver.as === 'domain' ? (
<>
<View style={{flexDirection: 'row'}}>
{/* <Text>{Service[resolvedAddressSelected?.service ?? ''] ?? ''}:</Text> */}
<Text>{receiver.selectedNameServer ? nameServerName[receiver.selectedNameServer] : ''}:</Text>

<Spacer width={5} />

<Text>{receiver}</Text>
<Text>{receiver.resolve}</Text>
</View>

<Spacer height={12} />
Expand All @@ -40,10 +36,10 @@ export const ReceiverInfo = ({receiver}: Props) => {

<Spacer height={12} />

{/* <Text testID="receiverAddressText">{resolvedAddressSelected?.address}</Text> */}
<Text testID="receiverAddressText">{entry.address}</Text>
</>
) : (
<Text testID="receiverAddressText">{receiver}</Text>
<Text testID="receiverAddressText">{entry.address}</Text>
)}
</View>
)
Expand Down
Loading

0 comments on commit 5e15c7c

Please sign in to comment.