+
+
+
+
+ {token.onChainFTMetadata?.symbol === "NEAR" &&
+ !token.contractName ? (
+
+ ) : (
+
+ )}
+
+
{disclaimer &&
@@ -96,7 +148,7 @@ export default function BalanceBox({
{button && (onClick || linkTo) &&
@@ -70,27 +72,17 @@ export default function Staking({
-
>
}
@@ -99,13 +91,13 @@ export default function Staking({
{
+ const getFarms = async () => {
+ const farms = await validator.contract.get_farms({from_index: 0, limit: 300});
+ setFarmList(await Promise.all(farms.map(({ token_id }, i) => {
+ dispatch(fetchToken({contractName: token_id}));
+ return validator.contract
+ .get_unclaimed_reward({ account_id: accountId, farm_id: i })
+ .catch(() => "0")
+ .then((balance) => ({ token_id, balance, farm_id: i }));
+ })));
+ };
+ if(validator && validator.version === ValidatorVersion[PROJECT_VALIDATOR_VERSION]) {
+ getFarms();
+ }
+ },[validator]);
+
const handleStakeAction = async () => {
if (showConfirmModal && !loading) {
await onWithdraw('withdraw', selectedValidator || validator.accountId);
@@ -62,7 +89,7 @@ export default function Validator({
{
dispatch(redirectTo(`/staking/${match.params.validator}/unstake`));
Mixpanel.track("UNSTAKE Click unstake button");
@@ -74,18 +101,37 @@ export default function Validator({
+ {farmList.map(({ token_id, balance, farm_id }) => (
+ {
+ // TODO claim accrued rewards and redirect home where tokens will be fetched
+ return validator.contract.claim({account_id: accountId, token_id, farm_id}).then(() => dispatch(redirectTo('/')));
+ }}
+ button="staking.balanceBox.farm.button"
+ buttonColor='gray-red'
+ />
+ ))}
{
setConfirm('withdraw');
Mixpanel.track("WITHDRAW Click withdraw button");
diff --git a/packages/frontend/src/hooks/fungibleTokensIncludingNEAR.js b/packages/frontend/src/hooks/fungibleTokensIncludingNEAR.js
index d71f89826a..8f54f58f32 100644
--- a/packages/frontend/src/hooks/fungibleTokensIncludingNEAR.js
+++ b/packages/frontend/src/hooks/fungibleTokensIncludingNEAR.js
@@ -4,7 +4,7 @@ import { selectAccountId, selectBalance } from "../redux/slices/account";
import { selectNearTokenFiatValueUSD } from "../redux/slices/tokenFiatValues";
import { selectTokensWithMetadataForAccountId } from "../redux/slices/tokens";
-const useNEARAsTokenWithMetadata = () => {
+export const useNEARAsTokenWithMetadata = () => {
const nearBalance = useSelector(selectBalance);
const nearTokenFiatValueUSD = useSelector(selectNearTokenFiatValueUSD);
diff --git a/packages/frontend/src/redux/slices/tokens/index.js b/packages/frontend/src/redux/slices/tokens/index.js
index fbd463ea00..b80c118cc3 100644
--- a/packages/frontend/src/redux/slices/tokens/index.js
+++ b/packages/frontend/src/redux/slices/tokens/index.js
@@ -25,12 +25,12 @@ const initialOwnedTokenState = {
error: initialErrorState
};
-async function getCachedContractMetadataOrFetch(contractName, accountId, state) {
+async function getCachedContractMetadataOrFetch(contractName, state) {
let contractMetadata = selectOneContractMetadata(state, { contractName });
if (contractMetadata) {
return contractMetadata;
}
- return FungibleTokens.getMetadata({ contractName, accountId });
+ return FungibleTokens.getMetadata({ contractName });
}
const fetchOwnedTokensForContract = createAsyncThunk(
@@ -63,11 +63,11 @@ const fetchTokens = createAsyncThunk(
await Promise.all(likelyContracts.map(async contractName => {
const { actions: { setContractMetadata } } = tokensSlice;
try {
- const contractMetadata = await getCachedContractMetadataOrFetch(contractName, accountId, getState());
+ const contractMetadata = await getCachedContractMetadataOrFetch(contractName, getState());
if (!selectOneContractMetadata(getState(), { contractName })) {
dispatch(setContractMetadata({ contractName, metadata: contractMetadata }));
}
- await dispatch(fetchOwnedTokensForContract({ accountId, contractName, contractMetadata }));
+ await dispatch(fetchOwnedTokensForContract({ accountId, contractName }));
} catch (e) {
// Continue loading other likely contracts on failures
console.warn(`Failed to load FT for ${contractName}`, e);
@@ -82,11 +82,13 @@ const fetchToken = createAsyncThunk(
const { dispatch, getState } = thunkAPI;
const { actions: { setContractMetadata } } = tokensSlice;
try {
- const contractMetadata = await getCachedContractMetadataOrFetch(contractName, accountId, getState());
+ const contractMetadata = await getCachedContractMetadataOrFetch(contractName, getState());
if (!selectOneContractMetadata(getState(), { contractName })) {
dispatch(setContractMetadata({ contractName, metadata: contractMetadata }));
}
- await dispatch(fetchOwnedTokensForContract({ accountId, contractName, contractMetadata }));
+ if(accountId) {
+ await dispatch(fetchOwnedTokensForContract({ accountId, contractName }));
+ }
} catch (e) {
// Continue loading other likely contracts on failures
console.warn(`Failed to load FT for ${contractName}`, e);
diff --git a/packages/frontend/src/utils/staking.js b/packages/frontend/src/utils/staking.js
index 33bfd9f172..3c7c0c7af4 100644
--- a/packages/frontend/src/utils/staking.js
+++ b/packages/frontend/src/utils/staking.js
@@ -40,7 +40,9 @@ export const stakingMethods = {
'get_reward_fee_fraction',
'get_farms',
'get_farm',
- 'get_active_farms'
+ 'get_active_farms',
+ 'get_unclaimed_reward',
+ 'claim'
],
changeMethods: [
'ping',