Skip to content

Commit

Permalink
Merge branch 'master' into brody/test-swaps-flow
Browse files Browse the repository at this point in the history
  • Loading branch information
BrodyHughes authored Sep 13, 2024
2 parents e66712a + 09bb6aa commit 59e1dc1
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 21 deletions.
100 changes: 98 additions & 2 deletions e2e/serial/swap/1_swapFlow1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -567,9 +567,105 @@ describe('Go through swaps settings and execute a swap', () => {
driver,
});
expect(assetToSellInputText).toBe('1');

await delayTime('very-long');

});
it('should be able to filter assets to buy by network', async () => {
// OP
await findElementByTestIdAndClick({
id: `${SWAP_VARIABLES.WBTC_MAINNET_ID}-token-to-buy-token-input-remove`,
driver,
});
await findElementByTestIdAndClick({
id: 'token-to-buy-networks-trigger',
driver,
});
await findElementByTestIdAndClick({
id: `switch-network-item-${ChainId.optimism}`,
driver,
});
await typeOnTextInput({
id: 'token-to-buy-search-token-input',
driver,
text: 'op',
});
await delayTime('long');
await findElementByTestIdAndClick({
id: `${SWAP_VARIABLES.OP_OPTIMISM_ID}-favorites-token-to-buy-row`,
driver,
});
// POLYGON
await findElementByTestIdAndClick({
id: `${SWAP_VARIABLES.OP_OPTIMISM_ID}-token-to-buy-token-input-remove`,
driver,
});
await findElementByTestIdAndClick({
id: 'token-to-buy-networks-trigger',
driver,
});
await findElementByTestIdAndClick({
id: `switch-network-item-${ChainId.polygon}`,
driver,
});
await typeOnTextInput({
id: 'token-to-buy-search-token-input',
driver,
text: 'pol',
});
await delayTime('long');
await findElementByTestIdAndClick({
id: `${SWAP_VARIABLES.MATIC_POLYGON_ID}-favorites-token-to-buy-row`,
driver,
});
// ARBITRUM
await findElementByTestIdAndClick({
id: `${SWAP_VARIABLES.MATIC_POLYGON_ID}-token-to-buy-token-input-remove`,
driver,
});
await findElementByTestIdAndClick({
id: 'token-to-buy-networks-trigger',
driver,
});
await findElementByTestIdAndClick({
id: `switch-network-item-${ChainId.arbitrum}`,
driver,
});
await typeOnTextInput({
id: 'token-to-buy-search-token-input',
driver,
text: 'gmx',
});
await delayTime('long');
await findElementByTestIdAndClick({
id: `${SWAP_VARIABLES.GMX_ARBITRUM_ID}-verified-token-to-buy-row`,
driver,
});
// BNB
await findElementByTestIdAndClick({
id: `${SWAP_VARIABLES.GMX_ARBITRUM_ID}-token-to-buy-token-input-remove`,
driver,
});
await findElementByTestIdAndClick({
id: 'token-to-buy-networks-trigger',
driver,
});
await findElementByTestIdAndClick({
id: `switch-network-item-${ChainId.bsc}`,
driver,
});
await typeOnTextInput({
id: 'token-to-buy-search-token-input',
driver,
text: 'uni',
});
await delayTime('long');
await findElementByTestIdAndClick({
id: `${SWAP_VARIABLES.UNI_BNB_ID}-verified-token-to-buy-row`,
driver,
});
await findElementByTestIdAndClick({
id: `${SWAP_VARIABLES.UNI_BNB_ID}-token-to-buy-token-input-remove`,
driver,
});
const assetToBuyInputText = await getTextFromTextInput({
id: `${SWAP_VARIABLES.WBTC_MAINNET_ID}-token-to-buy-swap-token-input-swap-input-mask`,
driver,
Expand Down
9 changes: 7 additions & 2 deletions lavamoat/build-webpack/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1184,8 +1184,13 @@
"define": true
},
"packages": {
"jest>@jest/core>jest-snapshot>@babel/traverse>@babel/generator>@jridgewell/trace-mapping>@jridgewell/sourcemap-codec": true,
"webpack>terser-webpack-plugin>@jridgewell/trace-mapping>@jridgewell/resolve-uri": true
"jest>@jest/core>jest-snapshot>@babel/traverse>@babel/generator>@jridgewell/trace-mapping>@jridgewell/resolve-uri": true,
"jest>@jest/core>jest-snapshot>@babel/traverse>@babel/generator>@jridgewell/trace-mapping>@jridgewell/sourcemap-codec": true
}
},
"jest>@jest/core>jest-snapshot>@babel/traverse>@babel/generator>@jridgewell/trace-mapping>@jridgewell/resolve-uri": {
"globals": {
"define": true
}
},
"jest>@jest/core>jest-snapshot>@babel/traverse>@babel/generator>@jridgewell/trace-mapping>@jridgewell/sourcemap-codec": {
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,9 @@
"braces": "3.0.3",
"ws": "8.17.1",
"micromatch": "4.0.8",
"webpack": "5.94.0"
"webpack": "5.94.0",
"path-to-regexp": "6.3.0",
"dset": "3.1.4"
},
"lavamoat": {
"allowScripts": {
Expand Down
19 changes: 13 additions & 6 deletions src/core/utils/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,10 @@ const parseFees = (
const feeValue = FixedNumber.from(
formatUnits(BigInt(fee.value) + rollupFee, nativeAssetDecimals),
);
const feePrice = FixedNumber.fromString(fee.price.toString());
const feePrice = FixedNumber.fromString(
fee.price.toFixed(nativeAssetDecimals).toString(),
nativeAssetDecimals,
);

return {
fee: feeValue.toString(),
Expand Down Expand Up @@ -278,19 +281,23 @@ export function parseTransaction({
const description = getDescription(asset, type, meta);

const nativeAsset = changes.find((change) => change?.asset.isNativeAsset);
const nativeAssetPrice = FixedNumber.fromString(
nativeAsset?.price?.toString() || '0',
);

const value = FixedNumber.fromValue(
BigNumber.from(nativeAsset?.value || 0),
nativeAsset?.asset.decimals || 0,
);

const valueInNative = value.mulUnsafe(nativeAssetPrice).toString();

const nativeAssetDecimals = 18; // we only support networks with 18 decimals native assets rn, backend will change when we support more

const nativeAssetPrice = FixedNumber.fromString(
typeof nativeAsset?.price === 'number'
? nativeAsset.price.toFixed(nativeAssetDecimals).toString()
: '0',
nativeAssetDecimals,
);

const valueInNative = value.mulUnsafe(nativeAssetPrice).toString();

const { feeInNative, ...fee } = parseFees(tx.fee, nativeAssetDecimals);

const native = {
Expand Down
8 changes: 6 additions & 2 deletions src/entries/popup/pages/swap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,9 @@ export function Swap({ bridge = false }: { bridge?: boolean }) {
}
setAssetToSellInputValue={setAssetToSellInputValue}
inputRef={assetToSellInputRef}
openDropdownOnMount={inputToOpenOnMount === 'sell'}
openDropdownOnMount={
inputToOpenOnMount === 'sell' && !assetToSell
}
assetToSellNativeValue={assetToSellNativeValue}
assetToSellNativeDisplay={assetToSellNativeDisplay}
setAssetToSellInputNativeValue={
Expand Down Expand Up @@ -881,7 +883,9 @@ export function Swap({ bridge = false }: { bridge?: boolean }) {
assetToSellValue={assetToSellValue}
setAssetToBuyInputValue={setAssetToBuyInputValue}
inputRef={assetToBuyInputRef}
openDropdownOnMount={inputToOpenOnMount === 'buy'}
openDropdownOnMount={
inputToOpenOnMount === 'buy' && !assetToBuy
}
inputDisabled={isCrosschainSwap}
assetToBuyNativeDisplay={assetToBuyNativeDisplay}
assetToSellNativeDisplay={assetToSellNativeDisplay}
Expand Down
16 changes: 8 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8231,10 +8231,10 @@ dotenv@^8.2.0:
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-8.6.0.tgz#061af664d19f7f4d8fc6e4ff9b584ce237adcb8b"
integrity sha512-IrPdXQsk2BbzvCBGBOTmmSH5SodmqZNt4ERAZDmW4CT+tL8VtvinqywuANaFu4bOMWki16nqf0e4oC0QIaDr/g==

dset@^3.1.2:
version "3.1.3"
resolved "https://registry.yarnpkg.com/dset/-/dset-3.1.3.tgz#c194147f159841148e8e34ca41f638556d9542d2"
integrity sha512-20TuZZHCEZ2O71q9/+8BwKwZ0QtD9D8ObhrihJPr+vLLYlSuAU3/zL4cSlgbfeoGHTjCSJBa7NGcrF9/Bx/WJQ==
dset@3.1.4, dset@^3.1.2:
version "3.1.4"
resolved "https://registry.yarnpkg.com/dset/-/dset-3.1.4.tgz#f8eaf5f023f068a036d08cd07dc9ffb7d0065248"
integrity sha512-2QF/g9/zTaPDc3BjNcVTGoBbXBgYfMTTceLaYcFJ/W9kggFUkhxD/hMEeuLKbugyef9SqAx8cpgwlIP/jinUTA==

dtrace-provider@~0.8:
version "0.8.8"
Expand Down Expand Up @@ -14026,10 +14026,10 @@ path-scurry@^1.6.1:
lru-cache "^9.1.1 || ^10.0.0"
minipass "^5.0.0 || ^6.0.2 || ^7.0.0"

path-to-regexp@^6.2.0:
version "6.2.1"
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-6.2.1.tgz#d54934d6798eb9e5ef14e7af7962c945906918e5"
integrity sha512-JLyh7xT1kizaEvcaXOQwOc2/Yhw6KZOvPf1S8401UyLk86CU79LN3vl7ztXGm/pZ+YjoyAJ4rxmHwbkBXJX+yw==
path-to-regexp@6.3.0, path-to-regexp@^6.2.0:
version "6.3.0"
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-6.3.0.tgz#2b6a26a337737a8e1416f9272ed0766b1c0389f4"
integrity sha512-Yhpw4T9C6hPpgPeA28us07OJeqZ5EzQTkbfwuhsUg0c237RomFoETJgmp2sa3F/41gfLE6G5cqcYwznmeEeOlQ==

path-type@^4.0.0:
version "4.0.0"
Expand Down

0 comments on commit 59e1dc1

Please sign in to comment.