Conversation
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
Builds ready [daa8a2a]
Page Load Metrics (755 ± 53 ms)
|
| txMeta.txParams.from, | ||
| txMeta.destinationTokenDecimals, | ||
| approvalTxMeta, | ||
| chainId, |
There was a problem hiding this comment.
txMeta should now include the chainId for the transaction. I think this is safer than getting the current chainId if in the event that the network switches while this flow is in flight.
|
|
||
| const METASWAP_ETH_API_HOST = 'https://api.metaswap.codefi.network'; | ||
|
|
||
| const SWAPS_TESTNET_CHAIN_ID = '0x539'; |
There was a problem hiding this comment.
what prevents a local ganache that doesn't fork mainnet or have the ability to interact with swaps from using this API?
There was a problem hiding this comment.
hmmm.... good point... nothing prevents that
There was a problem hiding this comment.
I think that's okay though... no risk of fund loss, and it is only developers using local ganache
| return ( | ||
| txParams?.to === recipientAddress || | ||
| (txParams?.to === SWAPS_CONTRACT_ADDRESS && | ||
| (txParams?.to === SWAPS_CHAINID_CONTRACT_ADDRESS_MAP[chainId] && |
There was a problem hiding this comment.
[Q] It's been a while since I viewed this code, and regret not having added documentation to it when I touched it last. If I understand correctly this is to help filter out transactions that aren't to the specified token. So when we're on, let's say DAI's asset page, we only see transactions interacting with DAI's contract address and swaps's contract address as long as the swap interacted with DAI's contract address?
I was able to walk through that logic in the current develop branch without the addition of chainId. If my assumption is correct it might be worth documenting the filter logic so that we don't lose the intent of these filters as logic changes.
There was a problem hiding this comment.
So when we're on, let's say DAI's asset page, we only see transactions interacting with DAI's contract address and swaps's contract address as long as the swap interacted with DAI's contract address?
yes, exactly
| let swapsFeatureIsLive = false; | ||
| try { | ||
| swapsFeatureIsLive = await fetchSwapsFeatureLiveness(); | ||
| swapsFeatureIsLive = await fetchSwapsFeatureLiveness(chainId); |
There was a problem hiding this comment.
I just noticed that this method is in a utility file that exists in pages/swaps/swap.util but is also used in the background. Could we move these shared utility methods into shared/ ?
There was a problem hiding this comment.
I have started this on a separate branch that I will PR after the present PR is merged https://github.com/MetaMask/metamask-extension/pull/new/swaps-utils-shared-directory
| export const signAndSendTransactions = (history, metaMetricsEvent) => { | ||
| return async (dispatch, getState) => { | ||
| const state = getState(); | ||
| const chainId = getCurrentChainId(state); |
There was a problem hiding this comment.
[Q] would it be worth it to extract fetchSwapsFeatureLiveness into its own dispatch action / thunk so that anywhere we call it in the UI code it can be responsible for getting chainid itself? Seems like it'd cut down on repetition.
There was a problem hiding this comment.
I have made this change on another branch that I will PR once this one is merged: https://github.com/MetaMask/metamask-extension/pull/new/fetchswapsfeatureliveness-thunk
| const conversionRate = useSelector(getConversionRate); | ||
| const currentCurrency = useSelector(getCurrentCurrency); | ||
|
|
||
| const defaultTokenSymbol = SWAPS_CHAINID_DEFAULT_TOKEN_MAP[chainId].symbol; |
There was a problem hiding this comment.
[Q] Do you expect defaultTokenSymbol to be different than defaultSwapsToken.symbol here? Seems like getSwapsDefaultToken returns this same object?
There was a problem hiding this comment.
No, I have addressed this as part of 04e7af6
|
@danjm the changes to tests will need to be applied onto the relocated versions that are now colocated with the code. Sorry for the inconvenience 🙏🏻 |
… comparisons in build-quote.js
daa8a2a to
04e7af6
Compare
|
@brad-decker This has been rebased and test related conflicts handled. Note that there is one commit of updates that I made that are not directly from review: b20c98f "Create util method for comparison of token addresses/symbols to default swaps token" |
Builds ready [04e7af6]
Page Load Metrics (600 ± 15 ms)
|
| // If the swap is from the selected chain's default token, subtract | ||
| // the sourceAmount from the total cost. Otherwise, the total fee | ||
| // is simply trade.value plus gas fees. | ||
| const ethFee = isSwapsDefaultTokenAddress(sourceToken, chainId) |
There was a problem hiding this comment.
nit: Do we want a more descriptive var name here? defaultTokenFee or transactionTokenFee? Just a thought. Naming is hard though.
There was a problem hiding this comment.
This is a good point. There actually are a bunch of variables related to swaps with 'eth' in the name that need to be updated. I think "chainCurrency" is a good alternative to "eth". Because the changes are so extensive, I'd like to do this in a separate/future PR, to minimize chance of missing bugs. I have started the work on this branch https://github.com/MetaMask/metamask-extension/pull/new/eth-naming-updates-swaps-alt-nets
| txMeta.txParams.from, | ||
| txMeta.destinationTokenDecimals, | ||
| approvalTxMeta, | ||
| txMeta.chainId, |
There was a problem hiding this comment.
Looking at the number of arguments going to this function, we're going to want to shift to passing an object sooon.
There was a problem hiding this comment.
I have put this changed on another branch and will PR it once this PR is merged https://github.com/MetaMask/metamask-extension/pull/new/getSwapsTokensReceivedFromTxMeta-object-param
| ) => { | ||
| return ({ initialTransaction: { txParams } }) => { | ||
| return ( | ||
| txParams?.to === recipientAddress || |
There was a problem hiding this comment.
Should we do a check here for:
if (!txParams) { return ____ }
Might be shorter than a bunch of ?. optional chaining checks.
There was a problem hiding this comment.
Given our lint rules, this would have to be over 3 lines, meanwhile two other lines just become shorter by a single character. So might be best to leave as is, unless adding the explicit if check and return is a readability improvement?
| toToken; | ||
| const toTokenIsNotEth = | ||
| const toTokenIsNotDefault = | ||
| selectedToToken?.address && |
There was a problem hiding this comment.
I don't think we need this check because isSwapsDefaultTokenAddress inherently would return false
There was a problem hiding this comment.
right, but line 137 is "**!**isSwapsDefaultTokenAddress(selectedToToken?.address, chainId)", so when selectedToToken?.address is a falsy value, toTokenIsNotDefault is true, because of the !
|
I've made a few minor suggestions. Really well done, can't wait to use this! |
This PR allows swaps to work on local test networks with chainId of
0x539. It also abstracts swaps logic dependent on chainId in a way that will allow us to add support for future networks simply by editing theshared/constants/swaps.jsfile.Video demo of swaps working on a local test network:
swap-testnet-support.mp4