Skip to content

Commit

Permalink
fix(bridge-ui): quota check (#17200)
Browse files Browse the repository at this point in the history
  • Loading branch information
KorbinianK authored May 15, 2024
1 parent 387ffb1 commit b883d34
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 22 deletions.
3 changes: 3 additions & 0 deletions lefthook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
pre-commit:
parallel: true
commands:
bridge-ui:
glob: "packages/bridge-ui/**.{js,ts,css,svelte}"
run: pnpm -F bridge-ui svelte:check && pnpm -F bridge-ui lint:fix && git add {staged_files}
guardian-ui:
glob: "packages/guardian-prover-health-check-ui/**.{js,ts,css,svelte}"
run: pnpm -F guardian-prover-health-check-ui svelte:check && pnpm -F guardian-prover-health-check-ui lint:fix && git add {staged_files}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { ActionButton } from '$components/Button';
import { StepBack } from '$components/Stepper';
import { ReleaseSteps } from './types';
import { INITIAL_STEP, ReleaseSteps } from './types';
const dispatch = createEventDispatcher();
Expand All @@ -16,8 +16,6 @@
export let releasing = false;
export let hideContinueButton: boolean;
const INITIAL_STEP = ReleaseSteps.CHECK;
const getNextStepText = (step: ReleaseSteps) => {
if (step === ReleaseSteps.REVIEW) {
return $t('common.confirm');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
const handleNextStep = () => {
if (activeStep === INITIAL_STEP) {
activeStep = RetrySteps.SELECT;
} else if (activeStep === RetrySteps.SELECT) {
activeStep = RetrySteps.REVIEW;
} else if (activeStep === RetrySteps.REVIEW) {
activeStep = RetrySteps.CONFIRM;
Expand All @@ -49,6 +51,8 @@
}
if (activeStep === RetrySteps.REVIEW) {
activeStep = RetrySteps.SELECT;
} else if (activeStep === RetrySteps.SELECT) {
activeStep = RetrySteps.CHECK;
} else if (activeStep === RetrySteps.CONFIRM) {
activeStep = RetrySteps.REVIEW;
}
Expand Down
43 changes: 24 additions & 19 deletions packages/bridge-ui/src/libs/bridge/checkBridgeQuota.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,30 @@ export const checkBridgeQuota = async ({
log('Skipping quota check for L2 chain');
return true;
}
try {
const quotaManagerAddress = getContractAddressByType({
srcChainId: Number(transaction.destChainId),
destChainId: Number(transaction.srcChainId),
contractType: ContractType.QUOTAMANAGER,
});

const quotaManagerAddress = getContractAddressByType({
srcChainId: Number(transaction.destChainId),
destChainId: Number(transaction.srcChainId),
contractType: ContractType.QUOTAMANAGER,
});

const quota = await readContract(config, {
address: quotaManagerAddress,
abi: quotaManagerAbi,
chainId: Number(transaction.destChainId),
functionName: 'availableQuota',
args: [tokenAddress, 0n],
});

if (amount > quota) {
log('Not enough quota', quota, amount);
return false;
const quota = await readContract(config, {
address: quotaManagerAddress,
abi: quotaManagerAbi,
chainId: Number(transaction.destChainId),
functionName: 'availableQuota',
args: [tokenAddress, 0n],
});

if (amount > quota) {
log('Not enough quota', quota, amount);
return false;
}
log('Quota:', quota, 'Amount:', amount, 'Has enough quota:', amount <= quota);
return true;
} catch (e) {
// If there is an error checking the quota, there is probably no quota configured
log('Error checking quota', e);
return true;
}
log('Quota:', quota, 'Amount:', amount, 'Has enough quota:', amount <= quota);
return true;
};

0 comments on commit b883d34

Please sign in to comment.