@ercworldio/blockchain-shared 1.0.1-dev.7 → 1.0.1-dev.8

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.
@@ -238,12 +238,7 @@ class BalanceService extends errors_1.default {
238
238
  WHERE user_id = $1 AND blockchain = $2
239
239
  RETURNING id, user_id, blockchain, parent_index, child_index, address, transaction_count, expires_at, created_at, updated_at
240
240
  ),
241
- deleted_balances AS (
242
- DELETE FROM usersmanagement.deposit_wallet_balance
243
- WHERE wallet_id = (SELECT id FROM updated_address)
244
- AND blockchain = $2
245
- ),
246
- inserted_balances AS (
241
+ upserted_balances AS (
247
242
  INSERT INTO usersmanagement.deposit_wallet_balance
248
243
  (wallet_id, blockchain, chain_id, token, decimals, balance, transaction_count, created_at, updated_at)
249
244
  SELECT
@@ -258,6 +253,11 @@ class BalanceService extends errors_1.default {
258
253
  unnest($7::text[]) AS token,
259
254
  unnest($8::int[]) AS decimals
260
255
  ) AS v
256
+ ON CONFLICT (blockchain, chain_id, wallet_id, token) DO UPDATE SET
257
+ decimals = EXCLUDED.decimals,
258
+ balance = 0,
259
+ transaction_count = 0,
260
+ updated_at = now()
261
261
  )
262
262
  SELECT * FROM updated_address;
263
263
  `, [userId, blockchain, newChildIndex, newAddress, newExpiresAt.toISOString(), chainIds, tokens, decimals]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ercworldio/blockchain-shared",
3
- "version": "1.0.1-dev.7",
3
+ "version": "1.0.1-dev.8",
4
4
  "description": "Shared library for blockchain projects",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",