Skip to content

Conversation

@brad-decker
Copy link
Contributor

@brad-decker brad-decker commented Jul 1, 2021

This makes it such that the state tree of the Gas Fee Controller is variable, but also known, and you can use state.gasEstimateType === GAS_ESTIMATE_TYPES.FEE_MARKET and the like to put Typescript in the branch that has the gasEstimate shape typed. This removes the need to have helper methods to check for object structure to identify type.

This also has a 'NONE' state that can be used to identify states in which we can rely on no values (still loading values)

never
>;
state?: Partial<GasFeeState>;
state?: GasFeeState;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

State is now very much required to have all pieces to write it, but that doesn't always have to be true. if in the future one of the state keys is optional in all shapes, we can add it to the shapes with the ?: syntax so that partial spreads are supported, but this would still be GasFeeState versus Partial

@brad-decker brad-decker marked this pull request as ready for review July 1, 2021 20:45
@brad-decker brad-decker requested a review from a team as a code owner July 1, 2021 20:45
estimatedGasFeeTimeBounds: { persist: true, anonymous: false },
gasEstimateType: { persist: true, anonymous: false },
};

Copy link
Contributor

Choose a reason for hiding this comment

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

So, just to confirm I understand: state will always have a estimatedGasFeeTimeBounds property, but it will be an empty object unless isEIP1559Compatible is true?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, all fields are always present, but their shape is determined by the value of gasEstimateType.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

and the fee-market value will only be set if we get a successful response from the EIP1559 gas estimate API.


export type unknownString = 'unknown';

export type FeeMarketEstimateType = 'fee-market';
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be helpful to add a brief comment here that explains that the FeeMarketEstimateType is the type used for EIP1559 compatible estimates

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@danjm added comments to each type. de81a41

@brad-decker brad-decker merged commit 9d5096a into draft-gasfee-controller Jul 2, 2021
@brad-decker brad-decker deleted the update-types branch July 2, 2021 15:28
brad-decker added a commit that referenced this pull request Jul 2, 2021
brad-decker added a commit that referenced this pull request Jul 7, 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.

4 participants