@cityofzion/blockchain-service 1.19.3 → 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 +67 -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,22 @@ 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;
|
|
109
|
+
};
|
|
110
|
+
type TransactionDefaultResponse = {
|
|
111
|
+
type: 'default';
|
|
112
|
+
};
|
|
113
|
+
export type TransactionBridgeNeo3NeoXResponse = {
|
|
114
|
+
type: 'bridgeNeo3NeoX';
|
|
115
|
+
data: {
|
|
116
|
+
amount: string;
|
|
117
|
+
token: TBridgeToken;
|
|
118
|
+
receiverAddress: string;
|
|
119
|
+
};
|
|
106
120
|
};
|
|
107
121
|
export type TransactionResponse = {
|
|
108
122
|
hash: string;
|
|
@@ -111,7 +125,7 @@ export type TransactionResponse = {
|
|
|
111
125
|
transfers: (TransactionTransferAsset | TransactionTransferNft)[];
|
|
112
126
|
fee?: string;
|
|
113
127
|
notifications: TransactionNotifications[];
|
|
114
|
-
};
|
|
128
|
+
} & (TransactionDefaultResponse | TransactionBridgeNeo3NeoXResponse);
|
|
115
129
|
export type ContractParameter = {
|
|
116
130
|
name: string;
|
|
117
131
|
type: string;
|
|
@@ -140,14 +154,14 @@ export type FullTransactionNftEvent = {
|
|
|
140
154
|
eventType: 'nft';
|
|
141
155
|
amount?: string;
|
|
142
156
|
methodName: string;
|
|
143
|
-
|
|
144
|
-
|
|
157
|
+
collectionHash: string;
|
|
158
|
+
collectionHashUrl?: string;
|
|
145
159
|
to?: string;
|
|
146
160
|
toUrl?: string;
|
|
147
161
|
from?: string;
|
|
148
162
|
fromUrl?: string;
|
|
149
163
|
tokenType: 'generic' | (string & NonNullable<unknown>);
|
|
150
|
-
|
|
164
|
+
tokenHash?: string;
|
|
151
165
|
nftImageUrl?: string;
|
|
152
166
|
nftUrl?: string;
|
|
153
167
|
name?: string;
|
|
@@ -157,8 +171,8 @@ export type FullTransactionAssetEvent = {
|
|
|
157
171
|
eventType: 'token';
|
|
158
172
|
amount?: string;
|
|
159
173
|
methodName: string;
|
|
160
|
-
|
|
161
|
-
|
|
174
|
+
contractHash: string;
|
|
175
|
+
contractHashUrl?: string;
|
|
162
176
|
to?: string;
|
|
163
177
|
toUrl?: string;
|
|
164
178
|
from?: string;
|
|
@@ -166,6 +180,17 @@ export type FullTransactionAssetEvent = {
|
|
|
166
180
|
token?: Token;
|
|
167
181
|
tokenType: 'generic' | (string & NonNullable<unknown>);
|
|
168
182
|
};
|
|
183
|
+
type FullTransactionsItemDefault = {
|
|
184
|
+
type: 'default';
|
|
185
|
+
};
|
|
186
|
+
export type FullTransactionsItemBridgeNeo3NeoX = {
|
|
187
|
+
type: 'bridgeNeo3NeoX';
|
|
188
|
+
data: {
|
|
189
|
+
amount: string;
|
|
190
|
+
token: TBridgeToken;
|
|
191
|
+
receiverAddress: string;
|
|
192
|
+
};
|
|
193
|
+
};
|
|
169
194
|
export type FullTransactionsItem = {
|
|
170
195
|
txId: string;
|
|
171
196
|
txIdUrl?: string;
|
|
@@ -176,7 +201,7 @@ export type FullTransactionsItem = {
|
|
|
176
201
|
networkFeeAmount?: string;
|
|
177
202
|
systemFeeAmount?: string;
|
|
178
203
|
events: (FullTransactionAssetEvent | FullTransactionNftEvent)[];
|
|
179
|
-
};
|
|
204
|
+
} & (FullTransactionsItemDefault | FullTransactionsItemBridgeNeo3NeoX);
|
|
180
205
|
export type FullTransactionsByAddressResponse = {
|
|
181
206
|
nextCursor?: string;
|
|
182
207
|
data: FullTransactionsItem[];
|
|
@@ -237,14 +262,16 @@ export interface ExchangeDataService {
|
|
|
237
262
|
getCurrencyRatio(currency: string): Promise<number>;
|
|
238
263
|
}
|
|
239
264
|
export interface NftResponse {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
265
|
+
hash: string;
|
|
266
|
+
collection: {
|
|
267
|
+
name?: string;
|
|
268
|
+
image?: string;
|
|
269
|
+
hash: string;
|
|
270
|
+
};
|
|
243
271
|
creator: {
|
|
244
272
|
address: string;
|
|
245
273
|
name?: string;
|
|
246
274
|
};
|
|
247
|
-
collectionImage?: string;
|
|
248
275
|
symbol: string;
|
|
249
276
|
image?: string;
|
|
250
277
|
name?: string;
|
|
@@ -262,12 +289,12 @@ export type GetNftsByAddressParams = {
|
|
|
262
289
|
size?: number;
|
|
263
290
|
};
|
|
264
291
|
export type GetNftParam = {
|
|
265
|
-
|
|
266
|
-
|
|
292
|
+
tokenHash: string;
|
|
293
|
+
collectionHash: string;
|
|
267
294
|
};
|
|
268
295
|
export type HasTokenParam = {
|
|
269
296
|
address: string;
|
|
270
|
-
|
|
297
|
+
collectionHash: string;
|
|
271
298
|
};
|
|
272
299
|
export interface NftDataService {
|
|
273
300
|
getNftsByAddress(params: GetNftsByAddressParams): Promise<NftsResponse>;
|
|
@@ -275,8 +302,8 @@ export interface NftDataService {
|
|
|
275
302
|
hasToken(params: HasTokenParam): Promise<boolean>;
|
|
276
303
|
}
|
|
277
304
|
export type BuildNftUrlParams = {
|
|
278
|
-
|
|
279
|
-
|
|
305
|
+
collectionHash: string;
|
|
306
|
+
tokenHash: string;
|
|
280
307
|
};
|
|
281
308
|
export interface ExplorerService {
|
|
282
309
|
buildTransactionUrl(hash: string): string;
|
|
@@ -431,3 +458,21 @@ export interface INeo3NeoXBridgeService<BSName extends string = string> {
|
|
|
431
458
|
getNonce(params: TNeo3NeoXBridgeServiceGetNonceParams<BSName>): Promise<string>;
|
|
432
459
|
getTransactionHashByNonce(params: TNeo3NeoXBridgeServiceGetTransactionHashByNonceParams<BSName>): Promise<string>;
|
|
433
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
|
+
}
|
|
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
|
-
}
|