@suilend/sui-fe 0.3.52 → 0.4.0
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 +1 -17
- package/lib/api.js +8 -13
- package/lib/coin.js +1 -4
- package/lib/coinMetadata.d.ts +1 -1
- package/lib/coinMetadata.js +23 -32
- package/lib/coinType.js +277 -297
- package/lib/constants.js +13 -19
- package/lib/format.js +46 -68
- package/lib/index.js +11 -27
- package/lib/indexedDB.js +3 -9
- package/lib/keypair.d.ts +19 -12
- package/lib/keypair.js +53 -67
- package/lib/ledger.d.ts +2 -2
- package/lib/ledger.js +7 -14
- package/lib/msafe.js +3 -9
- package/lib/transactions.d.ts +16 -7
- package/lib/transactions.js +33 -43
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,17 +1 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
12
|
-
|
|
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 = `${
|
|
37
|
-
address:
|
|
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
|
-
|
|
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 = `${
|
|
64
|
-
address:
|
|
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
package/lib/coinMetadata.d.ts
CHANGED
package/lib/coinMetadata.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,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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
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(
|
|
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) =>
|
|
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
|
|
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 =
|
|
43
|
-
const limit = (
|
|
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 = `${
|
|
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
|
|
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 =
|
|
66
|
-
?
|
|
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 =
|
|
72
|
-
?
|
|
73
|
-
: coinType]) !== null && _a !== void 0 ? _a : token.iconUrl, symbol: (_c = (_b =
|
|
74
|
-
?
|
|
75
|
-
: coinType]) !== null && _b !== void 0 ? _b : token.symbol) !== null && _c !== void 0 ? _c :
|
|
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
|
-
|
|
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
|
|
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;
|