@cityofzion/blockchain-service 1.20.0 → 1.21.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/dist/functions.d.ts +2 -1
- package/dist/functions.js +5 -1
- package/dist/helpers/BSBigNumberHelper.d.ts +1 -0
- package/dist/helpers/BSBigNumberHelper.js +3 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/interfaces.d.ts +44 -22
- package/dist/services/exchange-data/FlamingoForthewinEDS.d.ts +2 -2
- package/dist/services/exchange-data/FlamingoForthewinEDS.js +15 -8
- package/dist/services/token/TokenService.d.ts +12 -0
- package/dist/{helpers/BSTokenHelper.js → services/token/TokenService.js} +7 -11
- package/package.json +1 -1
- package/dist/helpers/BSTokenHelper.d.ts +0 -20
package/dist/functions.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Account, BlockchainService, BSCalculableFee, BSClaimable, BSWithExplorerService, BSWithLedger, BSWithNameService, BSWithNft, IBSWithNeo3NeoXBridge, UntilIndexRecord } from './interfaces';
|
|
1
|
+
import { Account, BlockchainService, BSCalculableFee, BSClaimable, BSWithEncryption, BSWithExplorerService, BSWithLedger, BSWithNameService, BSWithNft, IBSWithNeo3NeoXBridge, UntilIndexRecord } from './interfaces';
|
|
2
2
|
export declare function hasNameService<BSName extends string = string>(service: BlockchainService<BSName>): service is BlockchainService<BSName> & BSWithNameService;
|
|
3
3
|
export declare function isClaimable<BSName extends string = string>(service: BlockchainService<BSName>): service is BlockchainService<BSName> & BSClaimable<BSName>;
|
|
4
4
|
export declare function isCalculableFee<BSName extends string = string>(service: BlockchainService<BSName>): service is BlockchainService<BSName> & BSCalculableFee<BSName>;
|
|
@@ -6,6 +6,7 @@ export declare function hasNft<BSName extends string = string>(service: Blockcha
|
|
|
6
6
|
export declare function hasExplorerService<BSName extends string = string>(service: BlockchainService<BSName>): service is BlockchainService<BSName> & BSWithExplorerService;
|
|
7
7
|
export declare function hasLedger<BSName extends string = string>(service: BlockchainService<BSName>): service is BlockchainService<BSName> & BSWithLedger<BSName>;
|
|
8
8
|
export declare function hasNeo3NeoXBridge<BSName extends string = string>(service: BlockchainService<BSName>): service is BlockchainService<BSName> & IBSWithNeo3NeoXBridge<BSName>;
|
|
9
|
+
export declare function hasEncryption<BSName extends string = string>(service: BlockchainService<BSName>): service is BlockchainService<BSName> & BSWithEncryption<BSName>;
|
|
9
10
|
/**
|
|
10
11
|
* @deprecated use `waitForAccountTransaction` instead
|
|
11
12
|
*/
|
package/dist/functions.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.generateAccountForBlockchainService = exports.generateAccount = exports.fetchAccounts = exports.waitForAccountTransaction = exports.waitForTransaction = exports.hasNeo3NeoXBridge = exports.hasLedger = exports.hasExplorerService = exports.hasNft = exports.isCalculableFee = exports.isClaimable = exports.hasNameService = void 0;
|
|
12
|
+
exports.generateAccountForBlockchainService = exports.generateAccount = exports.fetchAccounts = exports.waitForAccountTransaction = exports.waitForTransaction = exports.hasEncryption = exports.hasNeo3NeoXBridge = exports.hasLedger = exports.hasExplorerService = exports.hasNft = exports.isCalculableFee = exports.isClaimable = exports.hasNameService = void 0;
|
|
13
13
|
const BSUtilsHelper_1 = require("./helpers/BSUtilsHelper");
|
|
14
14
|
function hasNameService(service) {
|
|
15
15
|
return 'resolveNameServiceDomain' in service && 'validateNameServiceDomainFormat' in service;
|
|
@@ -39,6 +39,10 @@ function hasNeo3NeoXBridge(service) {
|
|
|
39
39
|
return 'neo3NeoXBridgeService' in service;
|
|
40
40
|
}
|
|
41
41
|
exports.hasNeo3NeoXBridge = hasNeo3NeoXBridge;
|
|
42
|
+
function hasEncryption(service) {
|
|
43
|
+
return 'encrypt' in service && 'decrypt' in service;
|
|
44
|
+
}
|
|
45
|
+
exports.hasEncryption = hasEncryption;
|
|
42
46
|
/**
|
|
43
47
|
* @deprecated use `waitForAccountTransaction` instead
|
|
44
48
|
*/
|
|
@@ -4,6 +4,7 @@ type FormatNumberOptions = {
|
|
|
4
4
|
};
|
|
5
5
|
export declare class BSBigNumberHelper {
|
|
6
6
|
static toDecimals(value: BigNumber, decimals?: number): string;
|
|
7
|
+
static toNumber(value: BigNumber): string;
|
|
7
8
|
static fromNumber(value: string | number): BigNumber;
|
|
8
9
|
static fromDecimals(value: string | number, decimals?: number): BigNumber;
|
|
9
10
|
static format(value?: string | number | BigNumber, options?: FormatNumberOptions): string;
|
|
@@ -9,6 +9,9 @@ class BSBigNumberHelper {
|
|
|
9
9
|
static toDecimals(value, decimals = 0) {
|
|
10
10
|
return new bignumber_js_1.default(value).shiftedBy(decimals).toString();
|
|
11
11
|
}
|
|
12
|
+
static toNumber(value) {
|
|
13
|
+
return value.toFixed();
|
|
14
|
+
}
|
|
12
15
|
static fromNumber(value) {
|
|
13
16
|
return new bignumber_js_1.default(value);
|
|
14
17
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,11 +2,11 @@ export * from './constants/BSCommonConstants';
|
|
|
2
2
|
export * from './helpers/BSFullTransactionsByAddressHelper';
|
|
3
3
|
export * from './helpers/BSPromisesHelper';
|
|
4
4
|
export * from './helpers/BSBigNumberHelper';
|
|
5
|
-
export * from './helpers/BSTokenHelper';
|
|
6
5
|
export * from './helpers/BSUtilsHelper';
|
|
7
6
|
export * from './helpers/BSAccountHelper';
|
|
8
7
|
export * from './services/exchange-data/CryptoCompareEDS';
|
|
9
8
|
export * from './services/exchange-data/FlamingoForthewinEDS';
|
|
9
|
+
export * from './services/token/TokenService';
|
|
10
10
|
export * from './functions';
|
|
11
11
|
export * from './interfaces';
|
|
12
12
|
export * from './error';
|
package/dist/index.js
CHANGED
|
@@ -18,11 +18,11 @@ __exportStar(require("./constants/BSCommonConstants"), exports);
|
|
|
18
18
|
__exportStar(require("./helpers/BSFullTransactionsByAddressHelper"), exports);
|
|
19
19
|
__exportStar(require("./helpers/BSPromisesHelper"), exports);
|
|
20
20
|
__exportStar(require("./helpers/BSBigNumberHelper"), exports);
|
|
21
|
-
__exportStar(require("./helpers/BSTokenHelper"), exports);
|
|
22
21
|
__exportStar(require("./helpers/BSUtilsHelper"), exports);
|
|
23
22
|
__exportStar(require("./helpers/BSAccountHelper"), exports);
|
|
24
23
|
__exportStar(require("./services/exchange-data/CryptoCompareEDS"), exports);
|
|
25
24
|
__exportStar(require("./services/exchange-data/FlamingoForthewinEDS"), exports);
|
|
25
|
+
__exportStar(require("./services/token/TokenService"), exports);
|
|
26
26
|
__exportStar(require("./functions"), exports);
|
|
27
27
|
__exportStar(require("./interfaces"), exports);
|
|
28
28
|
__exportStar(require("./error"), exports);
|
package/dist/interfaces.d.ts
CHANGED
|
@@ -40,6 +40,7 @@ export interface BlockchainService<BSName extends string = string, BSAvailableNe
|
|
|
40
40
|
readonly feeToken: Token;
|
|
41
41
|
exchangeDataService: ExchangeDataService;
|
|
42
42
|
blockchainDataService: BlockchainDataService;
|
|
43
|
+
tokenService: ITokenService;
|
|
43
44
|
tokens: Token[];
|
|
44
45
|
nativeTokens: Token[];
|
|
45
46
|
network: Network<BSAvailableNetworks>;
|
|
@@ -47,15 +48,17 @@ export interface BlockchainService<BSName extends string = string, BSAvailableNe
|
|
|
47
48
|
setNetwork: (partialNetwork: Network<BSAvailableNetworks>) => void;
|
|
48
49
|
generateAccountFromMnemonic(mnemonic: string, index: number): Account<BSName>;
|
|
49
50
|
generateAccountFromKey(key: string): Account<BSName>;
|
|
50
|
-
decrypt(keyOrJson: string, password: string): Promise<Account<BSName>>;
|
|
51
|
-
encrypt(key: string, password: string): Promise<string>;
|
|
52
51
|
validateAddress(address: string): boolean;
|
|
53
|
-
validateEncrypted(keyOrJson: string): boolean;
|
|
54
52
|
validateKey(key: string): boolean;
|
|
55
53
|
transfer(param: TransferParam<BSName>): Promise<string[]>;
|
|
56
54
|
}
|
|
55
|
+
export interface BSWithEncryption<BSName extends string = string> {
|
|
56
|
+
decrypt(keyOrJson: string, password: string): Promise<Account<BSName>>;
|
|
57
|
+
encrypt(key: string, password: string): Promise<string>;
|
|
58
|
+
validateEncrypted(keyOrJson: string): boolean;
|
|
59
|
+
}
|
|
57
60
|
export interface BSCalculableFee<BSName extends string = string> {
|
|
58
|
-
calculateTransferFee(param: TransferParam<BSName
|
|
61
|
+
calculateTransferFee(param: TransferParam<BSName>): Promise<string>;
|
|
59
62
|
}
|
|
60
63
|
export interface BSClaimable<BSName extends string = string> {
|
|
61
64
|
readonly claimToken: Token;
|
|
@@ -98,11 +101,11 @@ export type TransactionTransferAsset = {
|
|
|
98
101
|
token?: Token;
|
|
99
102
|
};
|
|
100
103
|
export type TransactionTransferNft = {
|
|
101
|
-
|
|
104
|
+
tokenHash: string;
|
|
102
105
|
to: string;
|
|
103
106
|
from: string;
|
|
104
107
|
type: 'nft';
|
|
105
|
-
|
|
108
|
+
collectionHash: string;
|
|
106
109
|
};
|
|
107
110
|
type TransactionDefaultResponse = {
|
|
108
111
|
type: 'default';
|
|
@@ -111,7 +114,7 @@ export type TransactionBridgeNeo3NeoXResponse = {
|
|
|
111
114
|
type: 'bridgeNeo3NeoX';
|
|
112
115
|
data: {
|
|
113
116
|
amount: string;
|
|
114
|
-
token:
|
|
117
|
+
token: TBridgeToken;
|
|
115
118
|
receiverAddress: string;
|
|
116
119
|
};
|
|
117
120
|
};
|
|
@@ -151,14 +154,14 @@ export type FullTransactionNftEvent = {
|
|
|
151
154
|
eventType: 'nft';
|
|
152
155
|
amount?: string;
|
|
153
156
|
methodName: string;
|
|
154
|
-
|
|
155
|
-
|
|
157
|
+
collectionHash: string;
|
|
158
|
+
collectionHashUrl?: string;
|
|
156
159
|
to?: string;
|
|
157
160
|
toUrl?: string;
|
|
158
161
|
from?: string;
|
|
159
162
|
fromUrl?: string;
|
|
160
163
|
tokenType: 'generic' | (string & NonNullable<unknown>);
|
|
161
|
-
|
|
164
|
+
tokenHash?: string;
|
|
162
165
|
nftImageUrl?: string;
|
|
163
166
|
nftUrl?: string;
|
|
164
167
|
name?: string;
|
|
@@ -168,8 +171,8 @@ export type FullTransactionAssetEvent = {
|
|
|
168
171
|
eventType: 'token';
|
|
169
172
|
amount?: string;
|
|
170
173
|
methodName: string;
|
|
171
|
-
|
|
172
|
-
|
|
174
|
+
contractHash: string;
|
|
175
|
+
contractHashUrl?: string;
|
|
173
176
|
to?: string;
|
|
174
177
|
toUrl?: string;
|
|
175
178
|
from?: string;
|
|
@@ -184,7 +187,7 @@ export type FullTransactionsItemBridgeNeo3NeoX = {
|
|
|
184
187
|
type: 'bridgeNeo3NeoX';
|
|
185
188
|
data: {
|
|
186
189
|
amount: string;
|
|
187
|
-
token:
|
|
190
|
+
token: TBridgeToken;
|
|
188
191
|
receiverAddress: string;
|
|
189
192
|
};
|
|
190
193
|
};
|
|
@@ -259,14 +262,16 @@ export interface ExchangeDataService {
|
|
|
259
262
|
getCurrencyRatio(currency: string): Promise<number>;
|
|
260
263
|
}
|
|
261
264
|
export interface NftResponse {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
+
hash: string;
|
|
266
|
+
collection: {
|
|
267
|
+
name?: string;
|
|
268
|
+
image?: string;
|
|
269
|
+
hash: string;
|
|
270
|
+
};
|
|
265
271
|
creator: {
|
|
266
272
|
address: string;
|
|
267
273
|
name?: string;
|
|
268
274
|
};
|
|
269
|
-
collectionImage?: string;
|
|
270
275
|
symbol: string;
|
|
271
276
|
image?: string;
|
|
272
277
|
name?: string;
|
|
@@ -284,12 +289,12 @@ export type GetNftsByAddressParams = {
|
|
|
284
289
|
size?: number;
|
|
285
290
|
};
|
|
286
291
|
export type GetNftParam = {
|
|
287
|
-
|
|
288
|
-
|
|
292
|
+
tokenHash: string;
|
|
293
|
+
collectionHash: string;
|
|
289
294
|
};
|
|
290
295
|
export type HasTokenParam = {
|
|
291
296
|
address: string;
|
|
292
|
-
|
|
297
|
+
collectionHash: string;
|
|
293
298
|
};
|
|
294
299
|
export interface NftDataService {
|
|
295
300
|
getNftsByAddress(params: GetNftsByAddressParams): Promise<NftsResponse>;
|
|
@@ -297,8 +302,8 @@ export interface NftDataService {
|
|
|
297
302
|
hasToken(params: HasTokenParam): Promise<boolean>;
|
|
298
303
|
}
|
|
299
304
|
export type BuildNftUrlParams = {
|
|
300
|
-
|
|
301
|
-
|
|
305
|
+
collectionHash: string;
|
|
306
|
+
tokenHash: string;
|
|
302
307
|
};
|
|
303
308
|
export interface ExplorerService {
|
|
304
309
|
buildTransactionUrl(hash: string): string;
|
|
@@ -453,4 +458,21 @@ export interface INeo3NeoXBridgeService<BSName extends string = string> {
|
|
|
453
458
|
getNonce(params: TNeo3NeoXBridgeServiceGetNonceParams<BSName>): Promise<string>;
|
|
454
459
|
getTransactionHashByNonce(params: TNeo3NeoXBridgeServiceGetTransactionHashByNonceParams<BSName>): Promise<string>;
|
|
455
460
|
}
|
|
461
|
+
export type TTokenServicePredicateParams = {
|
|
462
|
+
hash: string;
|
|
463
|
+
symbol?: string;
|
|
464
|
+
};
|
|
465
|
+
export type TTokenServicePredicateByHashParams = string | {
|
|
466
|
+
hash: string;
|
|
467
|
+
};
|
|
468
|
+
export type TTokenServicePredicateBySymbolParams = string | {
|
|
469
|
+
symbol: string;
|
|
470
|
+
};
|
|
471
|
+
export interface ITokenService {
|
|
472
|
+
predicate({ hash, symbol }: TTokenServicePredicateParams): (params: TTokenServicePredicateParams) => boolean;
|
|
473
|
+
predicateByHash(tokenOrHash: TTokenServicePredicateByHashParams): (params: TTokenServicePredicateByHashParams) => boolean;
|
|
474
|
+
predicateBySymbol(tokenOrSymbol: TTokenServicePredicateBySymbolParams): (params: TTokenServicePredicateBySymbolParams) => boolean;
|
|
475
|
+
normalizeToken<T extends Token | Token[]>(token: T): T;
|
|
476
|
+
normalizeHash(hash: string): string;
|
|
477
|
+
}
|
|
456
478
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ExchangeDataService, GetTokenPricesParams, TokenPricesResponse } from '../../interfaces';
|
|
1
|
+
import { ExchangeDataService, GetTokenPricesParams, ITokenService, TokenPricesResponse } from '../../interfaces';
|
|
2
2
|
import { CryptoCompareEDS } from './CryptoCompareEDS';
|
|
3
3
|
export declare class FlamingoForthewinEDS extends CryptoCompareEDS implements ExchangeDataService {
|
|
4
4
|
#private;
|
|
5
|
-
constructor();
|
|
5
|
+
constructor(tokenService: ITokenService);
|
|
6
6
|
getTokenPrices({ tokens }: GetTokenPricesParams): Promise<TokenPricesResponse[]>;
|
|
7
7
|
}
|
|
@@ -8,6 +8,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
12
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
13
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
14
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
15
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
16
|
+
};
|
|
11
17
|
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
12
18
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
13
19
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
@@ -16,30 +22,31 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
16
22
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
23
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
24
|
};
|
|
19
|
-
var _FlamingoForthewinEDS_flamingoAxiosInstance, _FlamingoForthewinEDS_forthewinAxiosInstance;
|
|
25
|
+
var _FlamingoForthewinEDS_flamingoAxiosInstance, _FlamingoForthewinEDS_forthewinAxiosInstance, _FlamingoForthewinEDS_tokenService;
|
|
20
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
27
|
exports.FlamingoForthewinEDS = void 0;
|
|
22
28
|
const axios_1 = __importDefault(require("axios"));
|
|
23
29
|
const CryptoCompareEDS_1 = require("./CryptoCompareEDS");
|
|
24
|
-
const BSTokenHelper_1 = require("../../helpers/BSTokenHelper");
|
|
25
30
|
class FlamingoForthewinEDS extends CryptoCompareEDS_1.CryptoCompareEDS {
|
|
26
|
-
constructor() {
|
|
31
|
+
constructor(tokenService) {
|
|
27
32
|
super();
|
|
28
33
|
_FlamingoForthewinEDS_flamingoAxiosInstance.set(this, axios_1.default.create({ baseURL: 'https://neo-api.b-cdn.net/flamingo' }));
|
|
29
34
|
_FlamingoForthewinEDS_forthewinAxiosInstance.set(this, axios_1.default.create({ baseURL: 'https://api.forthewin.network' }));
|
|
35
|
+
_FlamingoForthewinEDS_tokenService.set(this, void 0);
|
|
36
|
+
__classPrivateFieldSet(this, _FlamingoForthewinEDS_tokenService, tokenService, "f");
|
|
30
37
|
}
|
|
31
38
|
getTokenPrices({ tokens }) {
|
|
32
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
33
40
|
const { data: flamingoData } = yield __classPrivateFieldGet(this, _FlamingoForthewinEDS_flamingoAxiosInstance, "f").get('/live-data/prices/latest');
|
|
34
41
|
const prices = [];
|
|
35
42
|
const neoToken = tokens.find(({ symbol }) => symbol === 'NEO');
|
|
36
|
-
if (neoToken && !flamingoData.find(
|
|
43
|
+
if (neoToken && !flamingoData.find(__classPrivateFieldGet(this, _FlamingoForthewinEDS_tokenService, "f").predicate(neoToken)))
|
|
37
44
|
flamingoData.forEach(item => {
|
|
38
45
|
if (item.symbol === 'bNEO')
|
|
39
46
|
flamingoData.push(Object.assign(Object.assign({}, item), { symbol: neoToken.symbol, hash: neoToken.hash }));
|
|
40
47
|
});
|
|
41
48
|
flamingoData.forEach(item => {
|
|
42
|
-
const token = tokens.find(
|
|
49
|
+
const token = tokens.find(__classPrivateFieldGet(this, _FlamingoForthewinEDS_tokenService, "f").predicate(item));
|
|
43
50
|
if (!token)
|
|
44
51
|
return;
|
|
45
52
|
prices.push({ usdPrice: item.usd_price, token });
|
|
@@ -47,10 +54,10 @@ class FlamingoForthewinEDS extends CryptoCompareEDS_1.CryptoCompareEDS {
|
|
|
47
54
|
if (tokens.length > prices.length) {
|
|
48
55
|
const { data: forthewinData } = yield __classPrivateFieldGet(this, _FlamingoForthewinEDS_forthewinAxiosInstance, "f").get('/mainnet/prices');
|
|
49
56
|
Object.entries(forthewinData).forEach(([hash, usdPrice]) => {
|
|
50
|
-
const hasPrice = !!prices.find(({ token }) =>
|
|
57
|
+
const hasPrice = !!prices.find(({ token }) => __classPrivateFieldGet(this, _FlamingoForthewinEDS_tokenService, "f").predicate({ hash })(token));
|
|
51
58
|
if (hasPrice)
|
|
52
59
|
return;
|
|
53
|
-
const foundToken = tokens.find(
|
|
60
|
+
const foundToken = tokens.find(__classPrivateFieldGet(this, _FlamingoForthewinEDS_tokenService, "f").predicate({ hash }));
|
|
54
61
|
if (!foundToken)
|
|
55
62
|
return;
|
|
56
63
|
prices.push({ usdPrice, token: foundToken });
|
|
@@ -61,4 +68,4 @@ class FlamingoForthewinEDS extends CryptoCompareEDS_1.CryptoCompareEDS {
|
|
|
61
68
|
}
|
|
62
69
|
}
|
|
63
70
|
exports.FlamingoForthewinEDS = FlamingoForthewinEDS;
|
|
64
|
-
_FlamingoForthewinEDS_flamingoAxiosInstance = new WeakMap(), _FlamingoForthewinEDS_forthewinAxiosInstance = new WeakMap();
|
|
71
|
+
_FlamingoForthewinEDS_flamingoAxiosInstance = new WeakMap(), _FlamingoForthewinEDS_forthewinAxiosInstance = new WeakMap(), _FlamingoForthewinEDS_tokenService = new WeakMap();
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ITokenService, Token, TTokenServicePredicateByHashParams, TTokenServicePredicateBySymbolParams, TTokenServicePredicateParams } from '../../interfaces';
|
|
2
|
+
export type TBSTokenHelperPredicateParams = {
|
|
3
|
+
hash: string;
|
|
4
|
+
symbol?: string;
|
|
5
|
+
};
|
|
6
|
+
export declare abstract class TokenService implements ITokenService {
|
|
7
|
+
predicate({ hash, symbol }: TTokenServicePredicateParams): (params: TTokenServicePredicateParams) => boolean;
|
|
8
|
+
predicateByHash(tokenOrHash: TTokenServicePredicateByHashParams): (params: TTokenServicePredicateByHashParams) => boolean;
|
|
9
|
+
predicateBySymbol(tokenOrSymbol: TTokenServicePredicateBySymbolParams): (params: TTokenServicePredicateBySymbolParams) => boolean;
|
|
10
|
+
normalizeToken<T extends Token | Token[]>(token: T): T;
|
|
11
|
+
abstract normalizeHash(hash: string): string;
|
|
12
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
class
|
|
5
|
-
|
|
3
|
+
exports.TokenService = void 0;
|
|
4
|
+
class TokenService {
|
|
5
|
+
predicate({ hash, symbol }) {
|
|
6
6
|
const normalizedHash = this.normalizeHash(hash);
|
|
7
7
|
return (params) => {
|
|
8
8
|
if (normalizedHash === this.normalizeHash(params.hash))
|
|
@@ -12,12 +12,12 @@ class BSTokenHelper {
|
|
|
12
12
|
return false;
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
|
-
|
|
15
|
+
predicateByHash(tokenOrHash) {
|
|
16
16
|
const hash = typeof tokenOrHash === 'string' ? tokenOrHash : tokenOrHash.hash;
|
|
17
17
|
const normalizedHash = this.normalizeHash(hash);
|
|
18
18
|
return (params) => normalizedHash === this.normalizeHash(typeof params === 'string' ? params : params.hash);
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
predicateBySymbol(tokenOrSymbol) {
|
|
21
21
|
const symbol = typeof tokenOrSymbol === 'string' ? tokenOrSymbol : tokenOrSymbol.symbol;
|
|
22
22
|
const lowercaseSymbol = symbol.toLowerCase();
|
|
23
23
|
return (params) => {
|
|
@@ -26,15 +26,11 @@ class BSTokenHelper {
|
|
|
26
26
|
return lowercaseSymbol === lowercaseTokenSymbol;
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
|
-
|
|
29
|
+
normalizeToken(token) {
|
|
30
30
|
if (Array.isArray(token)) {
|
|
31
31
|
return token.map(item => (Object.assign(Object.assign({}, item), { hash: this.normalizeHash(item.hash) })));
|
|
32
32
|
}
|
|
33
33
|
return Object.assign(Object.assign({}, token), { hash: this.normalizeHash(token.hash) });
|
|
34
34
|
}
|
|
35
|
-
static normalizeHash(hash) {
|
|
36
|
-
const fixed = hash.startsWith('0x') ? hash : `0x${hash}`;
|
|
37
|
-
return fixed.toLowerCase();
|
|
38
|
-
}
|
|
39
35
|
}
|
|
40
|
-
exports.
|
|
36
|
+
exports.TokenService = TokenService;
|
package/package.json
CHANGED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Token } from '../interfaces';
|
|
2
|
-
export type TBSTokenHelperPredicateParams = {
|
|
3
|
-
hash: string;
|
|
4
|
-
symbol?: string;
|
|
5
|
-
};
|
|
6
|
-
export declare class BSTokenHelper {
|
|
7
|
-
static predicate({ hash, symbol }: TBSTokenHelperPredicateParams): (params: TBSTokenHelperPredicateParams) => boolean;
|
|
8
|
-
static predicateByHash(tokenOrHash: string | {
|
|
9
|
-
hash: string;
|
|
10
|
-
}): (params: string | {
|
|
11
|
-
hash: string;
|
|
12
|
-
}) => boolean;
|
|
13
|
-
static predicateBySymbol(tokenOrSymbol: string | {
|
|
14
|
-
symbol: string;
|
|
15
|
-
}): (params: string | {
|
|
16
|
-
symbol: string;
|
|
17
|
-
}) => boolean;
|
|
18
|
-
static normalizeToken<T extends Token | Token[]>(token: T): T;
|
|
19
|
-
static normalizeHash(hash: string): string;
|
|
20
|
-
}
|