@suilend/sui-fe 0.3.53 → 0.4.1

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
@@ -1,17 +1 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./lib"), exports);
1
+ export * from "./lib";
package/lib/api.js CHANGED
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,10 +7,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
8
  });
10
9
  };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.getHistoryPrice = exports.getPrice = void 0;
13
- const coinType_1 = require("./coinType");
14
- const constants_1 = require("./constants");
10
+ import { SUI_COINTYPE, isSui } from "./coinType";
11
+ import { API_URL } from "./constants";
15
12
  // Date helper functions
16
13
  const getHours = (date) => date.getHours();
17
14
  const getMinutes = (date) => date.getMinutes();
@@ -31,10 +28,10 @@ const setSeconds = (date, seconds) => {
31
28
  result.setSeconds(seconds);
32
29
  return result;
33
30
  };
34
- const getPrice = (coinType) => __awaiter(void 0, void 0, void 0, function* () {
31
+ export const getPrice = (coinType) => __awaiter(void 0, void 0, void 0, function* () {
35
32
  try {
36
- const url = `${constants_1.API_URL}/proxy/price?${new URLSearchParams({
37
- address: (0, coinType_1.isSui)(coinType) ? coinType_1.SUI_COINTYPE : coinType,
33
+ const url = `${API_URL}/proxy/price?${new URLSearchParams({
34
+ address: isSui(coinType) ? SUI_COINTYPE : coinType,
38
35
  })}`;
39
36
  const res = yield fetch(url);
40
37
  const json = yield res.json();
@@ -47,8 +44,7 @@ const getPrice = (coinType) => __awaiter(void 0, void 0, void 0, function* () {
47
44
  return undefined;
48
45
  }
49
46
  });
50
- exports.getPrice = getPrice;
51
- const getHistoryPrice = (coinType, interval, timeFromS, timeToS) => __awaiter(void 0, void 0, void 0, function* () {
47
+ export const getHistoryPrice = (coinType, interval, timeFromS, timeToS) => __awaiter(void 0, void 0, void 0, function* () {
52
48
  let timeFrom = new Date(timeFromS * 1000);
53
49
  timeFrom = setHours(timeFrom, getHours(timeFrom) - (getHours(timeFrom) % 3));
54
50
  timeFrom = setMinutes(timeFrom, 0);
@@ -60,8 +56,8 @@ const getHistoryPrice = (coinType, interval, timeFromS, timeToS) => __awaiter(vo
60
56
  const processedTimeFromS = Math.floor(timeFrom.getTime() / 1000);
61
57
  const processedTimeToS = Math.floor(timeTo.getTime() / 1000);
62
58
  try {
63
- const url = `${constants_1.API_URL}/proxy/history-price?${new URLSearchParams({
64
- address: (0, coinType_1.isSui)(coinType) ? coinType_1.SUI_COINTYPE : coinType,
59
+ const url = `${API_URL}/proxy/history-price?${new URLSearchParams({
60
+ address: isSui(coinType) ? SUI_COINTYPE : coinType,
65
61
  type: interval,
66
62
  time_from: `${processedTimeFromS}`,
67
63
  time_to: `${processedTimeToS}`,
@@ -78,4 +74,3 @@ const getHistoryPrice = (coinType, interval, timeFromS, timeToS) => __awaiter(vo
78
74
  return undefined;
79
75
  }
80
76
  });
81
- exports.getHistoryPrice = getHistoryPrice;
package/lib/coin.js CHANGED
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BLACKLISTED_WORDS = void 0;
4
- exports.BLACKLISTED_WORDS = [
1
+ export const BLACKLISTED_WORDS = [
5
2
  // Sui
6
3
  "sui",
7
4
  "suilend",
@@ -1,4 +1,4 @@
1
- import { CoinMetadata } from "@mysten/sui/client";
1
+ import { CoinMetadata } from "@mysten/sui/jsonRpc";
2
2
  export type Token = CoinMetadata & {
3
3
  coinType: string;
4
4
  raw?: CoinMetadata;
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,41 +7,35 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
8
  });
10
9
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
10
  var _a;
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.removeCoinMetadataFromIndexedDB = exports.getCoinMetadataMap = exports.getToken = void 0;
17
- const lodash_1 = require("lodash");
18
- const p_limit_1 = __importDefault(require("p-limit"));
19
- const coinType_1 = require("./coinType");
20
- const constants_1 = require("./constants");
21
- const indexedDB_1 = require("./indexedDB");
11
+ import { chunk } from "lodash";
12
+ import pLimit from "p-limit";
13
+ import { COINTYPE_LOGO_MAP, COINTYPE_SYMBOL_MAP, extractCTokenCoinType, extractSymbolFromCoinType, isCTokenCoinType, isCoinType, } from "./coinType";
14
+ import { API_URL } from "./constants";
15
+ import { getTokenMapByCoinTypeFromIndexedDB, removeTokensFromIndexedDB, setTokenMapToIndexedDB, } from "./indexedDB";
22
16
  const CHUNK_SIZE = +((_a = process.env.NEXT_PUBLIC_COIN_METADATA_CHUNK_SIZE) !== null && _a !== void 0 ? _a : 50);
23
- const getToken = (coinType, coinMetadata) => (Object.assign({ coinType }, coinMetadata));
24
- exports.getToken = getToken;
25
- const getCoinMetadataMap = (uniqueCoinTypes) => __awaiter(void 0, void 0, void 0, function* () {
17
+ export const getToken = (coinType, coinMetadata) => (Object.assign({ coinType }, coinMetadata));
18
+ export const getCoinMetadataMap = (uniqueCoinTypes) => __awaiter(void 0, void 0, void 0, function* () {
26
19
  var _a, _b, _c;
27
- const validUniqueCoinTypes = uniqueCoinTypes.filter(coinType_1.isCoinType);
20
+ const validUniqueCoinTypes = uniqueCoinTypes.filter(isCoinType);
28
21
  if (validUniqueCoinTypes.length === 0)
29
22
  return {};
30
- const coinTypesToFetch = Array.from(new Set(validUniqueCoinTypes.map((coinType) => (0, coinType_1.isCTokenCoinType)(coinType) ? (0, coinType_1.extractCTokenCoinType)(coinType) : coinType))); // May contain duplicates
23
+ const coinTypesToFetch = Array.from(new Set(validUniqueCoinTypes.map((coinType) => isCTokenCoinType(coinType) ? extractCTokenCoinType(coinType) : coinType))); // May contain duplicates
31
24
  try {
32
25
  // Get cached tokens
33
26
  let cachedTokenMap = {};
34
27
  try {
35
28
  cachedTokenMap =
36
- yield (0, indexedDB_1.getTokenMapByCoinTypeFromIndexedDB)(coinTypesToFetch);
29
+ yield getTokenMapByCoinTypeFromIndexedDB(coinTypesToFetch);
37
30
  }
38
31
  catch (err) {
39
32
  // Silently fail if IndexedDB is not available
40
33
  }
41
34
  // Fetch new tokens from API
42
- const coinTypeChunks = (0, lodash_1.chunk)(coinTypesToFetch.filter((coinType) => !cachedTokenMap[coinType]), CHUNK_SIZE);
43
- const limit = (0, p_limit_1.default)(5);
35
+ const coinTypeChunks = chunk(coinTypesToFetch.filter((coinType) => !cachedTokenMap[coinType]), CHUNK_SIZE);
36
+ const limit = pLimit(5);
44
37
  const newTokens = (yield Promise.all(coinTypeChunks.map((coinTypeChunk) => limit(() => __awaiter(void 0, void 0, void 0, function* () {
45
- const url = `${constants_1.API_URL}/steamm/coins?${new URLSearchParams({
38
+ const url = `${API_URL}/steamm/coins?${new URLSearchParams({
46
39
  coinTypes: coinTypeChunk.join(","),
47
40
  })}`;
48
41
  const res = yield fetch(url);
@@ -52,7 +45,7 @@ const getCoinMetadataMap = (uniqueCoinTypes) => __awaiter(void 0, void 0, void 0
52
45
  // Store new tokens in IndexedDB
53
46
  const newTokenMap = newTokens.reduce((acc, token) => (Object.assign(Object.assign({}, acc), { [token.coinType]: token })), {});
54
47
  try {
55
- yield (0, indexedDB_1.setTokenMapToIndexedDB)(newTokenMap);
48
+ yield setTokenMapToIndexedDB(newTokenMap);
56
49
  }
57
50
  catch (err) {
58
51
  // Silently fail if IndexedDB is not available
@@ -62,17 +55,17 @@ const getCoinMetadataMap = (uniqueCoinTypes) => __awaiter(void 0, void 0, void 0
62
55
  //
63
56
  const tokenMap = {};
64
57
  for (let i = 0; i < validUniqueCoinTypes.length; i++) {
65
- const coinType = (0, coinType_1.isCTokenCoinType)(validUniqueCoinTypes[i])
66
- ? (0, coinType_1.extractCTokenCoinType)(validUniqueCoinTypes[i])
58
+ const coinType = isCTokenCoinType(validUniqueCoinTypes[i])
59
+ ? extractCTokenCoinType(validUniqueCoinTypes[i])
67
60
  : validUniqueCoinTypes[i];
68
61
  const token = combinedTokenMap[coinType];
69
62
  if (!token)
70
63
  throw new Error(`Missing metadata for ${coinType}`);
71
- tokenMap[validUniqueCoinTypes[i]] = Object.assign(Object.assign({}, token), { iconUrl: (_a = coinType_1.COINTYPE_LOGO_MAP[(0, coinType_1.isCTokenCoinType)(coinType)
72
- ? (0, coinType_1.extractCTokenCoinType)(coinType)
73
- : coinType]) !== null && _a !== void 0 ? _a : token.iconUrl, symbol: (_c = (_b = coinType_1.COINTYPE_SYMBOL_MAP[(0, coinType_1.isCTokenCoinType)(coinType)
74
- ? (0, coinType_1.extractCTokenCoinType)(coinType)
75
- : coinType]) !== null && _b !== void 0 ? _b : token.symbol) !== null && _c !== void 0 ? _c : (0, coinType_1.extractSymbolFromCoinType)(coinType), raw: token });
64
+ tokenMap[validUniqueCoinTypes[i]] = Object.assign(Object.assign({}, token), { iconUrl: (_a = COINTYPE_LOGO_MAP[isCTokenCoinType(coinType)
65
+ ? extractCTokenCoinType(coinType)
66
+ : coinType]) !== null && _a !== void 0 ? _a : token.iconUrl, symbol: (_c = (_b = COINTYPE_SYMBOL_MAP[isCTokenCoinType(coinType)
67
+ ? extractCTokenCoinType(coinType)
68
+ : coinType]) !== null && _b !== void 0 ? _b : token.symbol) !== null && _c !== void 0 ? _c : extractSymbolFromCoinType(coinType), raw: token });
76
69
  }
77
70
  return tokenMap;
78
71
  }
@@ -81,13 +74,11 @@ const getCoinMetadataMap = (uniqueCoinTypes) => __awaiter(void 0, void 0, void 0
81
74
  return {};
82
75
  }
83
76
  });
84
- exports.getCoinMetadataMap = getCoinMetadataMap;
85
- const removeCoinMetadataFromIndexedDB = (coinTypes) => __awaiter(void 0, void 0, void 0, function* () {
77
+ export const removeCoinMetadataFromIndexedDB = (coinTypes) => __awaiter(void 0, void 0, void 0, function* () {
86
78
  try {
87
- yield (0, indexedDB_1.removeTokensFromIndexedDB)(coinTypes);
79
+ yield removeTokensFromIndexedDB(coinTypes);
88
80
  }
89
81
  catch (err) {
90
82
  // Silently fail if IndexedDB is not available
91
83
  }
92
84
  });
93
- exports.removeCoinMetadataFromIndexedDB = removeCoinMetadataFromIndexedDB;