Skip to content

Commit

Permalink
Relayer provider withdrawMargin
Browse files Browse the repository at this point in the history
  • Loading branch information
JayJay1024 committed Nov 10, 2023
1 parent 61aba5c commit 9b8f318
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion packages/apps/src/providers/relayer-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ interface RelayerCtx {
depositMargin: (margin: bigint) => Promise<TransactionReceipt | undefined>;
updateFeeAndMargin: (margin: bigint, baseFee: bigint, feeRate: number) => Promise<TransactionReceipt | undefined>;
setFeeAndRate: (baseFee: bigint, feeRate: number) => Promise<TransactionReceipt | undefined>;
withdrawMargin: (amount: bigint) => Promise<TransactionReceipt | undefined>;
}

const defaultValue: RelayerCtx = {
Expand Down Expand Up @@ -79,6 +80,7 @@ const defaultValue: RelayerCtx = {
depositMargin: async () => undefined,
updateFeeAndMargin: async () => undefined,
setFeeAndRate: async () => undefined,
withdrawMargin: async () => undefined,
};

export const RelayerContext = createContext(defaultValue);
Expand Down Expand Up @@ -229,13 +231,29 @@ export default function RelayerProvider({ children }: PropsWithChildren<unknown>
return receipt;
} catch (err) {
console.error(err);
notification.error({ title: "Transfer failed", description: (err as Error).message });
notification.error({ title: "Update failed", description: (err as Error).message });
}
}
},
[address, oppositeBridge, sourceChain],
);

const withdrawMargin = useCallback(
async (amount: bigint) => {
if (address && defaultBridge) {
try {
const receipt = await defaultBridge.withdrawMargin(address, amount);
notifyTransaction(receipt, sourceChain);
return receipt;
} catch (err) {
console.error(err);
notification.error({ title: "Withdraw failed", description: (err as Error).message });
}
}
},
[address, defaultBridge, sourceChain],
);

useEffect(() => {
let sub$$: Subscription | undefined;

Expand Down Expand Up @@ -299,6 +317,7 @@ export default function RelayerProvider({ children }: PropsWithChildren<unknown>
depositMargin,
updateFeeAndMargin,
setFeeAndRate,
withdrawMargin,
}}
>
{children}
Expand Down

0 comments on commit 9b8f318

Please sign in to comment.