Skip to content

Commit

Permalink
Merge pull request #46 from DODOEX/hotfix/allowance
Browse files Browse the repository at this point in the history
fix: allowance error
  • Loading branch information
junjieit authored Nov 13, 2023
2 parents 25d0c7d + 57b42d7 commit 1b632da
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 21 deletions.
2 changes: 1 addition & 1 deletion example/angular-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@angular/platform-browser": "^15.1.0",
"@angular/platform-browser-dynamic": "^15.1.0",
"@angular/router": "^15.1.0",
"@dodoex/widgets": "^2.5.3",
"@dodoex/widgets": "^2.5.4",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.12.0"
Expand Down
2 changes: 1 addition & 1 deletion example/js-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"start:prod": "yarn run build && node express.js"
},
"dependencies": {
"@dodoex/widgets": "^2.5.3"
"@dodoex/widgets": "^2.5.4"
},
"devDependencies": {
"express": "^4.18.1",
Expand Down
2 changes: 1 addition & 1 deletion example/react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@dodoex/widgets": "^2.5.3",
"@dodoex/widgets": "^2.5.4",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/doc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"build": "build-storybook"
},
"peerDependencies": {
"@dodoex/widgets": "^2.5.3"
"@dodoex/widgets": "^2.5.4"
},
"dependencies": {
"@babel/runtime": "^7.17.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/dodoex-widgets/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dodoex/widgets",
"version": "2.5.3",
"version": "2.5.4",
"description": "DODO Widgets",
"source": "src/index.tsx",
"types": "dist/src/index.d.ts",
Expand Down
27 changes: 11 additions & 16 deletions packages/dodoex-widgets/src/hooks/Token/useGetAllowance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,33 @@ import contractConfig from '../contract/contractConfig';
export default function useGetAllowance(
contract: string | null,
): (token: TokenInfo) => BigNumber | null {
const { account } = useWeb3React();
const chainId = useSelector(getDefaultChainId);
const accountBalances = useSelector(getAccountBalances);
const EtherToken = useMemo(() => basicTokenMap[chainId], [chainId]);
const currentContractConfig = useMemo(
() => contractConfig[chainId as ChainId],
[chainId],
const { account, chainId: currentChainId } = useWeb3React();
const defaultChainId = useSelector(getDefaultChainId);
const chainId = useMemo(
() => (currentChainId ?? defaultChainId) as ChainId,
[currentChainId, defaultChainId],
);
const accountBalances = useSelector(getAccountBalances);

const getAllowance = useCallback(
(token: TokenInfo) => {
if (!account || !contract) return null;
const tokenChainId: ChainId = token.chainId ?? chainId;
const EtherToken = basicTokenMap[tokenChainId];
if (
token.symbol === EtherToken.symbol &&
isSameAddress(token.address, EtherToken.address)
)
return new BigNumber(BIG_ALLOWANCE);
const { DODO_APPROVE: dodoApproveAddress } = currentContractConfig || {};
const { DODO_APPROVE: dodoApproveAddress } =
contractConfig[tokenChainId as ChainId] || {};
// need fetch from fetchTokenAllowance
if (contract !== dodoApproveAddress) return null;
const allowances =
accountBalances?.[token.address.toLowerCase()]?.tokenAllowances;
return allowances ?? null;
},
[
account,
contract,
EtherToken.symbol,
EtherToken.address,
accountBalances,
currentContractConfig,
],
[account, chainId, contract, accountBalances],
);

return getAllowance;
Expand Down

1 comment on commit 1b632da

@vercel
Copy link

@vercel vercel bot commented on 1b632da Nov 13, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

widgets-doc – ./

widgets-doc-dodoex-io.vercel.app
dodo-widgets-doc.vercel.app
widgets-doc-git-main-dodoex-io.vercel.app

Please sign in to comment.