Skip to content

Commit d0a6100

Browse files
committed
feat: send active passport info to frontend
1 parent 5ed5aee commit d0a6100

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

src/localServer/define.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,14 @@ interface profile extends keyPair {
424424
historicBalance?: historicBalance[]
425425
airdrop?: airdrop
426426
silentPassPassports?: passportInfo[]
427+
activePassport?: freePassport
428+
}
429+
430+
interface freePassport {
431+
nftID: string;
432+
expires: string;
433+
expiresDays: string;
434+
premium: boolean;
427435
}
428436

429437
interface publicProfile {

src/localServer/workers/utilities/web3Util.ts

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3564,11 +3564,53 @@ const getPassportsInfoForAllProfiles = async () => {
35643564
}
35653565

35663566
for (const profile of profiles) {
3567-
const result = await getPassportsInfoForProfile(profile);
3568-
profile.silentPassPassports = result
3567+
const passports = await getPassportsInfoForProfile(profile);
3568+
const currentPassport = await getCurrentPassportInfo(profile);
3569+
3570+
profile.silentPassPassports = passports;
3571+
profile.activePassport = {
3572+
nftID: currentPassport?.nftIDs?.toString(),
3573+
expires: currentPassport?.expires?.toString(),
3574+
expiresDays: currentPassport?.expiresDays?.toString(),
3575+
premium: currentPassport?.premium,
3576+
}
35693577
}
35703578
};
35713579

3580+
const getCurrentPassportInfoInMainnet = async (profile: profile) => {
3581+
if (!profile) {
3582+
return;
3583+
}
3584+
3585+
const wallet = new ethers.Wallet(
3586+
profile.privateKeyArmor,
3587+
conetDepinProvider
3588+
);
3589+
3590+
const passportContract = new ethers.Contract(
3591+
passportContractAddress_mainnet,
3592+
passportAbi_mainnet,
3593+
wallet
3594+
);
3595+
3596+
try {
3597+
const result = await passportContract.getCurrentPassport(wallet.address);
3598+
return result;
3599+
} catch (ex) {
3600+
console.log(ex);
3601+
}
3602+
};
3603+
3604+
const getCurrentPassportInfo = async (profile: profile) => {
3605+
if (!CoNET_Data) {
3606+
return;
3607+
}
3608+
3609+
const resultMainnet = await getCurrentPassportInfoInMainnet(profile);
3610+
3611+
return resultMainnet;
3612+
};
3613+
35723614
const getPassportsInfoForProfile = async (profile: profile): Promise<passportInfo[]> => {
35733615
const tmpCancunPassports = await getPassportsInfo(profile, 'cancun');
35743616
const tmpMainnetPassports = await getPassportsInfo(profile, 'mainnet');

0 commit comments

Comments
 (0)