tek-wallet 0.0.813 → 0.0.822

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.
Files changed (83) hide show
  1. package/dist/components/TekWallet/components/ui/AssetsBoard/index.d.ts +2 -0
  2. package/dist/components/TekWallet/components/ui/AssetsBoard/index.js +60 -0
  3. package/dist/components/TekWallet/components/ui/ChangePasscode/index.js +1 -1
  4. package/dist/components/TekWallet/components/ui/ConfirmByPasscode/index.js +4 -4
  5. package/dist/components/TekWallet/components/ui/ConfirmSendExternal/index.d.ts +2 -2
  6. package/dist/components/TekWallet/components/ui/ConfirmSendExternal/index.js +1 -1
  7. package/dist/components/TekWallet/components/ui/ConfirmSendNft/Result.d.ts +10 -0
  8. package/dist/components/TekWallet/components/ui/ConfirmSendNft/Result.js +87 -0
  9. package/dist/components/TekWallet/components/ui/ConfirmSendNft/index.d.ts +17 -0
  10. package/dist/components/TekWallet/components/ui/ConfirmSendNft/index.js +133 -0
  11. package/dist/components/TekWallet/components/ui/ConfirmSwapToken/index.d.ts +1 -1
  12. package/dist/components/TekWallet/components/ui/ConfirmSwapToken/index.js +1 -1
  13. package/dist/components/TekWallet/components/ui/DrawerComponent/index.d.ts +1 -1
  14. package/dist/components/TekWallet/components/ui/DrawerComponent/index.js +2 -1
  15. package/dist/components/TekWallet/components/ui/LoadingLayout/index.js +1 -1
  16. package/dist/components/TekWallet/components/ui/NftDetail/index.d.ts +6 -0
  17. package/dist/components/TekWallet/components/ui/NftDetail/index.js +47 -0
  18. package/dist/components/TekWallet/components/ui/NftItem/index.d.ts +8 -0
  19. package/dist/components/TekWallet/components/ui/NftItem/index.js +74 -0
  20. package/dist/components/TekWallet/components/ui/NftsBoard/index.d.ts +2 -0
  21. package/dist/components/TekWallet/components/ui/NftsBoard/index.js +118 -0
  22. package/dist/components/TekWallet/components/ui/QrCodeReader/index.js +1 -1
  23. package/dist/components/TekWallet/components/ui/ReceiveDirectly/index.js +1 -1
  24. package/dist/components/TekWallet/components/ui/ReceiveFunction/index.js +2 -2
  25. package/dist/components/TekWallet/components/ui/ReceiveHistory/index.js +1 -1
  26. package/dist/components/TekWallet/components/ui/TokensBoard/index.js +21 -44
  27. package/dist/components/TekWallet/components/ui/WithdrawFunction/index.js +1 -1
  28. package/dist/components/TekWallet/components/views/AssetView/index.js +2 -2
  29. package/dist/components/TekWallet/components/views/NftDetailView/LoadingView.d.ts +2 -0
  30. package/dist/components/TekWallet/components/views/NftDetailView/LoadingView.js +29 -0
  31. package/dist/components/TekWallet/components/views/NftDetailView/index.d.ts +8 -0
  32. package/dist/components/TekWallet/components/views/NftDetailView/index.js +20 -0
  33. package/dist/components/TekWallet/components/views/SendExternalView/index.js +1 -1
  34. package/dist/components/TekWallet/components/views/SendNftView/components/Form.d.ts +12 -0
  35. package/dist/components/TekWallet/components/views/SendNftView/components/Form.js +268 -0
  36. package/dist/components/TekWallet/components/views/SendNftView/index.d.ts +2 -0
  37. package/dist/components/TekWallet/components/views/SendNftView/index.js +32 -0
  38. package/dist/components/TekWallet/components/views/SwapView/index.js +1 -1
  39. package/dist/components/TekWallet/components/views/TekWalletView/index.d.ts +1 -0
  40. package/dist/components/TekWallet/components/views/TekWalletView/index.js +5 -0
  41. package/dist/components/TekWallet/hooks/data/useNfts/api.d.ts +5 -0
  42. package/dist/components/TekWallet/hooks/data/useNfts/api.js +83 -0
  43. package/dist/components/TekWallet/hooks/data/useNfts/index.d.ts +213 -0
  44. package/dist/components/TekWallet/hooks/data/useNfts/index.js +55 -0
  45. package/dist/components/TekWallet/hooks/data/useNfts/nftQueryKey.d.ts +5 -0
  46. package/dist/components/TekWallet/hooks/data/useNfts/nftQueryKey.js +18 -0
  47. package/dist/components/TekWallet/hooks/data/useNfts/service.type.d.ts +84 -0
  48. package/dist/components/TekWallet/hooks/data/useNfts/service.type.js +10 -0
  49. package/dist/components/TekWallet/hooks/data/useNfts/state.type.d.ts +4 -0
  50. package/dist/components/TekWallet/hooks/data/useNfts/state.type.js +2 -0
  51. package/dist/components/TekWallet/hooks/data/useNfts/useNft.d.ts +22 -0
  52. package/dist/components/TekWallet/hooks/data/useNfts/useNft.js +213 -0
  53. package/dist/components/TekWallet/hooks/data/useVouchers/service.type.d.ts +22 -0
  54. package/dist/components/TekWallet/hooks/data/useVouchers/service.type.js +14 -0
  55. package/dist/components/TekWallet/hooks/store/useQueryKeys/index.d.ts +3 -0
  56. package/dist/components/TekWallet/hooks/store/useQueryKeys/index.js +86 -0
  57. package/dist/components/TekWallet/hooks/store/useQueryKeys/type.d.ts +27 -0
  58. package/dist/components/TekWallet/hooks/store/useQueryKeys/type.js +29 -0
  59. package/dist/components/TekWallet/hooks/store/useQueryKeys/useQueryKeyDependence.d.ts +11 -0
  60. package/dist/components/TekWallet/hooks/store/useQueryKeys/useQueryKeyDependence.js +35 -0
  61. package/dist/components/TekWallet/hooks/store/useQueryKeys/useQueryKeyDependenceOnAccount.d.ts +6 -0
  62. package/dist/components/TekWallet/hooks/store/useQueryKeys/useQueryKeyDependenceOnAccount.js +25 -0
  63. package/dist/components/TekWallet/hooks/useCustomRouter.js +7 -3
  64. package/dist/components/TekWallet/hooks/utils/useEditPageQuery.d.ts +9 -0
  65. package/dist/components/TekWallet/hooks/utils/useEditPageQuery.js +86 -0
  66. package/dist/components/TekWallet/hooks/utils/useEditSinglePageQuery.d.ts +4 -0
  67. package/dist/components/TekWallet/hooks/utils/useEditSinglePageQuery.js +75 -0
  68. package/dist/components/TekWallet/providers/TanstackReactQuery/index.d.ts +4 -0
  69. package/dist/components/TekWallet/providers/TanstackReactQuery/index.js +30 -0
  70. package/dist/components/TekWallet/providers/TanstackReactQuery/query.config.d.ts +2 -0
  71. package/dist/components/TekWallet/providers/TanstackReactQuery/query.config.js +18 -0
  72. package/dist/components/TekWallet/providers/TekWalletProvider/index.d.ts +1 -0
  73. package/dist/components/TekWallet/providers/TekWalletProvider/index.js +3 -1
  74. package/dist/components/TekWallet/services/axios/clients/userClientRequest.d.ts +2 -2
  75. package/dist/components/TekWallet/services/axios/clients/userClientRequest.js +3 -3
  76. package/dist/components/TekWallet/services/axios/type.d.ts +11 -0
  77. package/dist/components/TekWallet/theme/mui/components/index.d.ts +1 -15
  78. package/dist/components/TekWallet/theme/mui/components/overrides/Button.d.ts +1 -15
  79. package/dist/components/TekWallet/theme/mui/components/overrides/Button.js +3 -8
  80. package/dist/components/TekWallet/theme/mui/palette.d.ts +10 -4
  81. package/dist/components/TekWallet/theme/mui/palette.js +6 -1
  82. package/dist/components/TekWallet/utils/getContractColor.d.ts +1 -1
  83. package/package.json +5 -2
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __rest = (this && this.__rest) || function (s, e) {
14
+ var t = {};
15
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16
+ t[p] = s[p];
17
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
18
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
19
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
20
+ t[p[i]] = s[p[i]];
21
+ }
22
+ return t;
23
+ };
24
+ var __importDefault = (this && this.__importDefault) || function (mod) {
25
+ return (mod && mod.__esModule) ? mod : { "default": mod };
26
+ };
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ var react_query_1 = require("@tanstack/react-query");
29
+ var api_1 = require("./api");
30
+ var useQueryKeyDependenceOnAccount_1 = __importDefault(require("../../store/useQueryKeys/useQueryKeyDependenceOnAccount"));
31
+ var type_1 = require("../../store/useQueryKeys/type");
32
+ var react_1 = require("react");
33
+ var LIMIT = 20;
34
+ function useNfts(enabled) {
35
+ if (enabled === void 0) { enabled = true; }
36
+ var _a = (0, useQueryKeyDependenceOnAccount_1.default)(type_1.QueryKeyNames.NFTs), queryKeyAccount = _a.queryKey, isReadyAccount = _a.isReady;
37
+ var _b = (0, react_query_1.useInfiniteQuery)({
38
+ queryKey: queryKeyAccount,
39
+ queryFn: function (_a) {
40
+ var pageParam = _a.pageParam;
41
+ return (0, api_1.getNftsServices)({ limit: LIMIT, cursor: pageParam });
42
+ },
43
+ getNextPageParam: function (lastPage) {
44
+ var _a;
45
+ return (_a = lastPage === null || lastPage === void 0 ? void 0 : lastPage.paginated) === null || _a === void 0 ? void 0 : _a.cursor;
46
+ },
47
+ initialPageParam: undefined,
48
+ enabled: enabled && isReadyAccount,
49
+ }), data = _b.data, rest = __rest(_b, ["data"]);
50
+ var nfts = (0, react_1.useMemo)(function () {
51
+ return (data === null || data === void 0 ? void 0 : data.pages.flatMap(function (page) { var _a; return (_a = page === null || page === void 0 ? void 0 : page.data) === null || _a === void 0 ? void 0 : _a.nfts; })) || [];
52
+ }, [data]);
53
+ return __assign({ nfts: nfts }, rest);
54
+ }
55
+ exports.default = useNfts;
@@ -0,0 +1,5 @@
1
+ import { NftListParams } from "./state.type";
2
+ export declare const NftQueryKey: {
3
+ all: readonly ["nfts"];
4
+ list: (params: NftListParams) => readonly ["nfts", string | undefined, string | undefined];
5
+ };
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
+ if (ar || !(i in from)) {
5
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
+ ar[i] = from[i];
7
+ }
8
+ }
9
+ return to.concat(ar || Array.prototype.slice.call(from));
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.NftQueryKey = void 0;
13
+ exports.NftQueryKey = {
14
+ all: ["nfts"],
15
+ list: function (params) {
16
+ return __spreadArray(__spreadArray([], exports.NftQueryKey.all, true), [params === null || params === void 0 ? void 0 : params.search, params === null || params === void 0 ? void 0 : params.accessToken], false);
17
+ },
18
+ };
@@ -0,0 +1,84 @@
1
+ import { Cursor } from "../../../services/axios/type";
2
+ import { NetworkData } from "../../../services/axios/expose";
3
+ export interface GetNftsServiceQuery {
4
+ cursor?: string;
5
+ limit?: number;
6
+ keyword?: string;
7
+ }
8
+ export interface GetNftsServiceResponse {
9
+ success: boolean;
10
+ message: string;
11
+ data: NftData;
12
+ timestamp: string;
13
+ }
14
+ export interface NftData {
15
+ nfts: Nft[];
16
+ paginated: Cursor;
17
+ }
18
+ export declare enum NftStatus {
19
+ MINTED = "minted",
20
+ UNMINTED = "unminted",
21
+ MINTING = "minting",
22
+ SENDING = "sending"
23
+ }
24
+ export interface Nft {
25
+ animation_url: null;
26
+ external_app_url: null;
27
+ id: string;
28
+ image_url: string;
29
+ is_unique: boolean;
30
+ media_type: null;
31
+ media_url: string;
32
+ metadata: Metadata;
33
+ owner: Owner;
34
+ thumbnails: null;
35
+ token: Token;
36
+ token_type: string;
37
+ value: string;
38
+ status: NftStatus;
39
+ network: NetworkData;
40
+ }
41
+ export interface Token {
42
+ address_hash: string;
43
+ circulating_market_cap: null;
44
+ decimals: null;
45
+ exchange_rate: null;
46
+ holders_count: string;
47
+ icon_url: null;
48
+ name: string;
49
+ symbol: string;
50
+ total_supply: string;
51
+ type: string;
52
+ volume_24h: null;
53
+ }
54
+ export interface Owner {
55
+ ens_domain_name: null;
56
+ hash: string;
57
+ implementations: any[];
58
+ is_contract: boolean;
59
+ is_scam: boolean;
60
+ is_verified: boolean;
61
+ metadata: null;
62
+ name: null;
63
+ private_tags: any[];
64
+ proxy_type: null;
65
+ public_tags: any[];
66
+ watchlist_names: any[];
67
+ }
68
+ export interface Metadata {
69
+ attributes: Attribute[];
70
+ image: string;
71
+ }
72
+ export interface Attribute {
73
+ trait_type: string;
74
+ value?: string;
75
+ }
76
+ export interface NftActionPayload {
77
+ id: string;
78
+ }
79
+ export interface MintNfsPayload extends NftActionPayload {
80
+ }
81
+ export interface SendNftPayload extends NftActionPayload {
82
+ to_address: string;
83
+ passcode: string;
84
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NftStatus = void 0;
4
+ var NftStatus;
5
+ (function (NftStatus) {
6
+ NftStatus["MINTED"] = "minted";
7
+ NftStatus["UNMINTED"] = "unminted";
8
+ NftStatus["MINTING"] = "minting";
9
+ NftStatus["SENDING"] = "sending";
10
+ })(NftStatus || (exports.NftStatus = NftStatus = {}));
@@ -0,0 +1,4 @@
1
+ export interface NftListParams {
2
+ search?: string;
3
+ accessToken?: string;
4
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,22 @@
1
+ import { Nft, GetNftsServiceResponse, SendNftPayload } from "./service.type";
2
+ import { ReactEventHandler } from "react";
3
+ import { Voucher } from "../useVouchers/service.type";
4
+ import { InfiniteData } from "@tanstack/react-query";
5
+ import { Transaction } from "../../../services/axios/get-activities-service/type";
6
+ type MintNftContext = {
7
+ previousData?: InfiniteData<GetNftsServiceResponse>;
8
+ };
9
+ declare function useNft(id?: string, useSnapshot?: boolean): {
10
+ metadataAttributes: Voucher | null;
11
+ mintNft: import("@tanstack/react-query").UseMutationResult<Nft, Error, void, MintNftContext>;
12
+ sendNft: import("@tanstack/react-query").UseMutationResult<Transaction, Error, SendNftPayload, MintNftContext>;
13
+ voucherUnit: string;
14
+ voucherValue: number | undefined;
15
+ isMinting: boolean;
16
+ isMinted: boolean;
17
+ isSending: boolean;
18
+ handleClickButton: ReactEventHandler;
19
+ buttonLabel: string;
20
+ network: import("../../../services/axios/type").NetworkData | undefined;
21
+ };
22
+ export default useNft;
@@ -0,0 +1,213 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
24
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __importDefault = (this && this.__importDefault) || function (mod) {
50
+ return (mod && mod.__esModule) ? mod : { "default": mod };
51
+ };
52
+ Object.defineProperty(exports, "__esModule", { value: true });
53
+ var useQueryKeys_1 = __importDefault(require("../../store/useQueryKeys"));
54
+ var type_1 = require("../../store/useQueryKeys/type");
55
+ var service_type_1 = require("./service.type");
56
+ var react_1 = require("react");
57
+ var service_type_2 = require("../useVouchers/service.type");
58
+ var react_query_1 = require("@tanstack/react-query");
59
+ var api_1 = require("./api");
60
+ var useEditPageQuery_1 = __importDefault(require("../../utils/useEditPageQuery"));
61
+ var useRealtime_1 = __importDefault(require("../../useRealtime"));
62
+ var useCustomRouter_1 = __importDefault(require("../../useCustomRouter"));
63
+ var providers_1 = require("../../../providers");
64
+ var _1 = __importDefault(require("."));
65
+ function useNft(id, useSnapshot) {
66
+ var _this = this;
67
+ if (useSnapshot === void 0) { useSnapshot = false; }
68
+ var queryKey = (0, useQueryKeys_1.default)(function (state) { return state.getQueryKey(type_1.QueryKeyNames.NFTs); });
69
+ var options = (0, providers_1.useWalletSetup)().options;
70
+ var snapshotNft = (0, react_1.useRef)(undefined);
71
+ var basePath = options === null || options === void 0 ? void 0 : options.basePath;
72
+ var editPageQuery = (0, useEditPageQuery_1.default)().editPageQuery;
73
+ var queryClient = (0, react_query_1.useQueryClient)();
74
+ var pushNotification = (0, useRealtime_1.default)().pushNotification;
75
+ var router = (0, useCustomRouter_1.default)();
76
+ var nfts = (0, _1.default)().nfts;
77
+ var nft = (0, react_1.useMemo)(function () {
78
+ var matchedNft = nfts === null || nfts === void 0 ? void 0 : nfts.find(function (item) { return (item === null || item === void 0 ? void 0 : item.id) === id; });
79
+ if (useSnapshot && matchedNft) {
80
+ snapshotNft.current = matchedNft;
81
+ }
82
+ return useSnapshot ? snapshotNft.current : matchedNft;
83
+ }, [id, nfts, useSnapshot]);
84
+ var metadata = (nft || {}).metadata;
85
+ var metadataAttributes = (0, react_1.useMemo)(function () {
86
+ if (!metadata)
87
+ return null;
88
+ var attributes = metadata.attributes;
89
+ var result = attributes.reduce(function (acc, attribute) {
90
+ acc[attribute.trait_type] = attribute.value;
91
+ return acc;
92
+ }, {});
93
+ return result; // in this phase we use nft metadata for voucher data
94
+ }, [metadata]);
95
+ var mintNft = (0, react_query_1.useMutation)({
96
+ mutationFn: function () { return (0, api_1.mintNftServices)({ id: nft === null || nft === void 0 ? void 0 : nft.id }); },
97
+ onMutate: function () { return __awaiter(_this, void 0, void 0, function () {
98
+ var previousData;
99
+ return __generator(this, function (_a) {
100
+ switch (_a.label) {
101
+ case 0: return [4 /*yield*/, editPageQuery(queryKey, function (page) {
102
+ var _a, _b;
103
+ return __assign(__assign({}, page), { data: __assign(__assign({}, page === null || page === void 0 ? void 0 : page.data), { nfts: (_b = (_a = page === null || page === void 0 ? void 0 : page.data) === null || _a === void 0 ? void 0 : _a.nfts) === null || _b === void 0 ? void 0 : _b.map(function (item) {
104
+ return item.id === (nft === null || nft === void 0 ? void 0 : nft.id) ? __assign(__assign({}, item), { status: service_type_1.NftStatus.MINTING }) : item;
105
+ }) }) });
106
+ })];
107
+ case 1:
108
+ previousData = (_a.sent()).previousData;
109
+ return [2 /*return*/, { previousData: previousData }];
110
+ }
111
+ });
112
+ }); },
113
+ onSuccess: function (newNft) {
114
+ pushNotification({
115
+ id: "nft-minted-".concat(newNft.id),
116
+ message: "Claiming voucher successfully",
117
+ type: "success",
118
+ });
119
+ editPageQuery(queryKey, function (page) {
120
+ var _a, _b;
121
+ return __assign(__assign({}, page), { data: __assign(__assign({}, page === null || page === void 0 ? void 0 : page.data), { nfts: (_b = (_a = page === null || page === void 0 ? void 0 : page.data) === null || _a === void 0 ? void 0 : _a.nfts) === null || _b === void 0 ? void 0 : _b.map(function (item) { return (item.id === (nft === null || nft === void 0 ? void 0 : nft.id) ? newNft : item); }) }) });
122
+ });
123
+ },
124
+ onError: function (_, __, context) {
125
+ pushNotification({
126
+ id: "nft-minted-".concat(nft === null || nft === void 0 ? void 0 : nft.id),
127
+ message: "Claiming voucher failed",
128
+ type: "error",
129
+ });
130
+ if (context === null || context === void 0 ? void 0 : context.previousData) {
131
+ queryClient.setQueryData(queryKey, context.previousData);
132
+ }
133
+ },
134
+ });
135
+ var sendNft = (0, react_query_1.useMutation)({
136
+ mutationFn: function (payload) { return (0, api_1.sendNftServices)(payload); },
137
+ onMutate: function () { return __awaiter(_this, void 0, void 0, function () {
138
+ var previousData;
139
+ return __generator(this, function (_a) {
140
+ switch (_a.label) {
141
+ case 0: return [4 /*yield*/, editPageQuery(queryKey, function (page) {
142
+ var _a, _b;
143
+ return __assign(__assign({}, page), { data: __assign(__assign({}, page === null || page === void 0 ? void 0 : page.data), { nfts: (_b = (_a = page === null || page === void 0 ? void 0 : page.data) === null || _a === void 0 ? void 0 : _a.nfts) === null || _b === void 0 ? void 0 : _b.map(function (item) {
144
+ return item.id === (nft === null || nft === void 0 ? void 0 : nft.id) ? __assign(__assign({}, item), { status: service_type_1.NftStatus.SENDING }) : item;
145
+ }) }) });
146
+ })];
147
+ case 1:
148
+ previousData = (_a.sent()).previousData;
149
+ return [2 /*return*/, { previousData: previousData }];
150
+ }
151
+ });
152
+ }); },
153
+ onSuccess: function (transaction, variables) {
154
+ editPageQuery(queryKey, function (page) {
155
+ var _a, _b;
156
+ return __assign(__assign({}, page), { data: __assign(__assign({}, page === null || page === void 0 ? void 0 : page.data), { nfts: (_b = (_a = page === null || page === void 0 ? void 0 : page.data) === null || _a === void 0 ? void 0 : _a.nfts) === null || _b === void 0 ? void 0 : _b.filter(function (item) { return item.id !== (variables === null || variables === void 0 ? void 0 : variables.id); }) }) });
157
+ });
158
+ },
159
+ onError: function (_, __, context) {
160
+ pushNotification({
161
+ id: "nft-sent-".concat(nft === null || nft === void 0 ? void 0 : nft.id),
162
+ message: "Sending NFT failed",
163
+ type: "error",
164
+ });
165
+ if (context === null || context === void 0 ? void 0 : context.previousData) {
166
+ queryClient.setQueryData(queryKey, context.previousData);
167
+ }
168
+ },
169
+ });
170
+ var voucherUnit = (metadataAttributes === null || metadataAttributes === void 0 ? void 0 : metadataAttributes.type) === service_type_2.VoucherType.PERCENT ? "%" : "";
171
+ var voucherValue = metadataAttributes === null || metadataAttributes === void 0 ? void 0 : metadataAttributes.amount;
172
+ var isMinting = (0, react_1.useMemo)(function () { return (nft === null || nft === void 0 ? void 0 : nft.status) === service_type_1.NftStatus.MINTING; }, [nft]);
173
+ var isSending = (0, react_1.useMemo)(function () { return (nft === null || nft === void 0 ? void 0 : nft.status) === service_type_1.NftStatus.SENDING; }, [nft]);
174
+ var isMinted = (0, react_1.useMemo)(function () { return (nft === null || nft === void 0 ? void 0 : nft.status) === service_type_1.NftStatus.MINTED; }, [nft]);
175
+ var network = (0, react_1.useMemo)(function () { return nft === null || nft === void 0 ? void 0 : nft.network; }, [nft]);
176
+ var buttonLabel = (0, react_1.useMemo)(function () {
177
+ switch (true) {
178
+ case isMinted:
179
+ return "Use";
180
+ case isMinting:
181
+ return "Claim"; // it is loading state, so we don't need to show the loading label as Claiming
182
+ case isSending:
183
+ return "Sending..."; // it is loading state, so we don't need to show the loading label as Sending
184
+ default:
185
+ return "Claim";
186
+ }
187
+ }, [isMinted, isMinting, isSending]);
188
+ var handleClickButton = (0, react_1.useCallback)(function (e) {
189
+ e.preventDefault();
190
+ e.stopPropagation();
191
+ if (isMinting || isSending)
192
+ return;
193
+ if (isMinted) {
194
+ router.push("".concat(basePath || "", "/tek-wallet/send/nft?id=").concat(nft === null || nft === void 0 ? void 0 : nft.id));
195
+ return;
196
+ }
197
+ mintNft.mutate();
198
+ }, [mintNft, isMinting, isSending, isMinted, router, nft === null || nft === void 0 ? void 0 : nft.id, basePath]);
199
+ return {
200
+ metadataAttributes: metadataAttributes,
201
+ mintNft: mintNft,
202
+ sendNft: sendNft,
203
+ voucherUnit: voucherUnit,
204
+ voucherValue: voucherValue,
205
+ isMinting: isMinting,
206
+ isMinted: isMinted,
207
+ isSending: isSending,
208
+ handleClickButton: handleClickButton,
209
+ buttonLabel: buttonLabel,
210
+ network: network,
211
+ };
212
+ }
213
+ exports.default = useNft;
@@ -0,0 +1,22 @@
1
+ export declare enum VoucherType {
2
+ PERCENT = "percent",
3
+ FIXED = "fixed"
4
+ }
5
+ export declare enum VoucherStatus {
6
+ DRAFT = "draft",
7
+ PUBLISHED = "published",
8
+ ARCHIVED = "archived"
9
+ }
10
+ export interface Voucher {
11
+ id: number;
12
+ status: VoucherStatus;
13
+ title: string;
14
+ description: string;
15
+ image: string;
16
+ expire: string;
17
+ type: string;
18
+ amount: number;
19
+ tag: string;
20
+ date_created: string;
21
+ date_updated: string;
22
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VoucherStatus = exports.VoucherType = void 0;
4
+ var VoucherType;
5
+ (function (VoucherType) {
6
+ VoucherType["PERCENT"] = "percent";
7
+ VoucherType["FIXED"] = "fixed";
8
+ })(VoucherType || (exports.VoucherType = VoucherType = {}));
9
+ var VoucherStatus;
10
+ (function (VoucherStatus) {
11
+ VoucherStatus["DRAFT"] = "draft";
12
+ VoucherStatus["PUBLISHED"] = "published";
13
+ VoucherStatus["ARCHIVED"] = "archived";
14
+ })(VoucherStatus || (exports.VoucherStatus = VoucherStatus = {}));
@@ -0,0 +1,3 @@
1
+ import { UseQueryKeysStore } from "./type";
2
+ declare const useQueryKeysStore: import("zustand").UseBoundStore<import("zustand").StoreApi<UseQueryKeysStore>>;
3
+ export default useQueryKeysStore;
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ "use client";
3
+ var __assign = (this && this.__assign) || function () {
4
+ __assign = Object.assign || function(t) {
5
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
6
+ s = arguments[i];
7
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
8
+ t[p] = s[p];
9
+ }
10
+ return t;
11
+ };
12
+ return __assign.apply(this, arguments);
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ var zustand_1 = require("zustand");
16
+ var type_1 = require("./type");
17
+ var createInitialQueryKeys = function () {
18
+ return Object.values(type_1.QueryKeyNames).reduce(function (acc, queryKeyName) {
19
+ acc[queryKeyName] = (0, type_1.createQueryKeyRecord)(queryKeyName);
20
+ return acc;
21
+ }, {});
22
+ };
23
+ var ensureDefaultFields = function (map, name) {
24
+ type_1.DEFAULT_QUERY_KEY_FIELDS.forEach(function (field) {
25
+ if (field === "name") {
26
+ map.set(field, name);
27
+ return;
28
+ }
29
+ if (!map.has(field)) {
30
+ map.set(field, "");
31
+ }
32
+ });
33
+ return map;
34
+ };
35
+ var initialQueryKeys = createInitialQueryKeys();
36
+ var useQueryKeysStore = (0, zustand_1.create)(function (set, get) { return ({
37
+ queryKeys: initialQueryKeys,
38
+ setQueryKey: function (queryKeyName, payload) {
39
+ set(function (state) {
40
+ var _a;
41
+ var _b;
42
+ var currentRecord = (_b = state.queryKeys[queryKeyName]) !== null && _b !== void 0 ? _b : (0, type_1.createQueryKeyRecord)(queryKeyName);
43
+ var workingMap = (0, type_1.cloneQueryKeyMap)(currentRecord.map);
44
+ var updatedMap = typeof payload === "function" ? payload(workingMap) : (0, type_1.cloneQueryKeyMap)(payload);
45
+ ensureDefaultFields(updatedMap, queryKeyName);
46
+ return {
47
+ queryKeys: __assign(__assign({}, state.queryKeys), (_a = {}, _a[queryKeyName] = {
48
+ map: updatedMap,
49
+ array: (0, type_1.mapToArray)(updatedMap),
50
+ }, _a)),
51
+ };
52
+ });
53
+ },
54
+ getQueryKey: function (queryKeyName) {
55
+ var _a;
56
+ var record = (_a = get().queryKeys[queryKeyName]) !== null && _a !== void 0 ? _a : (0, type_1.createQueryKeyRecord)(queryKeyName);
57
+ return record.array;
58
+ },
59
+ getQueryKeyMap: function (queryKeyName) {
60
+ var _a;
61
+ var record = (_a = get().queryKeys[queryKeyName]) !== null && _a !== void 0 ? _a : (0, type_1.createQueryKeyRecord)(queryKeyName);
62
+ return record.map;
63
+ },
64
+ setQueryFields: function (queryKeyName, fields) {
65
+ set(function (state) {
66
+ var _a;
67
+ var _b;
68
+ var currentRecord = (_b = state.queryKeys[queryKeyName]) !== null && _b !== void 0 ? _b : (0, type_1.createQueryKeyRecord)(queryKeyName);
69
+ var workingMap = (0, type_1.cloneQueryKeyMap)(currentRecord.map);
70
+ Object.entries(fields).forEach(function (_a) {
71
+ var key = _a[0], value = _a[1];
72
+ if (key === "name")
73
+ return;
74
+ workingMap.set(key, value);
75
+ });
76
+ ensureDefaultFields(workingMap, queryKeyName);
77
+ return {
78
+ queryKeys: __assign(__assign({}, state.queryKeys), (_a = {}, _a[queryKeyName] = {
79
+ map: workingMap,
80
+ array: (0, type_1.mapToArray)(workingMap),
81
+ }, _a)),
82
+ };
83
+ });
84
+ },
85
+ }); });
86
+ exports.default = useQueryKeysStore;
@@ -0,0 +1,27 @@
1
+ export declare const QueryKeyNames: {
2
+ readonly NFTs: "nfts";
3
+ };
4
+ export type QueryKeyName = (typeof QueryKeyNames)[keyof typeof QueryKeyNames];
5
+ export type DefaultQueryKeyFields = {
6
+ name: QueryKeyName;
7
+ };
8
+ export type QueryKeyMap = Map<string, unknown>;
9
+ export type QueryKeyArray = unknown[];
10
+ export type QueryKeyRecord = {
11
+ map: QueryKeyMap;
12
+ array: QueryKeyArray;
13
+ };
14
+ export type UpdateQueryKey = (prev: QueryKeyMap) => QueryKeyMap;
15
+ export type QueryKeys = Record<QueryKeyName, QueryKeyRecord>;
16
+ export interface UseQueryKeysStore {
17
+ queryKeys: QueryKeys;
18
+ setQueryKey: (queryKey: QueryKeyName, value: QueryKeyMap | UpdateQueryKey) => void;
19
+ getQueryKey: (queryKey: QueryKeyName) => QueryKeyArray;
20
+ getQueryKeyMap: (queryKey: QueryKeyName) => QueryKeyMap;
21
+ setQueryFields: (queryKey: QueryKeyName, fields: Record<string, unknown>) => void;
22
+ }
23
+ export declare const DEFAULT_QUERY_KEY_FIELDS: Array<keyof DefaultQueryKeyFields>;
24
+ export declare const createQueryKeyMap: (name: QueryKeyName) => QueryKeyMap;
25
+ export declare const cloneQueryKeyMap: (map: QueryKeyMap) => QueryKeyMap;
26
+ export declare const mapToArray: (map: QueryKeyMap) => QueryKeyArray;
27
+ export declare const createQueryKeyRecord: (name: QueryKeyName) => QueryKeyRecord;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createQueryKeyRecord = exports.mapToArray = exports.cloneQueryKeyMap = exports.createQueryKeyMap = exports.DEFAULT_QUERY_KEY_FIELDS = exports.QueryKeyNames = void 0;
4
+ exports.QueryKeyNames = {
5
+ NFTs: "nfts",
6
+ };
7
+ exports.DEFAULT_QUERY_KEY_FIELDS = ["name"];
8
+ var createQueryKeyMap = function (name) {
9
+ var map = new Map();
10
+ map.set("name", name);
11
+ return map;
12
+ };
13
+ exports.createQueryKeyMap = createQueryKeyMap;
14
+ var cloneQueryKeyMap = function (map) {
15
+ return new Map(map);
16
+ };
17
+ exports.cloneQueryKeyMap = cloneQueryKeyMap;
18
+ var mapToArray = function (map) {
19
+ return Array.from(map.entries());
20
+ };
21
+ exports.mapToArray = mapToArray;
22
+ var createQueryKeyRecord = function (name) {
23
+ var map = (0, exports.createQueryKeyMap)(name);
24
+ return {
25
+ map: map,
26
+ array: (0, exports.mapToArray)(map),
27
+ };
28
+ };
29
+ exports.createQueryKeyRecord = createQueryKeyRecord;
@@ -0,0 +1,11 @@
1
+ import { QueryKeyName } from "./type";
2
+ export interface QueryKeyDependence {
3
+ value: unknown;
4
+ requiredToReady?: boolean;
5
+ requiredTruthyValue?: boolean;
6
+ }
7
+ declare function useQueryKeyDependence(name: QueryKeyName, dependencies: Record<string, QueryKeyDependence>, enabledTracking?: boolean): {
8
+ queryKey: import("./type").QueryKeyArray;
9
+ isReady: boolean | undefined;
10
+ };
11
+ export default useQueryKeyDependence;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ var react_1 = require("react");
7
+ var _1 = __importDefault(require("./"));
8
+ function useQueryKeyDependence(name, dependencies, enabledTracking) {
9
+ var queryKey = (0, _1.default)(function (state) { return state.getQueryKey(name); });
10
+ var queryKeyMap = (0, _1.default)(function (state) { return state.getQueryKeyMap(name); });
11
+ var setQueryFields = (0, _1.default)(function (state) { return state.setQueryFields; });
12
+ var isReady = (0, react_1.useMemo)(function () {
13
+ return (enabledTracking &&
14
+ Object.keys(dependencies).every(function (dependency) {
15
+ return (!dependencies[dependency].requiredToReady ||
16
+ (!!dependencies[dependency].requiredToReady && queryKeyMap.has(dependency))) &&
17
+ (!dependencies[dependency].requiredTruthyValue ||
18
+ (!!dependencies[dependency].requiredTruthyValue && !!dependencies[dependency].value));
19
+ }));
20
+ }, [dependencies, queryKeyMap, enabledTracking]);
21
+ (0, react_1.useEffect)(function () {
22
+ if (!enabledTracking)
23
+ return;
24
+ var dependenciesObject = Object.keys(dependencies).reduce(function (acc, key) {
25
+ acc[key] = dependencies[key].value;
26
+ return acc;
27
+ }, {});
28
+ setQueryFields(name, dependenciesObject);
29
+ }, [dependencies, name, setQueryFields, enabledTracking]);
30
+ return {
31
+ queryKey: queryKey,
32
+ isReady: isReady,
33
+ };
34
+ }
35
+ exports.default = useQueryKeyDependence;