Skip to content

Commit 9966905

Browse files
committed
feat: more assets in monitored wallets for admin monitoring
1 parent d0d142e commit 9966905

File tree

2 files changed

+103
-12
lines changed

2 files changed

+103
-12
lines changed

src/localServer/define.d.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,22 @@ interface fx168_Order {
340340
nodes: number
341341
}
342342

343+
interface MonitoredAsset {
344+
id:string,
345+
name: string,
346+
balance: string
347+
}
348+
343349
interface MonitoredWallet {
344350
address: string
345-
cntpBalance: string
351+
assets: {
352+
cntp: MonitoredAsset,
353+
conet: MonitoredAsset,
354+
guardianNft: MonitoredAsset,
355+
conetianNft: MonitoredAsset,
356+
guardianReferralNft: MonitoredAsset,
357+
conetianReferralNft: MonitoredAsset,
358+
}
346359
}
347360

348361
type encrypt_keys_object = {

src/localServer/workers/utilities/web3Util.ts

Lines changed: 89 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3002,6 +3002,46 @@ const getReferrer = async (wallet, CNTP_Referrals) => {
30023002
return result
30033003
}
30043004

3005+
const createMonitoredWalletStructure = (walletAddress):MonitoredWallet => {
3006+
const monitoredWallet: MonitoredWallet = {
3007+
address: walletAddress,
3008+
assets: {
3009+
cntp: {
3010+
id: 'cntp',
3011+
name: 'CNTP',
3012+
balance: '0'
3013+
},
3014+
conet: {
3015+
id: 'conet',
3016+
name: 'CONET',
3017+
balance: '0'
3018+
},
3019+
guardianNft: {
3020+
id: 'guardianNft',
3021+
name: 'Guardian NFT',
3022+
balance: '0'
3023+
},
3024+
conetianNft: {
3025+
id: 'conetianNft',
3026+
name: 'CoNETian NFT',
3027+
balance: '0'
3028+
},
3029+
guardianReferralNft: {
3030+
id: 'guardianReferralNft',
3031+
name: 'Guardian Referral NFT',
3032+
balance: '0'
3033+
},
3034+
conetianReferralNft: {
3035+
id: 'conetianReferralNft',
3036+
name: 'CoNETian Agent NFT',
3037+
balance: '0'
3038+
}
3039+
}
3040+
}
3041+
3042+
return monitoredWallet
3043+
}
3044+
30053045
const addMonitoredWallet = async (cmd) => {
30063046
const walletAddress = cmd.data[0]
30073047

@@ -3018,10 +3058,7 @@ const addMonitoredWallet = async (cmd) => {
30183058
}
30193059

30203060
if (!CoNET_Data.monitoredWallets.find(w => w.address === walletAddress)) {
3021-
const monitoredWallet = {
3022-
address: walletAddress,
3023-
cntpBalance: '0'
3024-
}
3061+
const monitoredWallet: MonitoredWallet = createMonitoredWalletStructure(walletAddress)
30253062

30263063
CoNET_Data?.monitoredWallets.push(monitoredWallet)
30273064
}
@@ -3064,22 +3101,63 @@ const getBalanceOfMonitoredWallets = async () => {
30643101
CoNET_Data.monitoredWallets = [];
30653102
}
30663103

3067-
const wallets = CoNET_Data?.monitoredWallets
3104+
const wallets: MonitoredWallet[] = CoNET_Data?.monitoredWallets
30683105

30693106
if (!wallets || wallets.length === 0) {
30703107
return
30713108
}
30723109

30733110
const tmpMonitoredWallets: MonitoredWallet[] = []
30743111

3075-
for (const wallet of wallets) {
3076-
const balance = await scanCCNTP(wallet.address)
3112+
for (let wallet of wallets) {
3113+
if(!wallet.assets){
3114+
wallet = createMonitoredWalletStructure(wallet.address)
3115+
}
3116+
3117+
const promises: any = []
3118+
3119+
promises.push(scanCCNTP(wallet.address));
3120+
promises.push(scanCONETHolesky(wallet.address, provideCONET));
3121+
promises.push(scan_GuardianPlanAddr(wallet.address));
3122+
promises.push(scan_CONETianPlanAddr(wallet.address));
30773123

3078-
if(balance) {
3079-
wallet.cntpBalance =
3080-
!balance
3124+
const [cntp, conet, guardianPlan, conetianPlan] = await Promise.all(promises)
3125+
3126+
if (cntp) {
3127+
wallet.assets.cntp.balance = !cntp
30813128
? ""
3082-
: parseFloat(ethers.formatEther(balance)).toFixed(6);
3129+
: parseFloat(ethers.formatEther(cntp)).toFixed(6).toString();
3130+
}
3131+
3132+
if (conet) {
3133+
wallet.assets.conet.balance = !conet
3134+
? ""
3135+
: parseFloat(ethers.formatEther(conet)).toFixed(6).toString();
3136+
}
3137+
3138+
const conetianData: {
3139+
balanceGuardian: BigInt;
3140+
balanceReferrer: BigInt;
3141+
availableBalance: BigInt;
3142+
} | false = conetianPlan;
3143+
3144+
const guardianData: {
3145+
balanceGuardian: BigInt;
3146+
balanceReferrer: BigInt;
3147+
nodeNftId: BigInt
3148+
} | false = guardianPlan;
3149+
3150+
if (conetianData !== false) {
3151+
wallet.assets.conetianNft.balance = conetianData.balanceGuardian.toString();
3152+
wallet.assets.conetianReferralNft.balance =
3153+
conetianData.balanceReferrer.toString();
3154+
}
3155+
3156+
if (guardianData !== false) {
3157+
wallet.assets.guardianNft.balance =
3158+
guardianData.balanceGuardian.toString();
3159+
wallet.assets.guardianReferralNft.balance =
3160+
guardianData.balanceReferrer.toString();
30833161
}
30843162

30853163
tmpMonitoredWallets.push(wallet)

0 commit comments

Comments
 (0)