diff --git a/snap.manifest.json b/snap.manifest.json index 0d78f0c..24182b5 100644 --- a/snap.manifest.json +++ b/snap.manifest.json @@ -7,7 +7,7 @@ "url": "https://github.com/paulfears/StellarSnap.git" }, "source": { - "shasum": "GrNtYQY0zlfcfbkst5bpWRYCw/MJZ01K27cLnCDCWtY=", + "shasum": "gEfexAJfyQ+SlicTpGeYgco9SVyVtXRQlUaFWSYjUW0=", "location": { "npm": { "filePath": "dist/bundle.js", diff --git a/src/notificationEngine.ts b/src/notificationEngine.ts index 73f34e0..d2b0e18 100644 --- a/src/notificationEngine.ts +++ b/src/notificationEngine.ts @@ -16,6 +16,7 @@ export class NotificationEngine{ const mainNetBalances = await this.client.getAssets(this.wallet.address); this.client.setNetwork("testnet") const testNetBalances = await this.client.getAssets(this.wallet.address); + let currentState:State = await StateManager.getState(); const currentAccountAddr = currentState.currentAccount; let currentBalances = currentState.accounts[currentAccountAddr].assets; @@ -25,6 +26,8 @@ export class NotificationEngine{ } async handleAssetNotifications(prevAssets, currentAssets, currentState:State, network:"mainnet"|"testnet"){ + console.log("handle assets called"); + console.log(network); let outputItems = {} function findIncreasedBalanceOrNewObjects(prevAssets, currentAssets) { // Create a map of issuer to balance from the first array @@ -32,22 +35,27 @@ export class NotificationEngine{ prevAssets.forEach((item) => { console.log(item); if(item.asset_type === "native"){ + console.log("is native"); balanceMap.set("native", item.balance); } else{ balanceMap.set(item.issuer, item.balance); } }); + console.log("balancemap is"); console.log(balanceMap); // Filter the second array to find objects with increased balance or new objects + console.log("current Assets is"); currentAssets = Array.from(currentAssets); - + console.log(currentAssets); const result = currentAssets.filter((item) => { if(item.asset_type === "native"){ item.issuer = "native"; } const balanceInArray1 = balanceMap.get(item.issuer); + console.log("balance in Array 1"); + console.log(balanceInArray1); if (balanceInArray1 === undefined) { // If the issuer is not in the first array, it's a new object outputItems[item.issuer] = {asset: item, "diff":item.balance} @@ -59,16 +67,20 @@ export class NotificationEngine{ return Array.from(result); } const diffAssets:any = findIncreasedBalanceOrNewObjects(prevAssets, currentAssets); + console.log("diff assets is"); console.log(diffAssets); if(diffAssets.length === 0){ return true; } currentState.accounts[currentState.currentAccount].assets[network] = currentAssets; + await StateManager.setState(currentState) if(diffAssets.length < 4){ for(let i = 0; i