@threekit-tools/treble 0.0.67 → 0.0.68

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.
@@ -1,9 +1,10 @@
1
1
  import { IHydratedAttribute, IMetadata, ISetConfiguration } from '../../types';
2
- declare type UseNestedConfiguratorError = [undefined, undefined, undefined];
2
+ declare type UseNestedConfiguratorError = [undefined, undefined, undefined, undefined];
3
3
  declare type UseNestedConfiguratorSuccess = [
4
4
  Record<string, IHydratedAttribute>,
5
5
  (val: ISetConfiguration) => Promise<void>,
6
- IMetadata
6
+ IMetadata,
7
+ number | undefined
7
8
  ];
8
9
  declare const useNestedConfigurator: (address: string | Array<string>) => UseNestedConfiguratorError | UseNestedConfiguratorSuccess;
9
10
  export default useNestedConfigurator;
@@ -41,10 +41,12 @@ var store_1 = require("../../store");
41
41
  var treble_1 = require("../../store/treble");
42
42
  var utils_1 = require("../../utils");
43
43
  var attributes_1 = require("../../store/attributes");
44
+ var price_1 = require("../../store/price");
44
45
  var useNestedConfigurator = function (address) {
45
46
  var dispatch = (0, store_1.useThreekitDispatch)();
46
47
  var hasInitialized = (0, store_1.useThreekitSelector)(treble_1.isThreekitInitialized);
47
48
  var playerLoading = (0, store_1.useThreekitSelector)(treble_1.isPlayerLoading);
49
+ var priceConfig = (0, store_1.useThreekitSelector)(price_1.getPriceConfig);
48
50
  var _a = (0, store_1.useThreekitSelector)(attributes_1.getHydrationData), _ = _a[0], translations = _a[1], language = _a[2];
49
51
  var _b = (0, react_1.useState)(), attributes = _b[0], setAttributes = _b[1];
50
52
  var metadataRef = (0, react_1.useRef)({});
@@ -65,7 +67,7 @@ var useNestedConfigurator = function (address) {
65
67
  })();
66
68
  }, [hasInitialized, address, playerLoading]);
67
69
  if (!hasInitialized || !configurator.current || !attributes)
68
- return [undefined, undefined, undefined];
70
+ return [undefined, undefined, undefined, undefined];
69
71
  var handleSelect = function (config) { return __awaiter(void 0, void 0, void 0, function () {
70
72
  var updatedAttrs;
71
73
  var _a, _b;
@@ -89,6 +91,9 @@ var useNestedConfigurator = function (address) {
89
91
  return Object.assign(output, (_a = {}, _a[attr.name] = attr, _a));
90
92
  }, {});
91
93
  var preppedAttributes = (0, utils_1.hydrateAttribute)([attributeObj, translations, language], handleSelect);
92
- return [preppedAttributes, handleSelect, metadataRef.current];
94
+ var price = priceConfig
95
+ ? configurator.current.getPrice(priceConfig.id, priceConfig.currency)
96
+ : undefined;
97
+ return [preppedAttributes, handleSelect, metadataRef.current, price];
93
98
  };
94
99
  exports.default = useNestedConfigurator;
@@ -2,11 +2,6 @@ import { RootState, ThreekitDispatch } from './index';
2
2
  /*****************************************************
3
3
  * Types and Interfaces
4
4
  ****************************************************/
5
- export interface PriceState {
6
- id: undefined | string;
7
- currency: undefined | string;
8
- price: undefined | number;
9
- }
10
5
  export interface IPriceConfig {
11
6
  id: string;
12
7
  currency: string;
@@ -15,6 +10,11 @@ export interface IPrice {
15
10
  currency: string;
16
11
  price: number;
17
12
  }
13
+ export interface PriceState {
14
+ id: undefined | string;
15
+ currency: undefined | string;
16
+ price: undefined | number;
17
+ }
18
18
  /*****************************************************
19
19
  * Actions
20
20
  ****************************************************/
@@ -26,6 +26,7 @@ declare const reducer: import("redux").Reducer<PriceState, import("redux").AnyAc
26
26
  * Standard Selectors
27
27
  ****************************************************/
28
28
  export declare const getPrice: (state: RootState) => undefined | IPrice;
29
+ export declare const getPriceConfig: (state: RootState) => undefined | IPriceConfig;
29
30
  /*****************************************************
30
31
  * Complex Actions
31
32
  ****************************************************/
@@ -39,7 +39,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
39
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
40
  };
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
- exports.updatePrice = exports.getPrice = exports.initPrice = exports.setPrice = exports.setPriceConfig = void 0;
42
+ exports.updatePrice = exports.getPriceConfig = exports.getPrice = exports.initPrice = exports.setPrice = exports.setPriceConfig = void 0;
43
43
  var toolkit_1 = require("@reduxjs/toolkit");
44
44
  var api_1 = __importDefault(require("../api"));
45
45
  /*****************************************************
@@ -103,6 +103,13 @@ var getPrice = function (state) {
103
103
  return { price: price, currency: currency };
104
104
  };
105
105
  exports.getPrice = getPrice;
106
+ var getPriceConfig = function (state) {
107
+ var _a = state.price, id = _a.id, currency = _a.currency;
108
+ if (!id || !currency)
109
+ return undefined;
110
+ return { id: id, currency: currency };
111
+ };
112
+ exports.getPriceConfig = getPriceConfig;
106
113
  /*****************************************************
107
114
  * Complex Actions
108
115
  ****************************************************/
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@threekit-tools/treble",
3
- "version": "0.0.67",
3
+ "version": "0.0.68",
4
4
  "author": "Amaan Saeed",
5
5
  "license": "MIT",
6
6
  "files": [