Skip to content

Commit

Permalink
Merge pull request #184 from zkBob/staging
Browse files Browse the repository at this point in the history
v2.0.1
  • Loading branch information
maxaleks authored Apr 28, 2023
2 parents f23cf20 + d6416be commit 1997bd4
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zkbob-ui",
"version": "2.0.0",
"version": "2.0.1",
"private": true,
"dependencies": {
"@dicebear/avatars": "^4.10.2",
Expand Down
2 changes: 1 addition & 1 deletion src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const config = {
rpcUrls: ['https://polygon-rpc.com'],
},
'10': {
rpcUrls: ['https://opt-mainnet.g.alchemy.com/v2/demo', 'https://mainnet.optimism.io']
rpcUrls: ['https://optimism-mainnet.public.blastapi.io'],
},
},
snarkParams: {
Expand Down
10 changes: 7 additions & 3 deletions src/containers/LiFiWidget/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import React from 'react';
import React, { useContext } from 'react';
import { LiFiWidget } from '@lifi/widget';

import { PoolContext } from 'contexts';
import { useWindowDimensions } from 'hooks';

import config from 'config';

export default () => {
const { currentPool } = useContext(PoolContext);
const { width } = useWindowDimensions();

const widgetConfig = {
Expand Down Expand Up @@ -34,8 +38,8 @@ export default () => {
},
fromChain: 1,
fromToken: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
toChain: 137,
toToken: '0xB0B195aEFA3650A6908f15CdaC7D92F8a5791B0B',
toChain: config.pools[currentPool].chainId,
toToken: config.pools[currentPool].tokenAddress,
disableTelemetry: true,
};

Expand Down
6 changes: 4 additions & 2 deletions src/containers/PasswordModal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ export default () => {
}, []);
const confirm = useCallback(async () => {
try {
await unlockAccount(password);
setPassword('');
const success = await unlockAccount(password);
if (success) {
setPassword('');
}
} catch (error) {
setError(error);
}
Expand Down
20 changes: 15 additions & 5 deletions src/contexts/ZkAccountContext/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const ZkAccountContextProvider = ({ children }) => {
const [zkAccountId, setZkAccountId] = useState(null);
const [balance, setBalance] = useState(ethers.constants.Zero);
const [history, setHistory] = useState(null);
const [isPendingIncoming, setIsPendingIncoming] = useState(false);
const [isPending, setIsPending] = useState(false);
const [pendingActions, setPendingActions] = useState([]);
const [isLoadingZkAccount, setIsLoadingZkAccount] = useState(false);
Expand Down Expand Up @@ -143,12 +144,14 @@ export const ZkAccountContextProvider = ({ children }) => {

const updateHistory = useCallback(async () => {
let history = [];
let isPendingIncoming = false;
let isPending = false;
let pendingActions = [];
let atomicTxFee = ethers.constants.Zero;
if (zkAccount) {
if (currentPool !== previousPool) {
setHistory([]);
setIsPendingIncoming(false);
setIsPending(false);
setPendingActions([]);
}
Expand All @@ -174,6 +177,9 @@ export const ZkAccountContextProvider = ({ children }) => {
highFee: item.fee.gt(await fromShieldedAmount(atomicTxFee)),
})));
history = history.reverse();
isPendingIncoming = !!history.find(item =>
item.state === HistoryRecordState.Pending && item.type === HistoryTransactionType.TransferIn
);
pendingActions = history.filter(item =>
item.state === HistoryRecordState.Pending && item.type !== HistoryTransactionType.TransferIn
);
Expand All @@ -187,6 +193,7 @@ export const ZkAccountContextProvider = ({ children }) => {
setHistory(history);
setPendingActions(pendingActions);
setIsPending(isPending);
setIsPendingIncoming(isPendingIncoming);
setIsLoadingHistory(false);
}, [zkAccount, zkClient, fromShieldedAmount, currentPool, previousPool]);

Expand Down Expand Up @@ -424,16 +431,17 @@ export const ZkAccountContextProvider = ({ children }) => {
sk: giftCard.sk,
pool: targetPool,
birthindex: Number(giftCard.birthIndex),
proverMode: proverExists ? ProverMode.Delegated : ProverMode.Local,
proverMode: proverExists ? ProverMode.DelegatedWithFallback : ProverMode.Local,
});
await zkClient.waitJobTxHash(jobId);
deleteGiftCard();
updatePoolData();
} catch (error) {
console.error(error);
Sentry.captureException(error, { tags: { method: 'ZkAccountContext.redeemGiftCard' } });
throw error;
}
}, [zkClient, giftCard, switchToPool, currentPool]);
}, [zkClient, giftCard, switchToPool, currentPool, updatePoolData]);

const decryptMnemonic = password => {
const cipherText = window.localStorage.getItem('seed');
Expand All @@ -443,14 +451,16 @@ export const ZkAccountContextProvider = ({ children }) => {
}

const unlockAccount = useCallback(password => {
if (!zkClient) return false;
try {
const mnemonic = decryptMnemonic(password);
closePasswordModal();
loadZkAccount(mnemonic);
return true;
} catch (error) {
throw new Error('Incorrect password');
}
}, [loadZkAccount, closePasswordModal]);
}, [zkClient, loadZkAccount, closePasswordModal]);

const verifyPassword = useCallback(password => {
try {
Expand Down Expand Up @@ -509,15 +519,15 @@ export const ZkAccountContextProvider = ({ children }) => {
}, [updateMaxTransferable, balance, currentPool]);

useEffect(() => {
if (isPending) {
if (isPending || isPendingIncoming) {
const interval = 5000; // 5 seconds
const intervalId = setInterval(() => {
updatePoolData();
updateTokenBalance();
}, interval);
return () => clearInterval(intervalId);
}
}, [isPending, updatePoolData, updateTokenBalance]);
}, [isPending, isPendingIncoming, updatePoolData, updateTokenBalance]);

useEffect(() => {
loadRelayerVersion();
Expand Down
2 changes: 1 addition & 1 deletion src/contexts/ZkAccountContext/zp.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const createAccount = async (zkClient, secretKey, birthIndex, useDelegatedProver
sk,
pool: currentPool,
birthindex: birthIndex,
proverMode: (useDelegatedProver && proverExists) ? ProverMode.Delegated : ProverMode.Local,
proverMode: (useDelegatedProver && proverExists) ? ProverMode.DelegatedWithFallback : ProverMode.Local,
});
};

Expand Down

0 comments on commit 1997bd4

Please sign in to comment.