Skip to content

Commit

Permalink
Merge pull request #23 from OriginProtocol/feat/replace-lodash
Browse files Browse the repository at this point in the history
feat: replace lodash with ramda, update usages
  • Loading branch information
toniocodo authored Sep 6, 2023
2 parents dd44c37 + f99872c commit b5e6b41
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 35 deletions.
7 changes: 3 additions & 4 deletions libs/defi/oeth/src/components/Swap/GasPopover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
Stack,
useTheme,
} from '@mui/material';
import { isNumber } from 'lodash';
import { useIntl } from 'react-intl';

import type { Theme } from '@mui/material';
Expand Down Expand Up @@ -108,9 +107,9 @@ export function GasPopover({ gasPrice, onPriceToleranceChange }: Props) {
},
}}
onChange={debounce((e) => {
if (isNumber(parseFloat(e.target.value))) {
setPriceTolerance(e.target.value);
}
try {
setPriceTolerance(parseFloat(e.target.value));
} catch {}
}, 300)}
endAdornment={
<InputAdornment
Expand Down
22 changes: 8 additions & 14 deletions libs/defi/oeth/src/components/Swap/Swap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
SwapCard,
TokenListModal,
} from '@origin/shared/components';
import random from 'lodash/random';
import { useIntl } from 'react-intl';

import { GasPopover } from './GasPopover';
Expand Down Expand Up @@ -47,12 +46,12 @@ export function Swap() {
baseToken: {
...prev.baseToken,
quantity: number,
value: number * random(18500, 19000, true),
value: number * 18500,
},
exchangeCurrency: {
...prev.exchangeCurrency,
quantity: number * random(number - 0.5, number, true),
value: number * random(18500, 19000, true),
quantity: number * number - 0.5,
value: number * 19000,
},
}));
}
Expand All @@ -62,14 +61,12 @@ export function Swap() {
baseToken: {
...prev.exchangeCurrency,
quantity: prev.baseToken.quantity,
value: prev.baseToken.quantity * random(18500, 19000),
value: prev.baseToken.quantity * 18500,
},
exchangeCurrency: {
...prev.baseToken,
quantity:
prev.baseToken.quantity *
random(prev.baseToken.quantity - 0.5, prev.baseToken.quantity, true),
value: prev.baseToken.quantity * random(18500, 19000, true),
quantity: prev.baseToken.quantity * (prev.baseToken.quantity - 0.5),
value: prev.baseToken.quantity * 19000,
},
}));
}
Expand Down Expand Up @@ -115,11 +112,8 @@ export function Swap() {
setValues((prev) => ({
...prev,
exchangeCurrency: {
value: prev.baseToken.quantity * random(18500, 19000, true),
quantity: random(
prev.baseToken.quantity - 0.5,
prev.baseToken.quantity,
),
value: prev.baseToken.quantity * 18500,
quantity: prev.baseToken.quantity - 0.5,
abbreviation: option.name,
imgSrc: option.imgSrc,
},
Expand Down
7 changes: 2 additions & 5 deletions libs/defi/oeth/src/components/Wrap/SwapWrap.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useState } from 'react';

import { SwapCard } from '@origin/shared/components';
import random from 'lodash/random';
import { useIntl } from 'react-intl';

export function PortfolioSwap() {
Expand All @@ -28,7 +27,7 @@ export function PortfolioSwap() {
},
exchangeCurrency: {
...prev.exchangeCurrency,
quantity: number * random(number - 0.5, number, true),
quantity: number * number - 0.5,
},
}));
}
Expand All @@ -41,9 +40,7 @@ export function PortfolioSwap() {
},
exchangeCurrency: {
...prev.baseToken,
quantity:
prev.baseToken.quantity *
random(prev.baseToken.quantity - 0.5, prev.baseToken.quantity, true),
quantity: prev.baseToken.quantity * prev.baseToken.quantity - 0.5,
},
}));
}
Expand Down
7 changes: 2 additions & 5 deletions libs/oeth/wrap/src/components/SwapWrap.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useState } from 'react';

import { SwapCard } from '@origin/shared/components';
import random from 'lodash/random';
import { useIntl } from 'react-intl';

export function PortfolioSwap() {
Expand All @@ -28,7 +27,7 @@ export function PortfolioSwap() {
},
exchangeCurrency: {
...prev.exchangeCurrency,
quantity: number * random(number - 0.5, number, true),
quantity: number * number - 0.5,
},
}));
}
Expand All @@ -41,9 +40,7 @@ export function PortfolioSwap() {
},
exchangeCurrency: {
...prev.baseToken,
quantity:
prev.baseToken.quantity *
random(prev.baseToken.quantity - 0.5, prev.baseToken.quantity, true),
quantity: prev.baseToken.quantity * prev.baseToken.quantity - 0.5,
},
}));
}
Expand Down
3 changes: 1 addition & 2 deletions libs/shared/components/src/Cards/SwapCard/TokenListModal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Dialog, MenuList } from '@mui/material';
import { eq } from 'lodash';

import { TokenListItem } from './TokenListItem';

Expand Down Expand Up @@ -66,7 +65,7 @@ export function TokenListModal({
onSelection(option);
handleClose();
}}
selected={eq(selected, option.abbreviation)}
selected={selected === option.abbreviation}
/>
))}
</MenuList>
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"axios": "^1.4.0",
"graphql": "^16.8.0",
"immer": "^10.0.2",
"lodash": "^4.17.21",
"ramda": "^0.29.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-intl": "^6.4.4",
Expand Down Expand Up @@ -59,6 +59,7 @@
"@testing-library/react": "14.0.0",
"@types/lodash": "^4.14.196",
"@types/node": "18.14.2",
"@types/ramda": "^0.29.3",
"@types/react": "18.2.18",
"@types/react-dom": "18.2.7",
"@typescript-eslint/eslint-plugin": "^6.3.0",
Expand Down
27 changes: 23 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b5e6b41

Please sign in to comment.