forked from the-standard/decentralised-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
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 #42 from the-standard/202411-staking-yield
202411 staking yield
- Loading branch information
Showing
21 changed files
with
2,092 additions
and
302 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
export const abi = [ | ||
{ | ||
"inputs": [], | ||
"name": "claim", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "dailyYield", | ||
"outputs": [ | ||
{ | ||
"components": [ | ||
{ | ||
"internalType": "address", | ||
"name": "token", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "amount", | ||
"type": "uint256" | ||
} | ||
], | ||
"internalType": "struct StakingTST.Reward[]", | ||
"name": "_rewards", | ||
"type": "tuple[]" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "_tst", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "decreaseStake", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "_tst", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "increaseStake", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "", | ||
"type": "address" | ||
} | ||
], | ||
"name": "positions", | ||
"outputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "start", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "TST", | ||
"type": "uint256" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "_holder", | ||
"type": "address" | ||
} | ||
], | ||
"name": "projectedEarnings", | ||
"outputs": [ | ||
{ | ||
"components": [ | ||
{ | ||
"internalType": "address", | ||
"name": "token", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "amount", | ||
"type": "uint256" | ||
} | ||
], | ||
"internalType": "struct StakingTST.Reward[]", | ||
"name": "_rewards", | ||
"type": "tuple[]" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "start", | ||
"outputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "", | ||
"type": "uint256" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
} | ||
] | ||
|
||
export default abi; |
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,170 @@ | ||
import { useState, useEffect, useRef } from "react"; | ||
import { | ||
useWriteContract, | ||
useChainId, | ||
} from "wagmi"; | ||
import { arbitrumSepolia } from "wagmi/chains"; | ||
import { toast } from 'react-toastify'; | ||
|
||
import { | ||
useStakingPoolv3AddressStore, | ||
useStakingPoolv3AbiStore | ||
} from "../../store/Store"; | ||
|
||
import Button from "../ui/Button"; | ||
import Modal from "../ui/Modal"; | ||
import Typography from "../ui/Typography"; | ||
import CenterLoader from "../ui/CenterLoader"; | ||
|
||
const ClaimingRewardsModal = ({ | ||
isOpen, | ||
handleCloseModal, | ||
}) => { | ||
const { | ||
arbitrumSepoliaStakingPoolv3Address, | ||
arbitrumStakingPoolv3Address, | ||
} = useStakingPoolv3AddressStore(); | ||
const { stakingPoolv3Abi } = useStakingPoolv3AbiStore(); | ||
const [claimLoading, setClaimLoading] = useState(false); | ||
const [showError, setShowError] = useState(false); | ||
const chainId = useChainId(); | ||
|
||
const stakingPoolv3Address = chainId === arbitrumSepolia.id ? arbitrumSepoliaStakingPoolv3Address : | ||
arbitrumStakingPoolv3Address; | ||
|
||
const { writeContract, isError, isPending, isSuccess, error } = useWriteContract(); | ||
|
||
const handleApproveClaim = async () => { | ||
try { | ||
writeContract({ | ||
abi: stakingPoolv3Abi, | ||
address: stakingPoolv3Address, | ||
functionName: "claim", | ||
args: [], | ||
}); | ||
} catch (error) { | ||
let errorMessage = ''; | ||
if (error && error.shortMessage) { | ||
errorMessage = error.shortMessage; | ||
} | ||
toast.error(errorMessage || 'There was an error'); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
if (isPending) { | ||
setClaimLoading(true); | ||
} else if (isSuccess) { | ||
toast.success('Success!'); | ||
setClaimLoading(false); | ||
handleCloseModal(); | ||
} else if (isError) { | ||
setShowError(true) | ||
setClaimLoading(false); | ||
} | ||
}, [ | ||
isPending, | ||
isSuccess, | ||
isError, | ||
error, | ||
]); | ||
|
||
if (showError) { | ||
return ( | ||
<> | ||
<Modal | ||
open={isOpen} | ||
closeModal={() => { | ||
setShowError(false); | ||
handleCloseModal(); | ||
}} | ||
> | ||
<> | ||
{claimLoading ? ( | ||
<> | ||
<Typography variant="h2" className="card-title"> | ||
Claiming Your Rewards | ||
</Typography> | ||
<CenterLoader /> | ||
</> | ||
) : ( | ||
<> | ||
<div> | ||
<Typography variant="h2" className="card-title"> | ||
Reward Claim Unsuccessful | ||
</Typography> | ||
<Typography variant="p"> | ||
There was a problem processing your reward claim request. | ||
</Typography> | ||
</div> | ||
|
||
<Button | ||
color="primary" | ||
onClick={() => setShowError(false)} | ||
> | ||
Return | ||
</Button> | ||
<Button | ||
color="ghost" | ||
onClick={() => { | ||
setShowError(false); | ||
handleCloseModal(); | ||
}} | ||
> | ||
Cancel | ||
</Button> | ||
</> | ||
)} | ||
</> | ||
</Modal> | ||
</> | ||
) | ||
} | ||
|
||
return ( | ||
<> | ||
<Modal | ||
open={isOpen} | ||
onClose={() => { | ||
handleCloseModal(); | ||
}} | ||
> | ||
<> | ||
{claimLoading ? ( | ||
<> | ||
<Typography variant="h2" className="card-title"> | ||
Claiming Your Rewards | ||
</Typography> | ||
<CenterLoader /> | ||
</> | ||
) : ( | ||
<> | ||
<div> | ||
<Typography variant="h2" className="card-title"> | ||
Claim Your Rewards | ||
</Typography> | ||
<Typography variant="p" className="mb-2"> | ||
Claiming your rewards will end your current staking period and restart a new one. | ||
</Typography> | ||
</div> | ||
<Button | ||
color="primary" | ||
onClick={handleApproveClaim} | ||
> | ||
Claim Rewards | ||
</Button> | ||
<Button | ||
color="ghost" | ||
onClick={handleCloseModal} | ||
> | ||
Cancel | ||
</Button> | ||
</> | ||
)} | ||
</> | ||
</Modal> | ||
</> | ||
) | ||
}; | ||
|
||
export default ClaimingRewardsModal; |
Oops, something went wrong.