@caspay/sdk 1.1.4 → 1.1.6

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/dist/index.esm.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { PublicKey, ExecutableDeployItem, TransferDeployItem, DeployHeader, Deploy } from 'casper-js-sdk';
2
2
 
3
- const SDK_VERSION = '1.1.4';
3
+ const SDK_VERSION = '1.1.6';
4
4
 
5
5
  class HttpClient {
6
6
  constructor(config) {
@@ -320,8 +320,9 @@ class Payments {
320
320
  }
321
321
 
322
322
  class Subscriptions {
323
- constructor(client) {
323
+ constructor(client, config) {
324
324
  this.client = client;
325
+ this.config = config;
325
326
  }
326
327
  async checkStatus(params) {
327
328
  if (!params.subscriberAddress) {
@@ -332,7 +333,8 @@ class Subscriptions {
332
333
  };
333
334
  }
334
335
  const merchantId = this.client.getMerchantId();
335
- let url = `/v1/subscriptions/check?merchant_id=${merchantId}&subscriber=${params.subscriberAddress}`;
336
+ const network = params.network || this.config.network || 'testnet';
337
+ let url = `/v1/subscriptions/check?merchant_id=${merchantId}&subscriber=${params.subscriberAddress}&network=${network}`;
336
338
  if (params.planId) {
337
339
  url += `&plan_id=${params.planId}`;
338
340
  }
@@ -346,6 +348,7 @@ class Wallet {
346
348
  this.provider = null;
347
349
  this.connected = false;
348
350
  this.activeAddress = null;
351
+ this.activeNetwork = null;
349
352
  this.config = config;
350
353
  this.initProvider();
351
354
  }
@@ -366,6 +369,9 @@ class Wallet {
366
369
  const state = JSON.parse(event.detail);
367
370
  this.connected = true;
368
371
  this.activeAddress = state.activeKey || null;
372
+ if (state.activeNetwork) {
373
+ this.activeNetwork = state.activeNetwork;
374
+ }
369
375
  }
370
376
  catch (e) {
371
377
  }
@@ -373,6 +379,7 @@ class Wallet {
373
379
  window.addEventListener('casper-wallet:disconnected', () => {
374
380
  this.connected = false;
375
381
  this.activeAddress = null;
382
+ this.activeNetwork = null;
376
383
  });
377
384
  window.addEventListener('casper-wallet:activeKeyChanged', (event) => {
378
385
  try {
@@ -382,6 +389,14 @@ class Wallet {
382
389
  catch (e) {
383
390
  }
384
391
  });
392
+ window.addEventListener('casper-wallet:activeNetworkChanged', (event) => {
393
+ try {
394
+ const state = JSON.parse(event.detail);
395
+ this.activeNetwork = state.activeNetwork || state;
396
+ }
397
+ catch (e) {
398
+ }
399
+ });
385
400
  window.addEventListener('casper-wallet:locked', () => {
386
401
  this.connected = false;
387
402
  });
@@ -530,14 +545,20 @@ class Wallet {
530
545
  return this.config.network === 'mainnet' ? 'casper' : 'casper-test';
531
546
  }
532
547
  async getActiveNetwork() {
548
+ if (this.activeNetwork) {
549
+ return this.activeNetwork;
550
+ }
533
551
  if (!this.provider) {
534
552
  return this.getNetwork();
535
553
  }
536
554
  try {
537
- const network = await this.provider.getActiveNetwork?.();
538
- if (network) {
539
- // 'casper' or 'casper-test'
540
- return network;
555
+ const state = await this.provider.getActivePublicKey();
556
+ if (state) {
557
+ const providerState = window.CasperWalletState;
558
+ if (providerState?.activeNetwork) {
559
+ this.activeNetwork = providerState.activeNetwork;
560
+ return providerState.activeNetwork;
561
+ }
541
562
  }
542
563
  }
543
564
  catch (error) {
@@ -591,7 +612,7 @@ class CasPay {
591
612
  this.transfer = new Transfer(this.wallet, apiBaseUrl);
592
613
  this.payments = new Payments(this.client);
593
614
  this.payments.setWallet(this.wallet, this.transfer);
594
- this.subscriptions = new Subscriptions(this.client);
615
+ this.subscriptions = new Subscriptions(this.client, config);
595
616
  }
596
617
  static get version() {
597
618
  return SDK_VERSION;
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var casperJsSdk = require('casper-js-sdk');
6
6
 
7
- const SDK_VERSION = '1.1.4';
7
+ const SDK_VERSION = '1.1.6';
8
8
 
9
9
  class HttpClient {
10
10
  constructor(config) {
@@ -324,8 +324,9 @@ class Payments {
324
324
  }
325
325
 
326
326
  class Subscriptions {
327
- constructor(client) {
327
+ constructor(client, config) {
328
328
  this.client = client;
329
+ this.config = config;
329
330
  }
330
331
  async checkStatus(params) {
331
332
  if (!params.subscriberAddress) {
@@ -336,7 +337,8 @@ class Subscriptions {
336
337
  };
337
338
  }
338
339
  const merchantId = this.client.getMerchantId();
339
- let url = `/v1/subscriptions/check?merchant_id=${merchantId}&subscriber=${params.subscriberAddress}`;
340
+ const network = params.network || this.config.network || 'testnet';
341
+ let url = `/v1/subscriptions/check?merchant_id=${merchantId}&subscriber=${params.subscriberAddress}&network=${network}`;
340
342
  if (params.planId) {
341
343
  url += `&plan_id=${params.planId}`;
342
344
  }
@@ -350,6 +352,7 @@ class Wallet {
350
352
  this.provider = null;
351
353
  this.connected = false;
352
354
  this.activeAddress = null;
355
+ this.activeNetwork = null;
353
356
  this.config = config;
354
357
  this.initProvider();
355
358
  }
@@ -370,6 +373,9 @@ class Wallet {
370
373
  const state = JSON.parse(event.detail);
371
374
  this.connected = true;
372
375
  this.activeAddress = state.activeKey || null;
376
+ if (state.activeNetwork) {
377
+ this.activeNetwork = state.activeNetwork;
378
+ }
373
379
  }
374
380
  catch (e) {
375
381
  }
@@ -377,6 +383,7 @@ class Wallet {
377
383
  window.addEventListener('casper-wallet:disconnected', () => {
378
384
  this.connected = false;
379
385
  this.activeAddress = null;
386
+ this.activeNetwork = null;
380
387
  });
381
388
  window.addEventListener('casper-wallet:activeKeyChanged', (event) => {
382
389
  try {
@@ -386,6 +393,14 @@ class Wallet {
386
393
  catch (e) {
387
394
  }
388
395
  });
396
+ window.addEventListener('casper-wallet:activeNetworkChanged', (event) => {
397
+ try {
398
+ const state = JSON.parse(event.detail);
399
+ this.activeNetwork = state.activeNetwork || state;
400
+ }
401
+ catch (e) {
402
+ }
403
+ });
389
404
  window.addEventListener('casper-wallet:locked', () => {
390
405
  this.connected = false;
391
406
  });
@@ -534,14 +549,20 @@ class Wallet {
534
549
  return this.config.network === 'mainnet' ? 'casper' : 'casper-test';
535
550
  }
536
551
  async getActiveNetwork() {
552
+ if (this.activeNetwork) {
553
+ return this.activeNetwork;
554
+ }
537
555
  if (!this.provider) {
538
556
  return this.getNetwork();
539
557
  }
540
558
  try {
541
- const network = await this.provider.getActiveNetwork?.();
542
- if (network) {
543
- // 'casper' or 'casper-test'
544
- return network;
559
+ const state = await this.provider.getActivePublicKey();
560
+ if (state) {
561
+ const providerState = window.CasperWalletState;
562
+ if (providerState?.activeNetwork) {
563
+ this.activeNetwork = providerState.activeNetwork;
564
+ return providerState.activeNetwork;
565
+ }
545
566
  }
546
567
  }
547
568
  catch (error) {
@@ -595,7 +616,7 @@ class CasPay {
595
616
  this.transfer = new Transfer(this.wallet, apiBaseUrl);
596
617
  this.payments = new Payments(this.client);
597
618
  this.payments.setWallet(this.wallet, this.transfer);
598
- this.subscriptions = new Subscriptions(this.client);
619
+ this.subscriptions = new Subscriptions(this.client, config);
599
620
  }
600
621
  static get version() {
601
622
  return SDK_VERSION;
@@ -1,7 +1,8 @@
1
1
  import type { HttpClient } from '../core/client';
2
- import type { SubscriptionCheckParams, SubscriptionCheckResponse } from '../types';
2
+ import type { SubscriptionCheckParams, SubscriptionCheckResponse, CasPayConfig } from '../types';
3
3
  export declare class Subscriptions {
4
4
  private client;
5
- constructor(client: HttpClient);
5
+ private config;
6
+ constructor(client: HttpClient, config: CasPayConfig);
6
7
  checkStatus(params: SubscriptionCheckParams): Promise<SubscriptionCheckResponse>;
7
8
  }
@@ -4,6 +4,7 @@ export declare class Wallet {
4
4
  private config;
5
5
  private connected;
6
6
  private activeAddress;
7
+ private activeNetwork;
7
8
  constructor(config: CasPayConfig);
8
9
  private initProvider;
9
10
  private setupEventListeners;
@@ -93,6 +93,7 @@ export interface TransferResult {
93
93
  export interface SubscriptionCheckParams {
94
94
  subscriberAddress: string;
95
95
  planId?: string;
96
+ network?: 'testnet' | 'mainnet';
96
97
  }
97
98
  export interface SubscriptionCheckResponse {
98
99
  success: boolean;
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "1.1.4";
1
+ export declare const SDK_VERSION = "1.1.6";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caspay/sdk",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
4
4
  "description": "Official CasPay JavaScript/TypeScript SDK - Accept crypto payments with Casper blockchain",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",