Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/75 address input for known address #79

Merged
merged 8 commits into from
Aug 16, 2021

Conversation

haolinj
Copy link
Collaborator

@haolinj haolinj commented Aug 15, 2021

No description provided.

@@ -571,9 +570,8 @@ const Show = () => {
<Label><Hint>To</Hint></Label>
<AddressInput
addressValue={transferTo}
setAddressCallback={(value) => setTransferTo(value)}
setAddressCallback={setTransferTo}
Copy link
Owner

Choose a reason for hiding this comment

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

Would that cause a warning "modifying another component's state inside a component"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I haven't seen this warning. But it is a call back to set the value in this component, and this component's value is being supplied as prop to the AddressInput component.

@polymorpher
Copy link
Owner

polymorpher commented Aug 16, 2021

Looks good, but I am getting

react-dom.development.js:67 Warning: Maximum update depth exceeded. This can happen when a component calls setState inside useEffect, but useEffect either doesn't have a dependency array, or one of the dependencies changes on every render.

@haolinj
Copy link
Collaborator Author

haolinj commented Aug 16, 2021

Looks good, but I am getting

react-dom.development.js:67 Warning: Maximum update depth exceeded. This can happen when a component calls setState inside useEffect, but useEffect either doesn't have a dependency array, or one of the dependencies changes on every render.

I will double check and fix it.


return (
<Select.Option key={index} value={util.safeOneAddress(knownAddress.address)}>
<Space size='small' align='baseline'>
Copy link
Owner

Choose a reason for hiding this comment

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

justify='spaceBetween'? Looks weird when checkmarks are unaligned

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point, I did not what to set there.

Copy link
Owner

Choose a reason for hiding this comment

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

actually it will need a Row and it is space-between

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I thought it would be Grid layout. I will play around it and try to make it align.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Replaced with Grid layout and removed the check button, replaced with text button that spans the whole Col space.

@polymorpher
Copy link
Owner

Looks good, but I am getting
react-dom.development.js:67 Warning: Maximum update depth exceeded. This can happen when a component calls setState inside useEffect, but useEffect either doesn't have a dependency array, or one of the dependencies changes on every render.

I will double check and fix it.

It is reporting setAddressCallback is changing on every render. Since it is a state-setter, and the function is quite large, it might not be a good idea to have that in the dependency array

function dispatchAction(fiber, queue, action) {
  {
    if (typeof arguments[3] === 'function') {
      error("State updates from the useState() and useReducer() Hooks don't support the " + 'second callback argument. To execute a side effect after ' + 'rendering, declare it in the component body with useEffect().');
    }
  }

  var eventTime = requestEventTime();
  var lane = requestUpdateLane(fiber);
  var update = {
    lane: lane,
    action: action,
    eagerReducer: null,
    eagerState: null,
    next: null
  }; // Append the update to the end of the list.

  var pending = queue.pending;

  if (pending === null) {
    // This is the first update. Create a circular list.
    update.next = update;
  } else {
    update.next = pending.next;
    pending.next = update;
  }

  queue.pending = update;
  var alternate = fiber.alternate;

  if (fiber === currentlyRenderingFiber$1 || alternate !== null && alternate === currentlyRenderingFiber$1) {
    // This is a render phase update. Stash it in a lazily-created map of
    // queue -> linked list of updates. After this render pass, we'll restart
    // and apply the stashed updates on top of the work-in-progress hook.
    didScheduleRenderPhaseUpdateDuringThisPass = didScheduleRenderPhaseUpdate = true;
  } else {
    if (fiber.lanes === NoLanes && (alternate === null || alternate.lanes === NoLanes)) {
      // The queue is currently empty, which means we can eagerly compute the
      // next state before entering the render phase. If the new state is the
      // same as the current state, we may be able to bail out entirely.
      var lastRenderedReducer = queue.lastRenderedReducer;

      if (lastRenderedReducer !== null) {
        var prevDispatcher;

        {
          prevDispatcher = ReactCurrentDispatcher$1.current;
          ReactCurrentDispatcher$1.current = InvalidNestedHooksDispatcherOnUpdateInDEV;
        }

        try {
          var currentState = queue.lastRenderedState;
          var eagerState = lastRenderedReducer(currentState, action); // Stash the eagerly computed state, and the reducer used to compute
          // it, on the update object. If the reducer hasn't changed by the
          // time we enter the render phase, then the eager state can be used
          // without calling the reducer again.

          update.eagerReducer = lastRenderedReducer;
          update.eagerState = eagerState;

          if (objectIs(eagerState, currentState)) {
            // Fast path. We can bail out without scheduling React to re-render.
            // It's still possible that we'll need to rebase this update later,
            // if the component re-renders for a different reason and by that
            // time the reducer has changed.
            return;
          }
        } catch (error) {// Suppress the error. It will throw again in the render phase.
        } finally {
          {
            ReactCurrentDispatcher$1.current = prevDispatcher;
          }
        }
      }
    }

    {
      // $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
      if ('undefined' !== typeof jest) {
        warnIfNotScopedWithMatchingAct(fiber);
        warnIfNotCurrentlyActingUpdatesInDev(fiber);
      }
    }

    scheduleUpdateOnFiber(fiber, lane, eventTime);
  }
}

numUsed: 0
}))
})
}, [knownAddresses, wallets, dispatch])
Copy link
Owner

Choose a reason for hiding this comment

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

Turns out the issue is with this dependency knownAddresses. There might be some invalid wallets left in the user's state (e.g. my browser). If the invalid wallet has no valid address, it would become part of walletsNotInKnownAddresses and sent to dispatch for setKnownAddress. The reducer in setKnownAddress can't add that invalid wallet's address to known addresses, but would create a new object for knownAddresses, therefore trigger another useEffect here, hence causing an infinite loop

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've made this effect run once when the component load.

showSelectManualInputAddress
? (
<Select.Option key='address-value' value={addressValue.value}>
<Space size='small' align='baseline'>
Copy link
Owner

Choose a reason for hiding this comment

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

onClick needs to be on Space, otherwise the function won't trigger

block
type='text'
style={{ textAlign: 'left' }}
onClick={() => onSelectAddress({ value: addr, label: longAddressLabel, key: index })}
Copy link
Owner

Choose a reason for hiding this comment

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

same as below

<Space size='small' align='baseline'>
{addressValue.value}
<Button type='text' onClick={() => onSelectAddress(addressValue)}>
<CheckOutlined />
Copy link
Owner

Choose a reason for hiding this comment

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

no longer needed

<Space size='small' align='baseline'>
I want to do this later in my wallet
<Button type='text' onClick={() => setLastResortAddress({ value: '', label: 'I want to do this later in my wallet' })}>
<CheckOutlined />
Copy link
Owner

Choose a reason for hiding this comment

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

no longer needed, but since we are removing this option altogether - you can update it in the next PR

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, forgot to remove it, will remove and push.

extraSelectOptions={
[
<Select.Option key='later' value=''>
<Space size='small' align='baseline'>
Copy link
Owner

Choose a reason for hiding this comment

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

same as above

@polymorpher
Copy link
Owner

Looks good

@polymorpher polymorpher merged commit 726ec17 into master Aug 16, 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.

None yet

2 participants