-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add loaders to wrap, unwrap, withdraw forms
- Loading branch information
1 parent
e768031
commit a32c49d
Showing
6 changed files
with
48 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,15 @@ | ||
import { useMemo, useEffect, useState } from 'react'; | ||
import { useWSTETHContractRPC } from '@lido-sdk/react'; | ||
import { useContractSWR, useWSTETHContractRPC } from '@lido-sdk/react'; | ||
import { BigNumber } from 'ethers'; | ||
import debounce from 'lodash/debounce'; | ||
import { STRATEGY_LAZY } from 'utils/swrStrategies'; | ||
|
||
export const useStethByWsteth = ( | ||
wsteth: BigNumber | undefined, | ||
): BigNumber | undefined => { | ||
const [stethBalance, setStethBalance] = useState<BigNumber>(); | ||
|
||
const wstethContractRPC = useWSTETHContractRPC(); | ||
|
||
const getStethBalance = useMemo( | ||
() => | ||
debounce(async (wsteth: BigNumber | undefined) => { | ||
if (!wsteth) { | ||
return; | ||
} | ||
|
||
const steth = await wstethContractRPC.getStETHByWstETH(wsteth); | ||
setStethBalance(steth); | ||
}, 500), | ||
[wstethContractRPC], | ||
); | ||
|
||
useEffect(() => { | ||
void getStethBalance(wsteth); | ||
}, [getStethBalance, wsteth]); | ||
|
||
return stethBalance; | ||
return useContractSWR({ | ||
contract: useWSTETHContractRPC(), | ||
method: 'getStETHByWstETH', | ||
params: [wsteth], | ||
shouldFetch: !!wsteth, | ||
config: STRATEGY_LAZY, | ||
}).data; | ||
}; |