-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
168 additions
and
117 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
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,106 @@ | ||
import { Button } from "@/features/core/components/base"; | ||
import { memo, useEffect, useRef, useState } from "react"; | ||
|
||
import { Button, HeroText } from "@/features/core/components/base"; | ||
import CommonModal from "@/features/core/components/common-modal"; | ||
|
||
import { claimRewardsAction } from "../../context/actions"; | ||
import { useStaking } from "../../context/hooks"; | ||
import { setModalOpened } from "../../context/reducer"; | ||
|
||
type Step = "completed" | "loading"; | ||
|
||
const initialStep: Step = "loading"; | ||
|
||
const claimRewards = async ( | ||
stakingRef: ReturnType<typeof useStaking>, | ||
setStep: (step: Step) => void, | ||
) => { | ||
const { client, staking } = stakingRef; | ||
const { modal } = staking.state; | ||
|
||
const validatorAddress = modal?.content.validator.operatorAddress; | ||
|
||
if (!client || !validatorAddress) return; | ||
|
||
const addresses = { | ||
delegator: stakingRef.account.bech32Address, | ||
validator: validatorAddress, | ||
}; | ||
|
||
claimRewardsAction(addresses, client, stakingRef.staking).finally(() => { | ||
setStep("completed"); | ||
}); | ||
}; | ||
|
||
const RewardsModal = () => { | ||
const stakingRef = useStaking(); | ||
const [currentStep, setStep] = useState<Step>(initialStep); | ||
const requested = useRef(false); | ||
|
||
const { staking } = stakingRef; | ||
const { modal } = staking.state; | ||
|
||
const isOpen = modal?.type === "rewards"; | ||
|
||
useEffect(() => { | ||
if (isOpen) { | ||
if (requested.current) return; | ||
|
||
requested.current = true; | ||
claimRewards(stakingRef, setStep); | ||
} | ||
}, [isOpen, stakingRef]); | ||
|
||
if (!isOpen) return null; | ||
|
||
const content = (() => { | ||
if (currentStep === "loading") { | ||
return ( | ||
<div className="w-full text-center"> | ||
<div className="mb-[16px] uppercase"> | ||
<HeroText>CLAIMING</HeroText> | ||
</div> | ||
<div className="mb-[16px]"> | ||
Wait until your rewards are withdrawn. | ||
</div> | ||
<Button isLoading /> | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<> | ||
<div className="text-center"> | ||
<div className="mb-[16px] uppercase"> | ||
<HeroText>Success!</HeroText> | ||
</div> | ||
<div className="mb-[16px]"> | ||
You have claimed your staking rewards successfully. | ||
</div> | ||
</div> | ||
<Button | ||
onClick={() => { | ||
stakingRef.staking.dispatch(setModalOpened(null)); | ||
}} | ||
> | ||
CLOSE | ||
</Button> | ||
</> | ||
); | ||
})(); | ||
|
||
return ( | ||
<CommonModal | ||
isOpen={isOpen} | ||
onRequestClose={() => { | ||
if (currentStep === "loading") return; | ||
|
||
stakingRef.staking.dispatch(setModalOpened(null)); | ||
}} | ||
> | ||
<div>Success!</div> | ||
<div>You have claimed your staking rewards successfully.</div> | ||
<Button>CLOSE</Button> | ||
<div className="min-w-[390px]">{content}</div> | ||
</CommonModal> | ||
); | ||
}; | ||
|
||
export default RewardsModal; | ||
export default memo(RewardsModal); |
Oops, something went wrong.