Skip to content

Commit

Permalink
Fix claims id
Browse files Browse the repository at this point in the history
  • Loading branch information
samuveth committed Jan 22, 2024
1 parent 9487aee commit 1633b87
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 25 deletions.
11 changes: 4 additions & 7 deletions src/components/SpaceProposalBoost.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import { getClaims, getBoosts } from '@/helpers/boost/subgraph';
import { SUPPORTED_NETWORKS } from '@/helpers/boost';
import { Proposal, BoostSubgraphResult } from '@/helpers/interfaces';
import { BigNumber } from '@ethersproject/bignumber';
import { useStorage } from '@vueuse/core';
import { getAddress } from '@ethersproject/address';
import { getRewards, Reward } from '@/helpers/boost/api';
import { BoostClaimSubgraph } from '@/helpers/boost/types';
const props = defineProps<{
proposal: Proposal;
Expand All @@ -14,7 +14,7 @@ const props = defineProps<{
const createModalOpen = ref(false);
const boostsModalOpen = ref(false);
const boosts = ref<BoostSubgraphResult[]>([]);
const claims = ref<{ id: string; amount: string }[]>([]);
const claims = ref<BoostClaimSubgraph[]>([]);
const loaded = ref(false);
const loadingRewards = ref(false);
const boostRewards = ref<Reward[]>([]);
Expand Down Expand Up @@ -54,9 +54,8 @@ const eligibleBoosts = computed(() => {
const hasUserClaimed = computed(() => {
if (!eligibleBoosts.value.length) return false;
const claimsIds = claims.value.map(claim => claim.id.split('.')[0]);
return eligibleBoosts.value.every(boost => {
return claimsIds.some(id => BigNumber.from(id).toString() === boost.id);
return claims.value.some(claim => claim.boost.id === boost.id);
});
});
Expand All @@ -68,9 +67,7 @@ const boostsSorted = computed(() => {
const other: BoostSubgraphResult[] = [];
boosts.value.forEach(boost => {
const isClaimed = claims.value.some(
claim => BigNumber.from(claim.id.split('.')[0]).toString() === boost.id
);
const isClaimed = claims.value.some(claim => claim.boost.id === boost.id);
if (isEligible(boost) && !isClaimed) {
eligible.push(boost);
Expand Down
21 changes: 5 additions & 16 deletions src/components/SpaceProposalBoostItem.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<script setup lang="ts">
import { Proposal, BoostSubgraphResult } from '@/helpers/interfaces';
import { formatUnits } from '@ethersproject/units';
import { BigNumber } from '@ethersproject/bignumber';
import { getAddress } from '@ethersproject/address';
import { Reward } from '@/helpers/boost/api';
import { BoostClaimSubgraph } from '@/helpers/boost/types';
const props = defineProps<{
proposal: Proposal;
boost: BoostSubgraphResult;
claims?: { id: string; amount: string }[];
claims?: BoostClaimSubgraph[];
web3Account: string;
isEligible?: boolean;
reward?: Reward;
Expand All @@ -28,24 +27,14 @@ const boostBalanceFormatted = computed(() => {
});
const isClaimedByUser = computed(() => {
if (!props.web3Account || !props.claims?.length) return false;
// Need to split because the id is in the format: boostId.address
const claims = props.claims.map(claim => claim.id.split('.'));
if (!props.claims?.length) return false;
return claims.some(
claim =>
BigNumber.from(claim[0]).toString() === props.boost.id &&
getAddress(claim[1]) === getAddress(props.web3Account)
);
return props.claims.some(claim => claim.boost.id === props.boost.id);
});
const claimedAmount = computed(() => {
if (!props.claims?.length) return '0';
// Need to split because the id is in the format: boostId.address
const claim = props.claims.find(
claim =>
BigNumber.from(claim.id.split('.')[0]).toString() === props.boost.id
);
const claim = props.claims.find(claim => claim.boost.id === props.boost.id);
if (!claim) return '0';
Expand Down
3 changes: 2 additions & 1 deletion src/components/SpaceProposalBoostModalBoosts.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<script setup lang="ts">
import { BoostSubgraphResult, Proposal } from '@/helpers/interfaces';
import { Reward } from '@/helpers/boost/api';
import { BoostClaimSubgraph } from '@/helpers/boost/types';
defineProps<{
open: boolean;
boosts: BoostSubgraphResult[];
boostsOwner: BoostSubgraphResult[];
claims: { id: string; amount: string }[];
claims: BoostClaimSubgraph[];
proposal: Proposal;
rewards: Reward[];
isEligible: (boost: BoostSubgraphResult) => boolean;
Expand Down
5 changes: 4 additions & 1 deletion src/helpers/boost/subgraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ export function getClaims(recipient: string, chainId: string) {
}
},
id: true,
amount: true
amount: true,
boost: {
id: true
}
}
});
}
Expand Down
7 changes: 7 additions & 0 deletions src/helpers/boost/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export type BoostClaimSubgraph = {
id: string;
amount: string;
boost: {
id: string;
};
};

0 comments on commit 1633b87

Please sign in to comment.