Skip to content

Giv/8 one address#21

Merged
polymorpher merged 8 commits intomasterfrom
giv/8-one-address
Jul 1, 2021
Merged

Giv/8 one address#21
polymorpher merged 8 commits intomasterfrom
giv/8-one-address

Conversation

@givp
Copy link
Copy Markdown
Collaborator

@givp givp commented Jun 30, 2021

I've tested with both one and eth addresses and they work interchangeably everywhere.

@givp givp requested a review from polymorpher June 30, 2021 00:46
@givp givp linked an issue Jun 30, 2021 that may be closed by this pull request
Comment thread code/client/src/pages/Create.jsx Outdated
return
}
// Check for one address
let verifiedLastResortAddress = lastResortAddress
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread code/client/src/pages/Show.jsx Outdated
const neighbor = neighbors[0]

// Check for one address
let verifiedTransferTo = transferTo
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be merged with above using utility function

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For sure, too much duplication. Will fix.

@polymorpher
Copy link
Copy Markdown
Owner

Screen.Recording.2021-06-29.at.6.19.17.PM.mov

@givp
Copy link
Copy Markdown
Collaborator Author

givp commented Jun 30, 2021

@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 transferAmount check wasn't working since it's a BN so I fixed that here.

Comment thread code/client/src/pages/Create.jsx Outdated
lifespan: duration / WalletConstants.interval,
slotSize,
lastResortAddress,
validLastResortAddress,
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work because it would change the key of the object.

Comment thread code/client/src/pages/Create.jsx Outdated
duration,
effectiveTime,
lastResortAddress,
validLastResortAddress,
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue as above

<Space direction='vertical' size='small'>
<Hint>Wallet Address</Hint>
<Text>{address}</Text>
<Text>{address && getAddress(address).bech32}</Text>
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Owner

@polymorpher polymorpher Jun 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

const wallets = useSelector(state => state.wallet.wallets)
const match = useRouteMatch(Paths.show)
const { address, action } = match ? match.params : {}
const oneAddress = getAddress(address).bech32
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Comment thread code/client/src/util.js Outdated
return { balance, formatted, fiat, fiatFormatted, valid: true }
},

validateAddress: (address) => {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Comment thread code/client/src/pages/Show.jsx Outdated
const neighbor = neighbors[0]

// Ensure valid address for both 0x and one1 formats
const validAddress = util.validateAddress(transferTo)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

normalizedAddress?

Comment thread code/client/src/pages/Create.jsx Outdated
}

// Ensure valid address for both 0x and one1 formats
const validLastResortAddress = util.validateAddress(lastResortAddress)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

normalizedAddress?

// Ensure valid address for both 0x and one1 formats
const validLastResortAddress = util.validateAddress(lastResortAddress)
if (!validLastResortAddress) {
return
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@givp
Copy link
Copy Markdown
Collaborator Author

givp commented Jun 30, 2021

@polymorpher sorry for the confusion. util.validateAddress name is confusing as you suggested. It doesn't just validate, it confirms the format of one1 and 0x addresses but always returns ETH format. So normalizedAddress makes more sense. I'll change that. But the relayer calls are not affected. I'm still sending 0x addresses for all transactions, even if the user enters an one1 address.

In terms of console errors, I will add them in the function but was trying to avoid console noise .

@givp
Copy link
Copy Markdown
Collaborator Author

givp commented Jun 30, 2021

This should be in a good place to merge. I'm going to revisit the getAddress speed issue once I've wrapped up some of the other tasks.

Comment thread code/client/src/pages/Create.jsx Outdated
lifespan: duration / WalletConstants.interval,
slotSize,
lastResortAddress,
normalizedAddress,
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still an issue. The expected object key is lastResortAddress

Comment thread code/client/src/pages/Create.jsx Outdated
duration,
effectiveTime,
lastResortAddress,
normalizedAddress,
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah apologies, fixing.

@polymorpher
Copy link
Copy Markdown
Owner

I made a quick update on separation of error handling logic, and simplified the normalization: d9a92a5

@polymorpher polymorpher merged commit 88ac339 into master Jul 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2. Support one1.... style address as recovery address

2 participants