Skip to content

Commit

Permalink
fix(pos-dashboard): Staking dashboard bug fixes (#14447)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberhorsey authored Aug 11, 2023
1 parent e6f7124 commit fd54f13
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 44 deletions.
3 changes: 3 additions & 0 deletions packages/bridge-ui/src/proof/ProofService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ export class ProofService implements Prover {
]);

log('Proof from eth_getProof', proof);
log('ProofOpts', opts);
log('Key', key);
log('Proof value', proof.storageProof[0].value);

if (proof.storageProof[0].value !== '0x1') {
throw Error('invalid proof');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ export const checkIfTokenIsDeployedCrossChain = async (
},
);
}
} else {
return true;
}
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion packages/bridge-ui/src/utils/getAddressForToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export async function getAddressForToken(
// Get the address for the token on the source chain
let address = token.addresses[srcChain.id];

// If the token isn't ETH or has no address...
// If the token isn't ETH and has no address...
if (!isETH(token) && (!address || address === '0x00')) {
// Find the address on the destination chain instead
const destChainAddress = token.addresses[destChain.id];
Expand Down
4 changes: 2 additions & 2 deletions packages/bridge-ui/src/wagmi/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ const setChain = (chainId: number) => {
srcChain.set(L1Chain);
destChain.set(L2Chain);

log(`Network swtiched to ${L1Chain.name}`);
log(`Network switched to ${L1Chain.name}`);
} else if (chainId === L2Chain.id) {
srcChain.set(L2Chain);
destChain.set(L1Chain);

log(`Network swtiched to ${L2Chain.name}`);
log(`Network switched to ${L2Chain.name}`);
} else {
isSwitchChainModalOpen.set(true);
}
Expand Down
2 changes: 0 additions & 2 deletions packages/pos-dashboard/src/components/Events/History.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
if (!allEvents) return [];
const start = (page - 1) * pageSize;
const end = start + pageSize;
console.log('total items', totalItems);
const ret = allEvents.slice(start, end);
console.log(ret);
return ret;
}
Expand Down
12 changes: 12 additions & 0 deletions packages/pos-dashboard/src/components/Rewards/Rewards.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
import { successToast } from '../NotificationToast.svelte';
import { pendingTransactions } from '../../store/transaction';
import { getTTKOBalance } from '../../utils/getTTKOBalance';
import { switchNetwork } from '../../utils/switchNetwork';
import { mainnetChain } from '../../chain/chains';
import { srcChain } from '../../store/chain';
let balance: BigNumber = BigNumber.from(0);
let ttkoBalanceInWei: BigNumber = BigNumber.from(0);
Expand Down Expand Up @@ -37,6 +41,10 @@
}
async function withdraw() {
if ($srcChain.id !== mainnetChain.id) {
await switchNetwork(mainnetChain.id);
}
const tx = await withdrawTaikoToken(
$signer,
TAIKO_L1_ADDRESS,
Expand All @@ -60,6 +68,10 @@
}
async function deposit() {
if ($srcChain.id !== mainnetChain.id) {
await switchNetwork(mainnetChain.id);
}
const tx = await depositTaikoToken(
$signer,
TAIKO_L1_ADDRESS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
import { successToast } from '../NotificationToast.svelte';
import { pendingTransactions } from '../../store/transaction';
import { getProverRequirements } from '../../utils/getProverRequirements';
import { switchNetwork } from '../../utils/switchNetwork';
import { mainnetChain } from '../../chain/chains';
import { srcChain } from '../../store/chain';
import { mainnet } from 'wagmi';
let ttkoBalanceInWei: BigNumber = BigNumber.from(0);
let amount: string = '0';
let rewardPerGas: number = 0;
Expand Down Expand Up @@ -42,6 +46,9 @@
}
async function submitForm() {
if ($srcChain.id !== mainnetChain.id) {
await switchNetwork(mainnetChain.id);
}
const tx = await stake(
$signer,
PROVER_POOL_ADDRESS,
Expand Down
1 change: 0 additions & 1 deletion packages/pos-dashboard/src/components/Tabs/TabPanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
activeTab = getContext<Writable<string>>(key);
} else {
activeTab = getContext<Writable<string>>(subKey);
console.log('EYY', tab, activeTab);
}
$: selected = tab === $activeTab;
Expand Down
38 changes: 0 additions & 38 deletions packages/pos-dashboard/src/utils/switchNetwork.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,5 @@
import { get } from 'svelte/store';
import { switchNetwork as wagmiSwitchNetwork } from 'wagmi/actions';

import { srcChain } from '../store/chain';
import { Deferred } from './Deferred';

export async function switchNetwork(chainId: number) {
const prevChainId = get(srcChain)?.id;

if (prevChainId === chainId) return;

await wagmiSwitchNetwork({ chainId });

// What are we doing here? we have a watcher waiting for network changes.
// When this happens this watcher is called and takes care of setting
// the signer and chains in the store. We are actually waiting here
// for these stores to change due to some race conditions in the UI.
// There will be a better design around this in alpha-4: fewer stores
// and '$:' tags. They're evil.
const deferred = new Deferred<void>();

// This will prevent an unlikely infinite loop
const starting = Date.now();
const timeout = 5000; // TODO: config?

const waitForNetworkChange = () => {
const srcChainId = get(srcChain)?.id;

if (srcChainId && srcChainId !== prevChainId) {
// We have finally set the chain in the store. We're done here.
deferred.resolve();
} else if (Date.now() > starting + timeout) {
// Wait, what???
deferred.reject(new Error('timeout switching network'));
} else {
setTimeout(waitForNetworkChange, 300); // TODO: config those 300?
}
};

waitForNetworkChange();

return deferred.promise;
}

0 comments on commit fd54f13

Please sign in to comment.