mirror of
https://github.com/pezkuwichain/pwap.git
synced 2026-04-23 05:57:55 +00:00
feat: add LP staking score and DOT/ETH/BTC tokens
This commit is contained in:
@@ -62,17 +62,29 @@ export const LPStakingModal: React.FC<LPStakingModalProps> = ({ isOpen, onClose
|
||||
const lpTokenId = poolData.stakedAssetId?.interior?.x2?.[1]?.generalIndex ?? poolId;
|
||||
|
||||
let userStaked = '0';
|
||||
const pendingRewards = '0';
|
||||
let pendingRewards = '0';
|
||||
let lpBalance = '0';
|
||||
|
||||
if (selectedAccount) {
|
||||
try {
|
||||
const stakeInfo = await assetHubApi.query.assetRewards.poolStakers([poolId, selectedAccount.address]);
|
||||
if (stakeInfo && (stakeInfo as { isSome: boolean }).isSome) {
|
||||
const stakeData = (stakeInfo as { unwrap: () => { toJSON: () => { amount: string } } }).unwrap().toJSON();
|
||||
const stakeData = (stakeInfo as { unwrap: () => { toJSON: () => { amount: string; rewardPerTokenPaid?: string } } }).unwrap().toJSON();
|
||||
userStaked = stakeData.amount || '0';
|
||||
}
|
||||
|
||||
// Fetch pending rewards from the pallet
|
||||
try {
|
||||
const rewardsResult = await (assetHubApi.call as { assetRewardsApi?: { pendingRewards: (poolId: number, account: string) => Promise<unknown> } })
|
||||
.assetRewardsApi?.pendingRewards(poolId, selectedAccount.address);
|
||||
if (rewardsResult && typeof rewardsResult === 'object' && 'toString' in rewardsResult) {
|
||||
pendingRewards = rewardsResult.toString();
|
||||
}
|
||||
} catch {
|
||||
// If runtime API not available, try direct calculation
|
||||
// pendingRewards stays 0
|
||||
}
|
||||
|
||||
const lpBal = await assetHubApi.query.poolAssets.account(lpTokenId, selectedAccount.address);
|
||||
if (lpBal && (lpBal as { isSome: boolean }).isSome) {
|
||||
const lpData = (lpBal as { unwrap: () => { toJSON: () => { balance: string } } }).unwrap().toJSON();
|
||||
|
||||
Reference in New Issue
Block a user