suidouble 1.14.3 → 1.15.1-2

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/index.js CHANGED
@@ -7,6 +7,7 @@ import SuiLocalTestValidator from './lib/SuiLocalTestValidator.js';
7
7
  import SuiMemoryObjectStorage from './lib/SuiMemoryObjectStorage.js';
8
8
  import SuiCoin from './lib/SuiCoin.js';
9
9
  import SuiCoins from './lib/SuiCoins.js';
10
+ import SuiPaginatedResponse from './lib/SuiPaginatedResponse.js';
10
11
  import { Transaction, Commands } from '@mysten/sui/transactions';
11
12
  import { bcs } from '@mysten/sui/bcs';
12
13
 
@@ -28,4 +29,5 @@ export {
28
29
  SuiMemoryObjectStorage,
29
30
  SuiCoin,
30
31
  SuiCoins,
32
+ SuiPaginatedResponse,
31
33
  };
package/lib/SuiCoin.js CHANGED
@@ -103,10 +103,10 @@ export default class SuiCoin {
103
103
  const asBig = BigInt(Math.floor(Number(asFloatString)));
104
104
 
105
105
  if (asBig > 1000n) {
106
- if (asBig < 1000000n) return this.formatWithAbbr(asBig, 1000n, 'K');
107
- if (asBig >= 1000000n && asBig < 1000000000n) return this.formatWithAbbr(asBig, 1000000n, 'M');
108
- if (asBig >= 1000000000n && asBig < 1000000000000n) return this.formatWithAbbr(asBig, 1000000000n, 'B');
109
- if (asBig >= 1000000000000n) return this.formatWithAbbr(asBig, 1000000000000n, 'T');
106
+ if (asBig < 1000000n) return this.formatWithAbbr(asBig, 1000n, 'K', separateThousands);
107
+ if (asBig >= 1000000n && asBig < 1000000000n) return this.formatWithAbbr(asBig, 1000000n, 'M', separateThousands);
108
+ if (asBig >= 1000000000n && asBig < 1000000000000n) return this.formatWithAbbr(asBig, 1000000000n, 'B', separateThousands);
109
+ if (asBig >= 1000000000000n) return this.formatWithAbbr(asBig, 1000000000000n, 'T', separateThousands);
110
110
  }
111
111
  }
112
112
 
@@ -133,12 +133,20 @@ export default class SuiCoin {
133
133
  *
134
134
  * @returns {string}
135
135
  */
136
- formatWithAbbr(amount, measureUnit, abbrSymbol) {
137
- let showAmount = (''+(Number(amount) / Number(measureUnit / 1000n)));
136
+ formatWithAbbr(amount, measureUnit, abbrSymbol, separateThousands = false) {
137
+ let showAmount = (''+Math.floor(Number(amount) / Number(measureUnit / 1000n)));
138
138
  showAmount = showAmount.padEnd(4, '0');
139
139
 
140
140
  const result = Intl.NumberFormat('en-US').format(Number(showAmount));
141
- return result.replace(',', '.') + abbrSymbol;
141
+
142
+ let separator = '';
143
+ if (separateThousands) {
144
+ separator = (typeof separateThousands === 'string') ? separateThousands : ',';
145
+ }
146
+
147
+ const pcs = result.split(',');
148
+ const lastPc = pcs.pop();
149
+ return pcs.join( separator ) + '.' + lastPc + abbrSymbol;
142
150
  }
143
151
 
144
152
 
@@ -222,7 +230,7 @@ export default class SuiCoin {
222
230
  }
223
231
 
224
232
  if (this.__getMetadataPromise) {
225
- return await this.__getMetadataPromise();
233
+ return await this.__getMetadataPromise;
226
234
  }
227
235
 
228
236
  // be sure it asyncs in 1 thread
package/lib/SuiMaster.js CHANGED
@@ -162,6 +162,13 @@ export default class SuiMaster extends SuiCommonMethods {
162
162
  get SuiEvent() {
163
163
  return SuiEvent;
164
164
  }
165
+ /**
166
+ * Referencing it here to get rid of circullar dependency. So you can always call SuiPaginatedResponse contructor if you have instance of SuiMaster
167
+ */
168
+ get SuiPaginatedResponse() {
169
+ return SuiPaginatedResponse;
170
+ }
171
+ /**
165
172
 
166
173
  /**
167
174
  * Storage storing all objects interacted by this suiMaster
@@ -406,10 +413,13 @@ export default class SuiMaster extends SuiCommonMethods {
406
413
  }
407
414
 
408
415
  async fetchTransactions(params = {}) {
409
- const filter = {};
416
+ let filter = {};
410
417
  if (params.fromAddress) {
411
418
  filter.FromAddress = params.fromAddress;
412
419
  }
420
+ if (params.filter) {
421
+ filter = params.filter;
422
+ }
413
423
 
414
424
  const queryParams = {
415
425
  descending_order: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "suidouble",
3
- "version": "1.14.3",
3
+ "version": "1.15.1-2",
4
4
  "description": "Set of provider, package and object classes for javascript representation of Sui Move smart contracts. Use same code for publishing, upgrading, integration testing, interaction with smart contracts and integration in browser web3 dapps",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -22,7 +22,7 @@
22
22
  "author": "suidouble (https://github.com/suidouble)",
23
23
  "license": "Apache-2.0",
24
24
  "dependencies": {
25
- "@mysten/sui": "^1.14.3",
25
+ "@mysten/sui": "^1.15.1",
26
26
  "@polymedia/coinmeta": "^0.0.17",
27
27
  "@wallet-standard/core": "^1.0.3",
28
28
  "websocket": "^1.0.35"
@@ -108,11 +108,27 @@ test('string representation (withAbbr) works ok', async t => {
108
108
  const toDisplayM2 = suiCoin.amountToString(suiMaster.MIST_PER_SUI * BigInt(2000000) + BigInt(900), {withAbbr: true}); // 1000 SUI + 1 mist
109
109
  t.equal(toDisplayM2, '2.000M');
110
110
 
111
+ const toDisplayM2spec = suiCoin.amountToString(148518424765531477n, {withAbbr: true}); // 1000 SUI + 1 mist
112
+ t.equal(toDisplayM2spec, '148.518M');
113
+
114
+
111
115
  const toDisplayB1 = suiCoin.amountToString(suiMaster.MIST_PER_SUI * BigInt(1000000000) + BigInt(1), {withAbbr: true}); // 1000 SUI + 1 mist
112
116
  t.equal(toDisplayB1, '1.000B');
113
117
 
118
+ const toDisplayB2spec = suiCoin.amountToString(148518424765531477000n, {withAbbr: true}); // 1000 SUI + 1 mist
119
+ t.equal(toDisplayB2spec, '148.518B');
120
+
114
121
  const toDisplayT1 = suiCoin.amountToString(suiMaster.MIST_PER_SUI * BigInt(1000000000000) + BigInt(1), {withAbbr: true}); // 1000 SUI + 1 mist
115
122
  t.equal(toDisplayT1, '1.000T');
123
+
124
+ const toDisplayT2spec = suiCoin.amountToString(148518424765531477000000n, {withAbbr: true}); // 1000 SUI + 1 mist
125
+ t.equal(toDisplayT2spec, '148.518T');
126
+
127
+ const toDisplayT20spec = suiCoin.amountToString(148518424765531477000000000n, {withAbbr: true}); // 1000 SUI + 1 mist
128
+ t.equal(toDisplayT20spec, '148518.424T');
129
+
130
+ const toDisplayT20spec2 = suiCoin.amountToString(148518424765531477000000000n, {withAbbr: true, separateThousands: true}); // 1000 SUI + 1 mist
131
+ t.equal(toDisplayT20spec2, '148,518.424T');
116
132
  });
117
133
 
118
134