Conversation
| return | ||
| } | ||
| // Check for one address | ||
| let verifiedLastResortAddress = lastResortAddress |
There was a problem hiding this comment.
Can we makes this a utility in util.js with boolean return value? Also, it should show some feedback to the user (e.g. message.error) at appropriate time (e.g. when full length is reached) when the address is incorrect. It should also give some visual signal when the full length is yet to be reached.
| const neighbor = neighbors[0] | ||
|
|
||
| // Check for one address | ||
| let verifiedTransferTo = transferTo |
There was a problem hiding this comment.
Can be merged with above using utility function
There was a problem hiding this comment.
For sure, too much duplication. Will fix.
Screen.Recording.2021-06-29.at.6.19.17.PM.mov |
|
@polymorpher please check again. I've moved the address checker to utils for both wallet creation and transfers. Added a message for the user when address check fails. Also, I noticed the |
| lifespan: duration / WalletConstants.interval, | ||
| slotSize, | ||
| lastResortAddress, | ||
| validLastResortAddress, |
There was a problem hiding this comment.
This won't work because it would change the key of the object.
| duration, | ||
| effectiveTime, | ||
| lastResortAddress, | ||
| validLastResortAddress, |
| <Space direction='vertical' size='small'> | ||
| <Hint>Wallet Address</Hint> | ||
| <Text>{address}</Text> | ||
| <Text>{address && getAddress(address).bech32}</Text> |
There was a problem hiding this comment.
The implementation of getAddress seems to be quite slow. The first thing it does seems to be a regex matching https://github.com/harmony-one/sdk/blob/3c7061887f25c6ba8def5af05672cdc4f44eb2dc/packages/harmony-utils/src/validators.ts#L6 , followed by multiple passes of the 20 bytes array and many string operations and comparisons. It may be too slow to be in the rendering loop. We might need another state variable for it, watched by useEffect and only converted when it is at full length.
| const history = useHistory() | ||
| const location = useLocation() | ||
| const { address, name } = wallet | ||
| const oneAddress = getAddress(address).bech32 |
There was a problem hiding this comment.
Same as above. Another approach is to useMemo, or to implement a custom hook (e.g. useAddress)
| const price = useSelector(state => state.wallet.price) | ||
| const { formatted, fiatFormatted } = util.computeBalance(balance, price) | ||
| const { dailyLimit, lastResortAddress } = wallet | ||
| const oneLastResort = lastResortAddress && getAddress(lastResortAddress).bech32 |
| const wallets = useSelector(state => state.wallet.wallets) | ||
| const match = useRouteMatch(Paths.show) | ||
| const { address, action } = match ? match.params : {} | ||
| const oneAddress = getAddress(address).bech32 |
| return { balance, formatted, fiat, fiatFormatted, valid: true } | ||
| }, | ||
|
|
||
| validateAddress: (address) => { |
There was a problem hiding this comment.
I see error message is prompted in this function instead of at each component themselves. And this function actually convert the address to ETH form, not just validate an address. Perhaps it should be renamed to normalizeAddress or something similar, and the UI prompt should be moved out to another function (e.g. promptBadAddress)
| const neighbor = neighbors[0] | ||
|
|
||
| // Ensure valid address for both 0x and one1 formats | ||
| const validAddress = util.validateAddress(transferTo) |
| } | ||
|
|
||
| // Ensure valid address for both 0x and one1 formats | ||
| const validLastResortAddress = util.validateAddress(lastResortAddress) |
| // Ensure valid address for both 0x and one1 formats | ||
| const validLastResortAddress = util.validateAddress(lastResortAddress) | ||
| if (!validLastResortAddress) { | ||
| return |
There was a problem hiding this comment.
It would be quite hard to keep tracking error handling if the message prompt is absorbed in above function and its name does not suggest it does handle errors.
|
@polymorpher sorry for the confusion. In terms of console errors, I will add them in the function but was trying to avoid console noise . |
|
This should be in a good place to merge. I'm going to revisit the |
| lifespan: duration / WalletConstants.interval, | ||
| slotSize, | ||
| lastResortAddress, | ||
| normalizedAddress, |
There was a problem hiding this comment.
This is still an issue. The expected object key is lastResortAddress
| duration, | ||
| effectiveTime, | ||
| lastResortAddress, | ||
| normalizedAddress, |
There was a problem hiding this comment.
Ah apologies, fixing.
# Conflicts: # code/client/src/util.js
|
I made a quick update on separation of error handling logic, and simplified the normalization: d9a92a5 |
I've tested with both one and eth addresses and they work interchangeably everywhere.