Skip to content

Commit

Permalink
Merge branch 'main' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
RAMTO committed Jan 10, 2024
2 parents 60a9549 + a2d2eae commit 1a296de
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/pages/SingleSidedStaking.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
addressToId,
getTokenBalance,
getUserAssociatedTokens,
idToAddress,
requestUserAddressFromId,
} from '../utils/tokenUtils';
import { renderSSSEndDate } from '../utils/farmUtils';
import {
Expand Down Expand Up @@ -142,11 +142,12 @@ const SingleSidedStaking = () => {
const { tokens: userRewardsData } = useTokensByListIds(userRewardsAddresses, useQueryOptions);

const getHeliStaked = useCallback(async () => {
const userAddress = await requestUserAddressFromId(userId);
try {
const promisesArray = [
kernelContract.balanceOf(idToAddress(userId)),
kernelContract.balanceOf(userAddress),
kernelContract.heliStaked(),
kernelContract.votingPower(idToAddress(userId)),
kernelContract.votingPower(userAddress),
];

const [balanceBN, totalStakedBN, votingPowerBN] = await Promise.all(promisesArray);
Expand All @@ -162,10 +163,11 @@ const SingleSidedStaking = () => {
}, [kernelContract, userId]);

const getUserRewardsBalance = useCallback(async () => {
const userAddress = await requestUserAddressFromId(userId);
try {
const decimals = await tokenContract.decimals();
const rewardsBN = await rewardsContract.callStatic.claim({
from: idToAddress(userId),
from: userAddress,
});
const rewards = ethers.utils.formatUnits(rewardsBN, decimals);

Expand Down Expand Up @@ -370,6 +372,8 @@ const SingleSidedStaking = () => {
const getSSSData = async () => {
setLoadingSSSData(true);

const userAddress = await requestUserAddressFromId(userId);

try {
const kernelAddress = process.env.REACT_APP_KERNEL_ADDRESS;

Expand All @@ -378,9 +382,9 @@ const SingleSidedStaking = () => {
// sssContract.maxSupply(),
// sssContract.expirationDate(),
sssContract.totalDeposited(),
sssContract.positions(kernelAddress, idToAddress(userId)),
sssContract.claimable(kernelAddress, idToAddress(userId)),
sssContract.totalRewards(kernelAddress, idToAddress(userId)),
sssContract.positions(kernelAddress, userAddress),
sssContract.claimable(kernelAddress, userAddress),
sssContract.totalRewards(kernelAddress, userAddress),
];

const [
Expand Down
13 changes: 13 additions & 0 deletions src/utils/tokenUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,19 @@ export const requestAddressFromId = async (id: string) => {
}
};

export const requestUserAddressFromId = async (id: string) => {
const url = `${process.env.REACT_APP_MIRROR_NODE_URL}/api/v1/accounts/${id}`;
try {
const {
data: { evm_address },
} = await axios(url);
return evm_address;
} catch (e) {
console.error(e);
return '0';
}
};

export const hasFeesOrKeys = (token: ITokenData) => {
const { hasFees, keys: tokenKeys } = token;
const keys = tokenKeys ? Object.keys(tokenKeys) : [];
Expand Down

0 comments on commit 1a296de

Please sign in to comment.