@blocklet/payment-react 1.14.33 → 1.14.36

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.
@@ -54,24 +54,27 @@ function getStakingSetup(items, currency, billingThreshold = 0) {
54
54
  licensed: new BN(0),
55
55
  metered: new BN(0)
56
56
  };
57
- items.forEach((x) => {
58
- const price = x.upsell_price || x.price;
59
- const unit = getPriceUintAmountByCurrency(price, currency);
60
- const amount = new BN(unit).mul(new BN(x.quantity));
61
- if (price.type === "recurring" && price.recurring) {
62
- if (price.recurring.usage_type === "licensed") {
63
- staking.licensed = staking.licensed.add(amount);
64
- }
65
- if (price.recurring.usage_type === "metered") {
66
- if (+billingThreshold) {
67
- staking.metered = fromTokenToUnit(billingThreshold, currency.decimal);
68
- } else {
57
+ const recurringItems = items.map((x) => x.upsell_price || x.price).filter((x) => x.type === "recurring" && x.recurring);
58
+ if (recurringItems.length > 0) {
59
+ if (+billingThreshold) {
60
+ return fromTokenToUnit(billingThreshold, currency.decimal).toString();
61
+ }
62
+ items.forEach((x) => {
63
+ const price = x.upsell_price || x.price;
64
+ const unit = getPriceUintAmountByCurrency(price, currency);
65
+ const amount = new BN(unit).mul(new BN(x.quantity));
66
+ if (price.type === "recurring" && price.recurring) {
67
+ if (price.recurring.usage_type === "licensed") {
68
+ staking.licensed = staking.licensed.add(amount);
69
+ }
70
+ if (price.recurring.usage_type === "metered") {
69
71
  staking.metered = staking.metered.add(amount);
70
72
  }
71
73
  }
72
- }
73
- });
74
- return staking.licensed.add(staking.metered).toString();
74
+ });
75
+ return staking.licensed.add(staking.metered).toString();
76
+ }
77
+ return "0";
75
78
  }
76
79
  PaymentSummary.defaultProps = {
77
80
  onUpsell: noop,
@@ -61,24 +61,27 @@ function getStakingSetup(items, currency, billingThreshold = 0) {
61
61
  licensed: new _util.BN(0),
62
62
  metered: new _util.BN(0)
63
63
  };
64
- items.forEach(x => {
65
- const price = x.upsell_price || x.price;
66
- const unit = (0, _util2.getPriceUintAmountByCurrency)(price, currency);
67
- const amount = new _util.BN(unit).mul(new _util.BN(x.quantity));
68
- if (price.type === "recurring" && price.recurring) {
69
- if (price.recurring.usage_type === "licensed") {
70
- staking.licensed = staking.licensed.add(amount);
71
- }
72
- if (price.recurring.usage_type === "metered") {
73
- if (+billingThreshold) {
74
- staking.metered = (0, _util.fromTokenToUnit)(billingThreshold, currency.decimal);
75
- } else {
64
+ const recurringItems = items.map(x => x.upsell_price || x.price).filter(x => x.type === "recurring" && x.recurring);
65
+ if (recurringItems.length > 0) {
66
+ if (+billingThreshold) {
67
+ return (0, _util.fromTokenToUnit)(billingThreshold, currency.decimal).toString();
68
+ }
69
+ items.forEach(x => {
70
+ const price = x.upsell_price || x.price;
71
+ const unit = (0, _util2.getPriceUintAmountByCurrency)(price, currency);
72
+ const amount = new _util.BN(unit).mul(new _util.BN(x.quantity));
73
+ if (price.type === "recurring" && price.recurring) {
74
+ if (price.recurring.usage_type === "licensed") {
75
+ staking.licensed = staking.licensed.add(amount);
76
+ }
77
+ if (price.recurring.usage_type === "metered") {
76
78
  staking.metered = staking.metered.add(amount);
77
79
  }
78
80
  }
79
- }
80
- });
81
- return staking.licensed.add(staking.metered).toString();
81
+ });
82
+ return staking.licensed.add(staking.metered).toString();
83
+ }
84
+ return "0";
82
85
  }
83
86
  PaymentSummary.defaultProps = {
84
87
  onUpsell: _noop.default,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/payment-react",
3
- "version": "1.14.33",
3
+ "version": "1.14.36",
4
4
  "description": "Reusable react components for payment kit v2",
5
5
  "keywords": [
6
6
  "react",
@@ -93,7 +93,7 @@
93
93
  "@babel/core": "^7.25.2",
94
94
  "@babel/preset-env": "^7.25.2",
95
95
  "@babel/preset-react": "^7.24.7",
96
- "@blocklet/payment-types": "1.14.33",
96
+ "@blocklet/payment-types": "1.14.36",
97
97
  "@storybook/addon-essentials": "^7.6.20",
98
98
  "@storybook/addon-interactions": "^7.6.20",
99
99
  "@storybook/addon-links": "^7.6.20",
@@ -123,5 +123,5 @@
123
123
  "vite-plugin-babel": "^1.2.0",
124
124
  "vite-plugin-node-polyfills": "^0.21.0"
125
125
  },
126
- "gitHead": "e5ae487796f7c104b577dbab2a937013c3fbac12"
126
+ "gitHead": "927e39d554524434d20f22a950eec503166ae529"
127
127
  }
@@ -100,25 +100,33 @@ function getStakingSetup(items: TLineItemExpanded[], currency: TPaymentCurrency,
100
100
  metered: new BN(0),
101
101
  };
102
102
 
103
- items.forEach((x) => {
104
- const price = x.upsell_price || x.price;
105
- const unit = getPriceUintAmountByCurrency(price, currency);
106
- const amount = new BN(unit).mul(new BN(x.quantity));
107
- if (price.type === 'recurring' && price.recurring) {
108
- if (price.recurring.usage_type === 'licensed') {
109
- staking.licensed = staking.licensed.add(amount);
110
- }
111
- if (price.recurring.usage_type === 'metered') {
112
- if (+billingThreshold) {
113
- staking.metered = fromTokenToUnit(billingThreshold, currency.decimal);
114
- } else {
103
+ const recurringItems = items
104
+ .map((x) => x.upsell_price || x.price)
105
+ .filter((x) => x.type === 'recurring' && x.recurring);
106
+
107
+ if (recurringItems.length > 0) {
108
+ if (+billingThreshold) {
109
+ return fromTokenToUnit(billingThreshold, currency.decimal).toString();
110
+ }
111
+
112
+ items.forEach((x) => {
113
+ const price = x.upsell_price || x.price;
114
+ const unit = getPriceUintAmountByCurrency(price, currency);
115
+ const amount = new BN(unit).mul(new BN(x.quantity));
116
+ if (price.type === 'recurring' && price.recurring) {
117
+ if (price.recurring.usage_type === 'licensed') {
118
+ staking.licensed = staking.licensed.add(amount);
119
+ }
120
+ if (price.recurring.usage_type === 'metered') {
115
121
  staking.metered = staking.metered.add(amount);
116
122
  }
117
123
  }
118
- }
119
- });
124
+ });
125
+
126
+ return staking.licensed.add(staking.metered).toString();
127
+ }
120
128
 
121
- return staking.licensed.add(staking.metered).toString();
129
+ return '0';
122
130
  }
123
131
 
124
132
  PaymentSummary.defaultProps = {