Skip to content

Commit

Permalink
Merge pull request #27 from Kolektivo-Labs/AnotherDev/Implement-multi…
Browse files Browse the repository at this point in the history
…call

feat: implement multicall and resolve upgrade NFT issues
  • Loading branch information
Another-DevX authored Jan 25, 2024
2 parents 8fe9051 + d53ba59 commit 580c2fb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function handleMintNFTClose() {
>
<p class="text-sm">Next level</p>
<p v-if="NFTData" class="text-sm">
{{ levels[NFTData?.id - 1].nextLevel }} RFP
{{ levels[NFTData?.tier - 1].nextLevel }} RFP
</p>
<p v-else class="text-sm">- RFP</p>
</div>
Expand Down Expand Up @@ -171,7 +171,7 @@ function handleMintNFTClose() {
>
<p class="text-sm">Next level</p>
<p v-if="NFTData" class="text-sm">
{{ levels[NFTData?.id - 1].nextLevel }} RFP
{{ levels[NFTData?.tier - 1].nextLevel }} RFP
</p>
<p v-else class="text-sm">- RFP</p>
</div>
Expand All @@ -190,7 +190,7 @@ function handleMintNFTClose() {
:color="!isAbleToUpgradeNFT ? 'gray' : 'gradient-blue-light'"
class="self-end w-fit"
size="sm"
@click="() => UpgradeNFT(NFTData?.id as number) "
@click="() => UpgradeNFT(NFTData?.id as number)"
>Upgrade</BalBtn
>
<BalBtn
Expand Down Expand Up @@ -242,7 +242,7 @@ function handleMintNFTClose() {
>
<p class="text-sm">Next level</p>
<p v-if="NFTData" class="text-sm">
{{ levels[NFTData?.id - 1].nextLevel }} RFP
{{ levels[NFTData?.tier - 1].nextLevel }} RFP
</p>
<p v-else class="text-sm">- RFP</p>
</div>
Expand Down
47 changes: 26 additions & 21 deletions src/services/campaigns/campaigns.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { call } from '@/lib/utils/balancer/contract';
import { call, multicall } from '@/lib/utils/balancer/contract';
import { walletService as walletServiceInstance } from '@/services/web3/wallet.service';
import { default as SimpleMinterAbi } from '@/lib/abi/KolektivoSimpleMinter.json';
import { default as RFNFTAbi } from '@/lib/abi/KolektivoRNFT.json';
Expand Down Expand Up @@ -26,6 +26,7 @@ export type NFTData = RFNFTData & {
imageData: string;
id: number;
points: number;
tier: number;
isAbleToUpgrade: [boolean, bigint];
};

Expand Down Expand Up @@ -63,30 +64,34 @@ export default class CampaignsService {
'ownerTokenId',
[userAddress],
]);
const currentNFTTier = await call(provider, RFNFTAbi, [
this.addresses.RFNFT,
'tokenIdTier',
[currentNFTId],
]);
const currentNFTPoints = await this.getCurrentPoints(currentNFTId);
const currentNFT = await call(provider, RFNFTAbi, [
this.addresses.RFNFT,
'tokenURI',
[BigNumber.from(currentNFTId).toNumber()],
]);
const isAbleToUpgrade = await call(provider, RFNFTAbi, [
this.addresses.RFNFT,
'canLevelUp',
[currentNFTId],
]);

const currentNFTDataCalls = [
[this.addresses.RFNFT, 'tokenIdPoints', [currentNFTId]],
[this.addresses.RFNFT, 'tokenIdTier', [currentNFTId]],
[
this.addresses.RFNFT,
'tokenURI',
[BigNumber.from(currentNFTId).toNumber()],
],
[this.addresses.RFNFT, 'canLevelUp', [currentNFTId]],
];
const currentNFTDataResponses = (await multicall(
String(chainId),
provider,
RFNFTAbi,
[...currentNFTDataCalls]
)) as (boolean | bigint | string | number | [boolean, bigint])[];
const NFTData: RFNFTData = await ipfsService.get(
currentNFT.split('ipfs://')[1]
(currentNFTDataResponses[2] as string).split('ipfs://')[1]
);
return {
...NFTData,
isAbleToUpgrade,
id: Number(currentNFTTier),
points: currentNFTPoints,
isAbleToUpgrade: currentNFTDataResponses[3] as [boolean, bigint],
id: Number(currentNFTId),
tier: Number(currentNFTDataResponses[1]),
points: parseInt(
formatUnits(BigNumber.from(currentNFTDataResponses[0]), 18)
),
};
}
return null;
Expand Down

0 comments on commit 580c2fb

Please sign in to comment.