-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #570 from threshold-network/display-redemptions-in…
…-my-activity Display redemptions in my activity Adds support for fetching pending/completed redemptions and displaying them under the `my activity` table on the Bridge page.
- Loading branch information
Showing
12 changed files
with
379 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { useWeb3React } from "@web3-react/core" | ||
import { useSubscribeToContractEvent } from "../../web3/hooks" | ||
import { isSameETHAddress } from "../../web3/utils" | ||
import { useAppDispatch } from "../store" | ||
import { useBridgeContract } from "./useBridgeContract" | ||
import { tbtcSlice } from "../../store/tbtc" | ||
import { BigNumber, Event } from "ethers" | ||
import { useThreshold } from "../../contexts/ThresholdContext" | ||
import { fromSatoshiToTokenPrecision } from "../../threshold-ts/utils" | ||
|
||
export const useSubscribeToRedemptionRequestedEvent = () => { | ||
const contract = useBridgeContract() | ||
const dispatch = useAppDispatch() | ||
const { account } = useWeb3React() | ||
const threshold = useThreshold() | ||
|
||
useSubscribeToContractEvent( | ||
contract, | ||
"RedemptionRequested", | ||
//@ts-ignore | ||
async ( | ||
walletPublicKeyHash: string, | ||
redeemerOutputScript: string, | ||
redeemer: string, | ||
requestedAmount: BigNumber, | ||
treasuryFee: BigNumber, | ||
txMaxFee: BigNumber, | ||
event: Event | ||
) => { | ||
if (!account || !isSameETHAddress(redeemer, account)) return | ||
|
||
const redemptionKey = threshold.tbtc.buildRedemptionKey( | ||
walletPublicKeyHash, | ||
redeemerOutputScript | ||
) | ||
|
||
dispatch( | ||
tbtcSlice.actions.redemptionRequested({ | ||
amount: fromSatoshiToTokenPrecision(requestedAmount).toString(), | ||
txHash: event.transactionHash, | ||
redemptionKey, | ||
blockNumber: event.blockNumber, | ||
additionalData: { redeemerOutputScript, walletPublicKeyHash }, | ||
}) | ||
) | ||
}, | ||
[null, null, account] | ||
) | ||
} |
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
Oops, something went wrong.