diff --git a/packages/apps/src/providers/relayer-provider.tsx b/packages/apps/src/providers/relayer-provider.tsx index f6539d713..73e787206 100644 --- a/packages/apps/src/providers/relayer-provider.tsx +++ b/packages/apps/src/providers/relayer-provider.tsx @@ -50,6 +50,7 @@ interface RelayerCtx { depositMargin: (margin: bigint) => Promise; updateFeeAndMargin: (margin: bigint, baseFee: bigint, feeRate: number) => Promise; setFeeAndRate: (baseFee: bigint, feeRate: number) => Promise; + withdrawMargin: (amount: bigint) => Promise; } const defaultValue: RelayerCtx = { @@ -79,6 +80,7 @@ const defaultValue: RelayerCtx = { depositMargin: async () => undefined, updateFeeAndMargin: async () => undefined, setFeeAndRate: async () => undefined, + withdrawMargin: async () => undefined, }; export const RelayerContext = createContext(defaultValue); @@ -229,13 +231,29 @@ export default function RelayerProvider({ children }: PropsWithChildren 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; @@ -299,6 +317,7 @@ export default function RelayerProvider({ children }: PropsWithChildren depositMargin, updateFeeAndMargin, setFeeAndRate, + withdrawMargin, }} > {children}