@cityofzion/blockchain-service 1.11.0 → 1.13.0

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.
@@ -9,3 +9,5 @@ export declare function waitForTransaction<BSName extends string = string>(servi
9
9
  export declare function waitForAccountTransaction<BSName extends string = string>(service: BlockchainService<BSName>, txId: string, account: Account<BSName>, maxAttempts?: number): Promise<boolean>;
10
10
  export declare function fetchAccountsForBlockchainServices<BSName extends string = string>(blockchainServices: BlockchainService<BSName>[], getAccountCallback: (service: BlockchainService<BSName>, index: number) => Promise<Account<BSName>>): Promise<Map<BSName, Account<BSName>[]>>;
11
11
  export declare function normalizeHash(hash: string): string;
12
+ export declare function countDecimals(value: string | number): number;
13
+ export declare function formatNumber(value: string | number, decimals?: number): string;
package/dist/functions.js CHANGED
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.normalizeHash = exports.fetchAccountsForBlockchainServices = exports.waitForAccountTransaction = exports.waitForTransaction = exports.hasLedger = exports.hasExplorerService = exports.hasNft = exports.isCalculableFee = exports.isClaimable = exports.hasNameService = void 0;
12
+ exports.formatNumber = exports.countDecimals = exports.normalizeHash = exports.fetchAccountsForBlockchainServices = exports.waitForAccountTransaction = exports.waitForTransaction = exports.hasLedger = exports.hasExplorerService = exports.hasNft = exports.isCalculableFee = exports.isClaimable = exports.hasNameService = void 0;
13
13
  function hasNameService(service) {
14
14
  return 'resolveNameServiceDomain' in service && 'validateNameServiceDomainFormat' in service;
15
15
  }
@@ -47,7 +47,7 @@ function waitForTransaction(service, txId) {
47
47
  yield service.blockchainDataService.getTransaction(txId);
48
48
  return true;
49
49
  }
50
- catch (_a) {
50
+ catch (_b) {
51
51
  // Empty block
52
52
  }
53
53
  attempts++;
@@ -68,7 +68,7 @@ function waitForAccountTransaction(service, txId, account, maxAttempts = 10) {
68
68
  if (isTransactionConfirmed)
69
69
  return true;
70
70
  }
71
- catch (_a) {
71
+ catch (_b) {
72
72
  // Empty block
73
73
  }
74
74
  attempts++;
@@ -94,7 +94,7 @@ function fetchAccountsForBlockchainServices(blockchainServices, getAccountCallba
94
94
  if (!transactions || transactions.length <= 0)
95
95
  shouldBreak = true;
96
96
  }
97
- catch (_a) {
97
+ catch (_b) {
98
98
  shouldBreak = true;
99
99
  }
100
100
  }
@@ -112,3 +112,27 @@ function normalizeHash(hash) {
112
112
  return hash.replace('0x', '').toLowerCase();
113
113
  }
114
114
  exports.normalizeHash = normalizeHash;
115
+ function countDecimals(value) {
116
+ var _b;
117
+ const [, decimals] = value.toString().split('.');
118
+ return (_b = decimals === null || decimals === void 0 ? void 0 : decimals.length) !== null && _b !== void 0 ? _b : 0;
119
+ }
120
+ exports.countDecimals = countDecimals;
121
+ function formatNumber(value, decimals = 0) {
122
+ let newValue = typeof value === 'number' ? value.toFixed(decimals) : value;
123
+ newValue = newValue.replace(/,|\.\.|\.,/g, '.');
124
+ if (decimals === 0) {
125
+ newValue = newValue.split('.')[0];
126
+ }
127
+ else {
128
+ newValue = newValue.replace(/[^\d.]/g, '');
129
+ const countedDecimals = countDecimals(newValue);
130
+ if (countedDecimals > decimals) {
131
+ newValue = newValue.slice(0, newValue.length - countedDecimals + decimals);
132
+ }
133
+ }
134
+ return newValue.replace(/\s|-/g, '').replace(/^([^.]*\.)(.*)$/, function (_a, b, c) {
135
+ return b + c.replace(/\./g, '');
136
+ });
137
+ }
138
+ exports.formatNumber = formatNumber;
@@ -257,6 +257,7 @@ export type SwapServiceEvents<BSName extends string = string> = {
257
257
  amountToReceive: (amount: SwapServiceLoadableValue<string>) => void | Promise<void>;
258
258
  tokenToReceive: (token: SwapServiceLoadableValue<SwapServiceToken<BSName>>) => void | Promise<void>;
259
259
  availableTokensToReceive: (tokens: SwapServiceLoadableValue<SwapServiceToken<BSName>[]>) => void | Promise<void>;
260
+ error: (error: string) => void | Promise<void>;
260
261
  };
261
262
  export type SwapServiceSwapResult = {
262
263
  id: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cityofzion/blockchain-service",
3
- "version": "1.11.0",
3
+ "version": "1.13.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": "https://github.com/CityOfZion/blockchain-services",