Skip to content

Commit

Permalink
v5.1.2
Browse files Browse the repository at this point in the history
v5.1.2
  • Loading branch information
platschi authored Nov 20, 2022
2 parents c019595 + cdd8c03 commit 6e384e0
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 38 deletions.
10 changes: 6 additions & 4 deletions hooks/useStakingData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ const useStakingData = () => {
const [kwentaAllowance, setKwentaAllowance] = useState(zeroBN);
const [veKwentaBalance, setVEKwentaBalance] = useState(zeroBN);
const [veKwentaAllowance, setVEKwentaAllowance] = useState(zeroBN);
const [totalVestable, setTotalVestable] = useState(0);

const { refetch: resetStakingState } = useContractReads({
contracts: [
Expand Down Expand Up @@ -255,13 +256,14 @@ const useStakingData = () => {
escrowRows[index].vestable = Number(d?.quantity / 1e18) ?? 0;
escrowRows[index].fee = Number(d?.fee / 1e18) ?? 0;
});
setTotalVestable(
Object.values(escrowRows)
.map((d) => d.vestable)
.reduce((acc, curr) => acc + curr, 0)
);
},
});

const totalVestable = useMemo(() => {
return escrowRows.reduce((acc, row) => wei(acc).add(wei(row.vestable ?? 0)) ?? zeroBN, zeroBN);
}, [escrowRows]);

const resetTime = useMemo(() => {
const { epochEnd } = getEpochDetails(network?.id, epochPeriod);
return epochEnd;
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kwenta",
"version": "5.1.1",
"version": "5.1.2",
"scripts": {
"dev": "next",
"build": "next build",
Expand Down
65 changes: 39 additions & 26 deletions queries/futures/useQueryCrossMarginAccount.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { NetworkId } from '@synthetixio/contracts-interface';
import request, { gql } from 'graphql-request';
import { useEffect } from 'react';
import { useEffect, useState } from 'react';
import { useRecoilState } from 'recoil';

import { CROSS_MARGIN_ACCOUNT_FACTORY } from 'constants/address';
Expand All @@ -11,21 +9,32 @@ import logError from 'utils/logError';

import useCrossMarginAccountContracts from '../../hooks/useCrossMarginContracts';
import { FuturesAccountState } from './types';
import { getFuturesEndpoint } from './utils';

const SUPPORTED_NETWORKS = Object.keys(CROSS_MARGIN_ACCOUNT_FACTORY);

export default function useQueryCrossMarginAccount() {
const { crossMarginContractFactory } = useCrossMarginAccountContracts();
const { network, walletAddress } = Connector.useContainer();
const { network, walletAddress, signer } = Connector.useContainer();

const [futuresAccount, setFuturesAccount] = useRecoilState(futuresAccountState);
const [storedCrossMarginAccounts, setStoredCrossMarginAccount] = usePersistedRecoilState(
crossMarginAccountsState
);
const futuresEndpoint = getFuturesEndpoint(network?.id as NetworkId);
const [retryCount, setRetryCount] = useState(0);

const handleAccountQuery = async () => {
const queryAccountFromLogs = async (address: string): Promise<string | null> => {
if (!signer || !crossMarginContractFactory) return null;
const accountFilter = crossMarginContractFactory.filters.NewAccount(address);
if (accountFilter) {
const logs = await crossMarginContractFactory.queryFilter(accountFilter);
if (logs.length) {
return logs[0].args?.[1] || null;
}
}
return null;
};

if (!SUPPORTED_NETWORKS.includes(String(network.id))) {
const accountState: FuturesAccountState = {
crossMarginAvailable: false,
Expand Down Expand Up @@ -71,20 +80,7 @@ export default function useQueryCrossMarginAccount() {
walletAddress,
});

const response = await request(
futuresEndpoint,
gql`
query crossMarginAccounts($owner: String!) {
crossMarginAccounts(where: { owner: $owner }) {
id
owner
}
}
`,
{ owner: walletAddress }
);

const crossMarginAccount = response?.crossMarginAccounts[0]?.id || null;
const crossMarginAccount = await queryAccountFromLogs(walletAddress);

const existingAccounts = crossMarginContractFactory
? storedCrossMarginAccounts[crossMarginContractFactory.address]
Expand Down Expand Up @@ -114,12 +110,22 @@ export default function useQueryCrossMarginAccount() {
try {
return await handleAccountQuery();
} catch (err) {
logError(err);
setFuturesAccount({
...futuresAccount,
status: 'error',
});
return null;
// This is a hacky workaround to deal with the delayed Metamask error
// which causes the logs query to fail on network switching
// https://github.com/MetaMask/metamask-extension/issues/13375#issuecomment-1046125113
if (err.message.includes('underlying network changed') && retryCount < 5) {
setTimeout(() => {
setRetryCount(retryCount + 1);
}, 500);
} else {
setRetryCount(0);
logError(err);
setFuturesAccount({
...futuresAccount,
status: 'error',
});
return null;
}
}
};

Expand All @@ -128,5 +134,12 @@ export default function useQueryCrossMarginAccount() {
// eslint-disable-next-line
}, [walletAddress, crossMarginContractFactory?.address]);

useEffect(() => {
if (retryCount) {
queryAccount();
}
// eslint-disable-next-line
}, [retryCount]);

return queryAccount;
}
4 changes: 0 additions & 4 deletions sections/dashboard/Stake/EscrowTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { TableCellHead } from 'components/Table/Table';
import { monitorTransaction } from 'contexts/RelayerContext';
import { useStakingContext } from 'contexts/StakingContext';
import { EscrowRow } from 'hooks/useStakingData';
import { STAKING_LOW_GAS_LIMIT } from 'queries/staking/utils';
import { truncateNumbers } from 'utils/formatters/number';

import { StakingCard } from './common';
Expand Down Expand Up @@ -75,9 +74,6 @@ const EscrowTable = () => {
const { config } = usePrepareContractWrite({
...rewardEscrowContract,
functionName: 'vest',
overrides: {
gasLimit: STAKING_LOW_GAS_LIMIT,
},
args: [escrowRows.filter((d, index) => !!checkedState[index]).map((d) => d.id)],
enabled: escrowRows.filter((d, index) => !!checkedState[index]).map((d) => d.id).length > 0,
});
Expand Down
2 changes: 1 addition & 1 deletion translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
},
"hero": {
"title": "TRADE SYNTHETIC PERPETUALS",
"copy": "Gain exposure to a variety of asset with up to <0>25x leverage</0> and <0>deep liquidity</0>."
"copy": "Gain exposure to a variety of assets with up to <0>25x leverage</0> and <0>deep liquidity</0>."
},
"assets": {
"title": "UNIQUE MARKETS",
Expand Down

1 comment on commit 6e384e0

@vercel
Copy link

@vercel vercel bot commented on 6e384e0 Nov 20, 2022

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:

kwenta – ./

kwenta-kwenta.vercel.app
kwenta-git-main-kwenta.vercel.app
kwenta.io

Please sign in to comment.