@exodus/solana-api 2.5.26 → 2.5.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/solana-api",
3
- "version": "2.5.26",
3
+ "version": "2.5.27",
4
4
  "description": "Exodus internal Solana asset API wrapper",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -34,5 +34,5 @@
34
34
  "devDependencies": {
35
35
  "@exodus/assets-testing": "file:../../../__testing__"
36
36
  },
37
- "gitHead": "88be13b711bcb6ca1be86993d67e69d4ec5ac263"
37
+ "gitHead": "9e93c3846854f6c64b0bdd5abe103ec5ff980596"
38
38
  }
@@ -111,20 +111,24 @@ export class SolanaMonitor extends BaseMonitor {
111
111
  refresh,
112
112
  })
113
113
 
114
- let staking = accountState.mem
115
-
116
114
  const cursorChanged = this.hasNewCursor({ walletAccount, cursorState })
117
- if (refresh || cursorChanged) {
118
- staking = await this.updateStakingInfo({ walletAccount, address, stakingAddresses })
119
- this.cursors[walletAccount] = cursorState.cursor
120
- }
121
115
 
122
- await this.updateTxLogByAsset({ walletAccount, logItemsByAsset, refresh })
123
116
  if (refresh || hasNewTxs || cursorChanged) {
117
+ const staking =
118
+ refresh || cursorChanged
119
+ ? await this.getStakingInfo({ address, stakingAddresses })
120
+ : accountState.mem
121
+
124
122
  const tokenAccounts = await this.api.getTokenAccountsByOwner(address)
125
- await this.emitUnknownTokensEvent({ tokenAccounts })
126
123
  const account = await this.getAccount({ address, staking, tokenAccounts })
127
- await this.updateState({ account, cursorState, walletAccount })
124
+
125
+ // update all state at once
126
+ await this.emitUnknownTokensEvent({ tokenAccounts })
127
+ await this.updateTxLogByAsset({ walletAccount, logItemsByAsset, refresh })
128
+ await this.updateState({ account, cursorState, walletAccount, staking })
129
+ if (refresh || cursorChanged) {
130
+ this.cursors[walletAccount] = cursorState.cursor
131
+ }
128
132
  }
129
133
  }
130
134
 
@@ -144,6 +148,7 @@ export class SolanaMonitor extends BaseMonitor {
144
148
  if (assetName === 'unknown' || !asset) continue // skip unknown tokens
145
149
  const feeAsset = asset.feeAsset
146
150
 
151
+ // TODO: remove all uses of toDefault()
147
152
  const coinAmount = asset.currency.baseUnit(tx.amount).toDefault()
148
153
 
149
154
  const item = {
@@ -209,15 +214,15 @@ export class SolanaMonitor extends BaseMonitor {
209
214
  this.api.getTokensBalance({ address, filterByTokens: tokens, tokenAccounts }),
210
215
  ])
211
216
 
212
- const stakedBalance = this.asset.currency.baseUnit(staking.locked).toDefault()
213
- const withdrawableBalance = this.asset.currency.baseUnit(staking.withdrawable).toDefault()
214
- const pendingBalance = this.asset.currency.baseUnit(staking.pending).toDefault()
217
+ const stakedBalance = this.asset.currency.baseUnit(staking.locked)
218
+ const withdrawableBalance = this.asset.currency.baseUnit(staking.withdrawable)
219
+ const pendingBalance = this.asset.currency.baseUnit(staking.pending)
215
220
  const balance = this.asset.currency
216
221
  .baseUnit(solBalance)
217
- .toDefault()
218
222
  .add(stakedBalance)
219
223
  .add(withdrawableBalance)
220
224
  .add(pendingBalance)
225
+ .toDefault()
221
226
 
222
227
  const tokenBalances = _.mapValues(splBalances, (balance, name) =>
223
228
  this.assets[name].currency.baseUnit(balance).toDefault()
@@ -229,18 +234,19 @@ export class SolanaMonitor extends BaseMonitor {
229
234
  }
230
235
  }
231
236
 
232
- async updateState({ account, cursorState, walletAccount }) {
237
+ async updateState({ account, cursorState, walletAccount, staking }) {
233
238
  const { balance, tokenBalances } = account
234
- const newData = { balance, tokenBalances, ...cursorState }
239
+ const newData = { balance, tokenBalances, mem: staking, ...cursorState }
235
240
  return this.updateAccountState({ newData, walletAccount })
236
241
  }
237
242
 
238
- async updateStakingInfo({ walletAccount, address, stakingAddresses = [] }) {
243
+ async getStakingInfo({ address, stakingAddresses = [] }) {
239
244
  const stakingInfo = await this.api.getStakeAccountsInfo(address)
240
245
  // merge current and old staking addresses
241
246
  const allStakingAddresses = _.uniq([...Object.keys(stakingInfo.accounts), ...stakingAddresses])
242
247
  const rewards = await this.api.getRewards(allStakingAddresses)
243
- const mem = {
248
+
249
+ return {
244
250
  loaded: true,
245
251
  staking: this.staking,
246
252
  isDelegating: Object.values(stakingInfo.accounts).some(({ state }) =>
@@ -252,8 +258,5 @@ export class SolanaMonitor extends BaseMonitor {
252
258
  earned: this.asset.currency.baseUnit(rewards).toDefault(),
253
259
  accounts: stakingInfo.accounts, // Obj
254
260
  }
255
-
256
- await this.updateAccountState({ walletAccount, newData: { mem } })
257
- return mem
258
261
  }
259
262
  }