@requestnetwork/request-client.js 0.30.0 → 0.30.1-next.709
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/README.md +9 -13
- package/dist/api/content-data-extension.js +3 -3
- package/dist/api/content-data-extension.js.map +1 -1
- package/dist/api/request-network.d.ts +50 -15
- package/dist/api/request-network.d.ts.map +1 -1
- package/dist/api/request-network.js +187 -87
- package/dist/api/request-network.js.map +1 -1
- package/dist/api/request.d.ts +55 -6
- package/dist/api/request.d.ts.map +1 -1
- package/dist/api/request.js +171 -149
- package/dist/api/request.js.map +1 -1
- package/dist/api/utils.d.ts +5 -6
- package/dist/api/utils.d.ts.map +1 -1
- package/dist/api/utils.js +1 -3
- package/dist/api/utils.js.map +1 -1
- package/dist/http-config-defaults.d.ts +4 -0
- package/dist/http-config-defaults.d.ts.map +1 -0
- package/dist/http-config-defaults.js +16 -0
- package/dist/http-config-defaults.js.map +1 -0
- package/dist/http-data-access.d.ts +40 -9
- package/dist/http-data-access.d.ts.map +1 -1
- package/dist/http-data-access.js +113 -95
- package/dist/http-data-access.js.map +1 -1
- package/dist/http-metamask-data-access.d.ts +7 -7
- package/dist/http-metamask-data-access.d.ts.map +1 -1
- package/dist/http-metamask-data-access.js +57 -61
- package/dist/http-metamask-data-access.js.map +1 -1
- package/dist/http-request-network.d.ts +15 -15
- package/dist/http-request-network.d.ts.map +1 -1
- package/dist/http-request-network.js +23 -25
- package/dist/http-request-network.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/mock-storage.d.ts +2 -5
- package/dist/mock-storage.d.ts.map +1 -1
- package/dist/mock-storage.js +24 -77
- package/dist/mock-storage.js.map +1 -1
- package/dist/no-persist-http-data-access.d.ts +10 -0
- package/dist/no-persist-http-data-access.d.ts.map +1 -0
- package/dist/no-persist-http-data-access.js +36 -0
- package/dist/no-persist-http-data-access.js.map +1 -0
- package/dist/report.html +9 -24
- package/dist/requestnetwork.min.js +441 -1
- package/dist/requestnetwork.min.js.LICENSE.txt +18 -20
- package/dist/requestnetwork.min.js.map +1 -1
- package/dist/types.js +2 -11
- package/dist/types.js.map +1 -1
- package/package.json +33 -44
- package/CHANGELOG.md +0 -2077
- package/dist/api/currency/erc20/celo.d.ts +0 -14
- package/dist/api/currency/erc20/celo.d.ts.map +0 -1
- package/dist/api/currency/erc20/celo.js +0 -26
- package/dist/api/currency/erc20/celo.js.map +0 -1
- package/dist/api/currency/erc20/networks.d.ts +0 -25
- package/dist/api/currency/erc20/networks.d.ts.map +0 -1
- package/dist/api/currency/erc20/networks.js +0 -14
- package/dist/api/currency/erc20/networks.js.map +0 -1
- package/dist/api/currency/erc20/rinkeby.d.ts +0 -19
- package/dist/api/currency/erc20/rinkeby.d.ts.map +0 -1
- package/dist/api/currency/erc20/rinkeby.js +0 -43
- package/dist/api/currency/erc20/rinkeby.js.map +0 -1
- package/dist/api/currency/erc20.d.ts +0 -62
- package/dist/api/currency/erc20.d.ts.map +0 -1
- package/dist/api/currency/erc20.js +0 -136
- package/dist/api/currency/erc20.js.map +0 -1
- package/dist/api/currency.d.ts +0 -45
- package/dist/api/currency.d.ts.map +0 -1
- package/dist/api/currency.js +0 -162
- package/dist/api/currency.js.map +0 -1
- package/dist/mock-data-access.d.ts +0 -11
- package/dist/mock-data-access.d.ts.map +0 -1
- package/dist/mock-data-access.js +0 -16
- package/dist/mock-data-access.js.map +0 -1
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { RequestLogicTypes } from '@requestnetwork/types';
|
|
2
|
-
export declare const supportedCeloERC20: Map<string, {
|
|
3
|
-
network: string;
|
|
4
|
-
type: RequestLogicTypes.CURRENCY;
|
|
5
|
-
value: string;
|
|
6
|
-
}>;
|
|
7
|
-
export declare const supportedCeloERC20Details: {
|
|
8
|
-
CUSD: {
|
|
9
|
-
address: string;
|
|
10
|
-
decimals: number;
|
|
11
|
-
name: string;
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=celo.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"celo.d.ts","sourceRoot":"","sources":["../../../../src/api/currency/erc20/celo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAG1D,eAAO,MAAM,kBAAkB;;;;EAU7B,CAAC;AAGH,eAAO,MAAM,yBAAyB;;;;;;CAOrC,CAAC"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.supportedCeloERC20Details = exports.supportedCeloERC20 = void 0;
|
|
4
|
-
const types_1 = require("@requestnetwork/types");
|
|
5
|
-
// List of the supported celo network tokens
|
|
6
|
-
exports.supportedCeloERC20 = new Map([
|
|
7
|
-
// cUSD token (https://explorer.celo.org/address/0x765de816845861e75a25fca122bb6898b8b1282a/transactions)
|
|
8
|
-
[
|
|
9
|
-
'CUSD',
|
|
10
|
-
{
|
|
11
|
-
network: 'celo',
|
|
12
|
-
type: types_1.RequestLogicTypes.CURRENCY.ERC20,
|
|
13
|
-
value: '0x765DE816845861e75A25fCA122bb6898B8B1282a',
|
|
14
|
-
},
|
|
15
|
-
],
|
|
16
|
-
]);
|
|
17
|
-
// Additional details about the supported rinkeby ERC20 tokens.
|
|
18
|
-
exports.supportedCeloERC20Details = {
|
|
19
|
-
// Request Central Bank token, used for testing on rinkeby.
|
|
20
|
-
CUSD: {
|
|
21
|
-
address: '0x765DE816845861e75A25fCA122bb6898B8B1282a',
|
|
22
|
-
decimals: 18,
|
|
23
|
-
name: 'Celo Dollar',
|
|
24
|
-
},
|
|
25
|
-
};
|
|
26
|
-
//# sourceMappingURL=celo.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"celo.js","sourceRoot":"","sources":["../../../../src/api/currency/erc20/celo.ts"],"names":[],"mappings":";;;AAAA,iDAA0D;AAE1D,4CAA4C;AAC/B,QAAA,kBAAkB,GAAG,IAAI,GAAG,CAAC;IACxC,yGAAyG;IACzG;QACE,MAAM;QACN;YACE,OAAO,EAAE,MAAM;YACf,IAAI,EAAE,yBAAiB,CAAC,QAAQ,CAAC,KAAK;YACtC,KAAK,EAAE,4CAA4C;SACpD;KACF;CACF,CAAC,CAAC;AAEH,+DAA+D;AAClD,QAAA,yBAAyB,GAAG;IACvC,2DAA2D;IAC3D,IAAI,EAAE;QACJ,OAAO,EAAE,4CAA4C;QACrD,QAAQ,EAAE,EAAE;QACZ,IAAI,EAAE,aAAa;KACpB;CACF,CAAC"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { RequestLogicTypes } from '@requestnetwork/types';
|
|
2
|
-
/**
|
|
3
|
-
* ERC20 Symbol details type
|
|
4
|
-
*/
|
|
5
|
-
export interface ERC20SymbolDetails {
|
|
6
|
-
address: string;
|
|
7
|
-
decimals: number;
|
|
8
|
-
name: string;
|
|
9
|
-
}
|
|
10
|
-
interface ISupportedNetworksMap {
|
|
11
|
-
[network: string]: Map<string, {
|
|
12
|
-
network: string;
|
|
13
|
-
type: RequestLogicTypes.CURRENCY;
|
|
14
|
-
value: string;
|
|
15
|
-
}>;
|
|
16
|
-
}
|
|
17
|
-
interface ISupportedNetworksDetails {
|
|
18
|
-
[network: string]: {
|
|
19
|
-
[symbol: string]: ERC20SymbolDetails;
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
export declare const supportedNetworks: ISupportedNetworksMap;
|
|
23
|
-
export declare const supportedNetworksDetails: ISupportedNetworksDetails;
|
|
24
|
-
export {};
|
|
25
|
-
//# sourceMappingURL=networks.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"networks.d.ts","sourceRoot":"","sources":["../../../../src/api/currency/erc20/networks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAI1D;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,UAAU,qBAAqB;IAC7B,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CACpB,MAAM,EACN;QACE,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE,iBAAiB,CAAC,QAAQ,CAAC;QACjC,KAAK,EAAE,MAAM,CAAC;KACf,CACF,CAAC;CACH;AAED,UAAU,yBAAyB;IACjC,CAAC,OAAO,EAAE,MAAM,GAAG;QACjB,CAAC,MAAM,EAAE,MAAM,GAAG,kBAAkB,CAAC;KACtC,CAAC;CACH;AAED,eAAO,MAAM,iBAAiB,EAAE,qBAG/B,CAAC;AAEF,eAAO,MAAM,wBAAwB,EAAE,yBAGtC,CAAC"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.supportedNetworksDetails = exports.supportedNetworks = void 0;
|
|
4
|
-
const rinkeby_1 = require("./rinkeby");
|
|
5
|
-
const celo_1 = require("./celo");
|
|
6
|
-
exports.supportedNetworks = {
|
|
7
|
-
celo: celo_1.supportedCeloERC20,
|
|
8
|
-
rinkeby: rinkeby_1.supportedRinkebyERC20,
|
|
9
|
-
};
|
|
10
|
-
exports.supportedNetworksDetails = {
|
|
11
|
-
celo: celo_1.supportedCeloERC20Details,
|
|
12
|
-
rinkeby: rinkeby_1.supportedRinkebyERC20Details,
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=networks.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"networks.js","sourceRoot":"","sources":["../../../../src/api/currency/erc20/networks.ts"],"names":[],"mappings":";;;AACA,uCAAgF;AAChF,iCAAuE;AA4B1D,QAAA,iBAAiB,GAA0B;IACtD,IAAI,EAAE,yBAAkB;IACxB,OAAO,EAAE,+BAAqB;CAC/B,CAAC;AAEW,QAAA,wBAAwB,GAA8B;IACjE,IAAI,EAAE,gCAAyB;IAC/B,OAAO,EAAE,sCAA4B;CACtC,CAAC"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { RequestLogicTypes } from '@requestnetwork/types';
|
|
2
|
-
export declare const supportedRinkebyERC20: Map<string, {
|
|
3
|
-
network: string;
|
|
4
|
-
type: RequestLogicTypes.CURRENCY;
|
|
5
|
-
value: string;
|
|
6
|
-
}>;
|
|
7
|
-
export declare const supportedRinkebyERC20Details: {
|
|
8
|
-
CTBK: {
|
|
9
|
-
address: string;
|
|
10
|
-
decimals: number;
|
|
11
|
-
name: string;
|
|
12
|
-
};
|
|
13
|
-
FAU: {
|
|
14
|
-
address: string;
|
|
15
|
-
decimals: number;
|
|
16
|
-
name: string;
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
//# sourceMappingURL=rinkeby.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rinkeby.d.ts","sourceRoot":"","sources":["../../../../src/api/currency/erc20/rinkeby.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAG1D,eAAO,MAAM,qBAAqB;;;;EAoBhC,CAAC;AAGH,eAAO,MAAM,4BAA4B;;;;;;;;;;;CAexC,CAAC"}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.supportedRinkebyERC20Details = exports.supportedRinkebyERC20 = void 0;
|
|
4
|
-
const types_1 = require("@requestnetwork/types");
|
|
5
|
-
// List of the supported rinkeby ERC20 tokens
|
|
6
|
-
exports.supportedRinkebyERC20 = new Map([
|
|
7
|
-
// Request Central Bank token, used for testing on rinkeby.
|
|
8
|
-
[
|
|
9
|
-
'CTBK',
|
|
10
|
-
{
|
|
11
|
-
network: 'rinkeby',
|
|
12
|
-
type: types_1.RequestLogicTypes.CURRENCY.ERC20,
|
|
13
|
-
value: '0x995d6a8c21f24be1dd04e105dd0d83758343e258',
|
|
14
|
-
},
|
|
15
|
-
],
|
|
16
|
-
// Faucet Token on rinkeby network. Easy to use on tests.
|
|
17
|
-
[
|
|
18
|
-
'FAU',
|
|
19
|
-
{
|
|
20
|
-
network: 'rinkeby',
|
|
21
|
-
type: types_1.RequestLogicTypes.CURRENCY.ERC20,
|
|
22
|
-
value: '0xFab46E002BbF0b4509813474841E0716E6730136',
|
|
23
|
-
},
|
|
24
|
-
],
|
|
25
|
-
]);
|
|
26
|
-
// Additional details about the supported rinkeby ERC20 tokens.
|
|
27
|
-
exports.supportedRinkebyERC20Details = {
|
|
28
|
-
// Request Central Bank token, used for testing on rinkeby.
|
|
29
|
-
CTBK: {
|
|
30
|
-
// Faucet URL: https://central.request.network
|
|
31
|
-
address: '0x995d6a8c21f24be1dd04e105dd0d83758343e258',
|
|
32
|
-
decimals: 18,
|
|
33
|
-
name: 'Central Bank Token',
|
|
34
|
-
},
|
|
35
|
-
// Faucet Token on rinkeby network.
|
|
36
|
-
FAU: {
|
|
37
|
-
// Faucet URL: https://erc20faucet.com/
|
|
38
|
-
address: '0xFab46E002BbF0b4509813474841E0716E6730136',
|
|
39
|
-
decimals: 18,
|
|
40
|
-
name: 'Faucet Token',
|
|
41
|
-
},
|
|
42
|
-
};
|
|
43
|
-
//# sourceMappingURL=rinkeby.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rinkeby.js","sourceRoot":"","sources":["../../../../src/api/currency/erc20/rinkeby.ts"],"names":[],"mappings":";;;AAAA,iDAA0D;AAE1D,6CAA6C;AAChC,QAAA,qBAAqB,GAAG,IAAI,GAAG,CAAC;IAC3C,2DAA2D;IAC3D;QACE,MAAM;QACN;YACE,OAAO,EAAE,SAAS;YAClB,IAAI,EAAE,yBAAiB,CAAC,QAAQ,CAAC,KAAK;YACtC,KAAK,EAAE,4CAA4C;SACpD;KACF;IAED,yDAAyD;IACzD;QACE,KAAK;QACL;YACE,OAAO,EAAE,SAAS;YAClB,IAAI,EAAE,yBAAiB,CAAC,QAAQ,CAAC,KAAK;YACtC,KAAK,EAAE,4CAA4C;SACpD;KACF;CACF,CAAC,CAAC;AAEH,+DAA+D;AAClD,QAAA,4BAA4B,GAAG;IAC1C,2DAA2D;IAC3D,IAAI,EAAE;QACJ,8CAA8C;QAC9C,OAAO,EAAE,4CAA4C;QACrD,QAAQ,EAAE,EAAE;QACZ,IAAI,EAAE,oBAAoB;KAC3B;IACD,mCAAmC;IACnC,GAAG,EAAE;QACH,uCAAuC;QACvC,OAAO,EAAE,4CAA4C;QACrD,QAAQ,EAAE,EAAE;QACZ,IAAI,EAAE,cAAc;KACrB;CACF,CAAC"}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { RequestLogicTypes } from '@requestnetwork/types';
|
|
2
|
-
import { ERC20SymbolDetails } from './erc20/networks';
|
|
3
|
-
interface ITokenDescription {
|
|
4
|
-
name: string;
|
|
5
|
-
logo: string;
|
|
6
|
-
erc20: boolean;
|
|
7
|
-
symbol: string;
|
|
8
|
-
decimals: number;
|
|
9
|
-
address: string;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Returns a Currency object for an ERC20, if found
|
|
13
|
-
* @param symbol The ERC20 token symbol
|
|
14
|
-
* @param network The ERC20 contract network
|
|
15
|
-
*/
|
|
16
|
-
export declare function getErc20Currency(symbol: string, network: string): RequestLogicTypes.ICurrency | undefined;
|
|
17
|
-
/**
|
|
18
|
-
* Get the amount of decimals for an ERC20 currency
|
|
19
|
-
*
|
|
20
|
-
* @param currency The ERC20 Currency object
|
|
21
|
-
* @returns The number of decimals for the ERC20 currency
|
|
22
|
-
*/
|
|
23
|
-
export declare function getErc20Decimals(currency: RequestLogicTypes.ICurrency): number;
|
|
24
|
-
/**
|
|
25
|
-
* Get an ERC20 currency from the currency address
|
|
26
|
-
*
|
|
27
|
-
* @param address the ERC20 currency address
|
|
28
|
-
* @returns the ERC20 ITokenDescription
|
|
29
|
-
*/
|
|
30
|
-
export declare function getMainnetErc20FromAddress(address: string): ITokenDescription | undefined;
|
|
31
|
-
/**
|
|
32
|
-
* Get an ERC20 currency from the currency value string, for mainnet only
|
|
33
|
-
*
|
|
34
|
-
* @param symbol the ERC20 currency symbol string
|
|
35
|
-
* @returns the ERC20 ITokenDescription
|
|
36
|
-
*/
|
|
37
|
-
export declare function getMainnetErc20FromSymbol(symbol: string): ITokenDescription | undefined;
|
|
38
|
-
/**
|
|
39
|
-
* Returns true if the address is a valid checksum address
|
|
40
|
-
*
|
|
41
|
-
* @param address The address to validate
|
|
42
|
-
* @returns If the address is valid or not
|
|
43
|
-
*/
|
|
44
|
-
export declare function validERC20Address(address: string): boolean;
|
|
45
|
-
/**
|
|
46
|
-
* Get an ERC20 symbol from the Currency object
|
|
47
|
-
*
|
|
48
|
-
* @param token the ERC20 ICurrency
|
|
49
|
-
* @returns the ERC20 currency symbol string
|
|
50
|
-
*/
|
|
51
|
-
export declare function getErc20Symbol(currency: RequestLogicTypes.ICurrency): string | null;
|
|
52
|
-
interface ERC20TokenDetails extends ERC20SymbolDetails {
|
|
53
|
-
symbol: string;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Returns a list of supported ERC20 currencies
|
|
57
|
-
*
|
|
58
|
-
* @returns List of supported ERC20 currencies
|
|
59
|
-
*/
|
|
60
|
-
export declare function getSupportedERC20Tokens(): ERC20TokenDetails[];
|
|
61
|
-
export {};
|
|
62
|
-
//# sourceMappingURL=erc20.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"erc20.d.ts","sourceRoot":"","sources":["../../../src/api/currency/erc20.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE1D,OAAO,EAA+C,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAInG,UAAU,iBAAiB;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB;AASD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,GACd,iBAAiB,CAAC,SAAS,GAAG,SAAS,CAuBzC;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,iBAAiB,CAAC,SAAS,GAAG,MAAM,CAoB9E;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,MAAM,GAAG,iBAAiB,GAAG,SAAS,CAOzF;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,MAAM,GAAG,iBAAiB,GAAG,SAAS,CAQvF;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAE1D;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,iBAAiB,CAAC,SAAS,GAAG,MAAM,GAAG,IAAI,CAmBnF;AAED,UAAU,iBAAkB,SAAQ,kBAAkB;IACpD,MAAM,EAAE,MAAM,CAAC;CAChB;AACD;;;;GAIG;AACH,wBAAgB,uBAAuB,IAAI,iBAAiB,EAAE,CAkB7D"}
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSupportedERC20Tokens = exports.getErc20Symbol = exports.validERC20Address = exports.getMainnetErc20FromSymbol = exports.getMainnetErc20FromAddress = exports.getErc20Decimals = exports.getErc20Currency = void 0;
|
|
4
|
-
const types_1 = require("@requestnetwork/types");
|
|
5
|
-
const ethers_1 = require("ethers");
|
|
6
|
-
const networks_1 = require("./erc20/networks");
|
|
7
|
-
const supportedERC20Tokens = require('eth-contract-metadata');
|
|
8
|
-
/**
|
|
9
|
-
* Returns a Currency object for an ERC20, if found
|
|
10
|
-
* @param symbol The ERC20 token symbol
|
|
11
|
-
* @param network The ERC20 contract network
|
|
12
|
-
*/
|
|
13
|
-
function getErc20Currency(symbol, network) {
|
|
14
|
-
// If network is mainnet, check if it's one of the supported ERC20
|
|
15
|
-
if (!network || network === 'mainnet') {
|
|
16
|
-
const erc20Token = getMainnetErc20FromSymbol(symbol);
|
|
17
|
-
if (erc20Token) {
|
|
18
|
-
return {
|
|
19
|
-
network: 'mainnet',
|
|
20
|
-
type: types_1.RequestLogicTypes.CURRENCY.ERC20,
|
|
21
|
-
value: erc20Token.address,
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
// Check if it's on one of the other supported networks
|
|
26
|
-
if (network &&
|
|
27
|
-
networks_1.supportedNetworks.hasOwnProperty(network) &&
|
|
28
|
-
networks_1.supportedNetworks[network].has(symbol)) {
|
|
29
|
-
return networks_1.supportedNetworks[network].get(symbol);
|
|
30
|
-
}
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
exports.getErc20Currency = getErc20Currency;
|
|
34
|
-
/**
|
|
35
|
-
* Get the amount of decimals for an ERC20 currency
|
|
36
|
-
*
|
|
37
|
-
* @param currency The ERC20 Currency object
|
|
38
|
-
* @returns The number of decimals for the ERC20 currency
|
|
39
|
-
*/
|
|
40
|
-
function getErc20Decimals(currency) {
|
|
41
|
-
let erc20Token;
|
|
42
|
-
// Get the decimals from the supported mainnet ERC20
|
|
43
|
-
if (!currency.network || currency.network === 'mainnet') {
|
|
44
|
-
erc20Token = getMainnetErc20FromAddress(currency.value);
|
|
45
|
-
}
|
|
46
|
-
// Get the decimals from one of the supported ERC20 networks
|
|
47
|
-
if (currency.network && networks_1.supportedNetworksDetails.hasOwnProperty(currency.network)) {
|
|
48
|
-
erc20Token = Object.values(networks_1.supportedNetworksDetails[currency.network]).find(({ address }) => address === currency.value);
|
|
49
|
-
}
|
|
50
|
-
if (erc20Token) {
|
|
51
|
-
return erc20Token.decimals;
|
|
52
|
-
}
|
|
53
|
-
// If no supported ERC20 is found, throw error
|
|
54
|
-
throw new Error(`Unsupported ERC20 address: ${currency.value}`);
|
|
55
|
-
}
|
|
56
|
-
exports.getErc20Decimals = getErc20Decimals;
|
|
57
|
-
/**
|
|
58
|
-
* Get an ERC20 currency from the currency address
|
|
59
|
-
*
|
|
60
|
-
* @param address the ERC20 currency address
|
|
61
|
-
* @returns the ERC20 ITokenDescription
|
|
62
|
-
*/
|
|
63
|
-
function getMainnetErc20FromAddress(address) {
|
|
64
|
-
const checksumAddress = ethers_1.utils.getAddress(address);
|
|
65
|
-
const token = supportedERC20Tokens[checksumAddress];
|
|
66
|
-
if (!token || !token.erc20) {
|
|
67
|
-
return undefined;
|
|
68
|
-
}
|
|
69
|
-
return Object.assign(Object.assign({}, token), { address: checksumAddress });
|
|
70
|
-
}
|
|
71
|
-
exports.getMainnetErc20FromAddress = getMainnetErc20FromAddress;
|
|
72
|
-
/**
|
|
73
|
-
* Get an ERC20 currency from the currency value string, for mainnet only
|
|
74
|
-
*
|
|
75
|
-
* @param symbol the ERC20 currency symbol string
|
|
76
|
-
* @returns the ERC20 ITokenDescription
|
|
77
|
-
*/
|
|
78
|
-
function getMainnetErc20FromSymbol(symbol) {
|
|
79
|
-
const token = Object.entries(supportedERC20Tokens).find(([_, tokenObject]) => tokenObject.symbol === symbol && tokenObject.erc20);
|
|
80
|
-
if (!token) {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
return Object.assign(Object.assign({}, token[1]), { address: token[0] });
|
|
84
|
-
}
|
|
85
|
-
exports.getMainnetErc20FromSymbol = getMainnetErc20FromSymbol;
|
|
86
|
-
/**
|
|
87
|
-
* Returns true if the address is a valid checksum address
|
|
88
|
-
*
|
|
89
|
-
* @param address The address to validate
|
|
90
|
-
* @returns If the address is valid or not
|
|
91
|
-
*/
|
|
92
|
-
function validERC20Address(address) {
|
|
93
|
-
return ethers_1.utils.getAddress(address) === address;
|
|
94
|
-
}
|
|
95
|
-
exports.validERC20Address = validERC20Address;
|
|
96
|
-
/**
|
|
97
|
-
* Get an ERC20 symbol from the Currency object
|
|
98
|
-
*
|
|
99
|
-
* @param token the ERC20 ICurrency
|
|
100
|
-
* @returns the ERC20 currency symbol string
|
|
101
|
-
*/
|
|
102
|
-
function getErc20Symbol(currency) {
|
|
103
|
-
if (currency.type !== types_1.RequestLogicTypes.CURRENCY.ERC20) {
|
|
104
|
-
throw new Error('Can only get symbol for ERC20 currencies');
|
|
105
|
-
}
|
|
106
|
-
const checksumAddress = ethers_1.utils.getAddress(currency.value);
|
|
107
|
-
if (!currency.network || currency.network === 'mainnet') {
|
|
108
|
-
const token = supportedERC20Tokens[checksumAddress];
|
|
109
|
-
return token ? token.symbol : null;
|
|
110
|
-
}
|
|
111
|
-
// Find ERC20 symbol in one of the other supported ERC20 networks
|
|
112
|
-
if (networks_1.supportedNetworks.hasOwnProperty(currency.network)) {
|
|
113
|
-
const entry = [...networks_1.supportedNetworks[currency.network].entries()].find(([, obj]) => currency.value === obj.value);
|
|
114
|
-
return entry ? entry[0] : null;
|
|
115
|
-
}
|
|
116
|
-
return null;
|
|
117
|
-
}
|
|
118
|
-
exports.getErc20Symbol = getErc20Symbol;
|
|
119
|
-
/**
|
|
120
|
-
* Returns a list of supported ERC20 currencies
|
|
121
|
-
*
|
|
122
|
-
* @returns List of supported ERC20 currencies
|
|
123
|
-
*/
|
|
124
|
-
function getSupportedERC20Tokens() {
|
|
125
|
-
return Object.entries(supportedERC20Tokens)
|
|
126
|
-
.filter(([, { erc20 }]) => !!erc20)
|
|
127
|
-
.map(([address, { name, symbol, decimals }]) => ({ name, symbol, decimals, address }))
|
|
128
|
-
.concat(Object.entries(networks_1.supportedNetworksDetails).reduce((acc, [networkName, network]) => {
|
|
129
|
-
return [
|
|
130
|
-
...acc,
|
|
131
|
-
...Object.entries(network).map(([symbol, token]) => (Object.assign(Object.assign({}, token), { symbol: `${symbol}-${networkName}` }))),
|
|
132
|
-
];
|
|
133
|
-
}, []));
|
|
134
|
-
}
|
|
135
|
-
exports.getSupportedERC20Tokens = getSupportedERC20Tokens;
|
|
136
|
-
//# sourceMappingURL=erc20.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"erc20.js","sourceRoot":"","sources":["../../../src/api/currency/erc20.ts"],"names":[],"mappings":";;;AAAA,iDAA0D;AAC1D,mCAA+B;AAC/B,+CAAmG;AAkBnG,MAAM,oBAAoB,GAAG,OAAO,CAAC,uBAAuB,CAAc,CAAC;AAE3E;;;;GAIG;AACH,SAAgB,gBAAgB,CAC9B,MAAc,EACd,OAAe;IAEf,kEAAkE;IAClE,IAAI,CAAC,OAAO,IAAI,OAAO,KAAK,SAAS,EAAE;QACrC,MAAM,UAAU,GAAG,yBAAyB,CAAC,MAAM,CAAC,CAAC;QACrD,IAAI,UAAU,EAAE;YACd,OAAO;gBACL,OAAO,EAAE,SAAS;gBAClB,IAAI,EAAE,yBAAiB,CAAC,QAAQ,CAAC,KAAK;gBACtC,KAAK,EAAE,UAAU,CAAC,OAAO;aAC1B,CAAC;SACH;KACF;IAED,uDAAuD;IACvD,IACE,OAAO;QACP,4BAAiB,CAAC,cAAc,CAAC,OAAO,CAAC;QACzC,4BAAiB,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,EACtC;QACA,OAAO,4BAAiB,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;KAC/C;IAED,OAAO;AACT,CAAC;AA1BD,4CA0BC;AAED;;;;;GAKG;AACH,SAAgB,gBAAgB,CAAC,QAAqC;IACpE,IAAI,UAAU,CAAC;IACf,oDAAoD;IACpD,IAAI,CAAC,QAAQ,CAAC,OAAO,IAAI,QAAQ,C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C,OAAO,CAAC,oBAAoB,CAAC;SACxC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;SAClC,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;SACrF,MAAM,CACL,MAAM,CAAC,OAAO,CAAC,mCAAwB,CAAC,CAAC,MAAM,CAC7C,CAAC,GAAwB,EAAE,CAAC,WAAW,EAAE,OAAO,CAAC,EAAE,EAAE;QACnD,OAAO;YACL,GAAG,GAAG;YACN,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,iCAC/C,KAAK,KACR,MAAM,EAAE,GAAG,MAAM,IAAI,WAAW,EAAE,IAClC,CAAC;SACJ,CAAC;IACJ,CAAC,EACD,EAAE,CACH,CACF,CAAC;AACN,CAAC;AAlBD,0DAkBC"}
|
package/dist/api/currency.d.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { RequestLogicTypes } from '@requestnetwork/types';
|
|
2
|
-
/**
|
|
3
|
-
* Returns a Currency object from a user-friendly currency string.
|
|
4
|
-
* The string format is: [CURRENCY_NAME]-[network].
|
|
5
|
-
* The network is optional.
|
|
6
|
-
* E.g: BTC, ETH, ETH-rinkeby, SAI, USD, EUR
|
|
7
|
-
*
|
|
8
|
-
* @param currencyString The currency string to be formatted
|
|
9
|
-
*/
|
|
10
|
-
export declare function stringToCurrency(currencyString: string): RequestLogicTypes.ICurrency;
|
|
11
|
-
/**
|
|
12
|
-
* Converts a Currency object to a readable currency string
|
|
13
|
-
*
|
|
14
|
-
* @param currency The currency object to get the string from
|
|
15
|
-
* @returns The currency string identifier
|
|
16
|
-
*/
|
|
17
|
-
export declare function currencyToString(currency: RequestLogicTypes.ICurrency): string;
|
|
18
|
-
/**
|
|
19
|
-
* Returns the number of decimals for a currency
|
|
20
|
-
*
|
|
21
|
-
* @param currency The currency
|
|
22
|
-
* @returns The number of decimals
|
|
23
|
-
*/
|
|
24
|
-
export declare function getDecimalsForCurrency(currency: RequestLogicTypes.ICurrency): number;
|
|
25
|
-
/**
|
|
26
|
-
* Returns an object with all the supported currency by type
|
|
27
|
-
*
|
|
28
|
-
* @returns List of all supported currencies
|
|
29
|
-
*/
|
|
30
|
-
export declare function getAllSupportedCurrencies(): {
|
|
31
|
-
[type: string]: Array<{
|
|
32
|
-
name: string;
|
|
33
|
-
symbol: string;
|
|
34
|
-
decimals: number;
|
|
35
|
-
address?: string;
|
|
36
|
-
}>;
|
|
37
|
-
};
|
|
38
|
-
declare const _default: {
|
|
39
|
-
currencyToString: typeof currencyToString;
|
|
40
|
-
getAllSupportedCurrencies: typeof getAllSupportedCurrencies;
|
|
41
|
-
getDecimalsForCurrency: typeof getDecimalsForCurrency;
|
|
42
|
-
stringToCurrency: typeof stringToCurrency;
|
|
43
|
-
};
|
|
44
|
-
export default _default;
|
|
45
|
-
//# sourceMappingURL=currency.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"currency.d.ts","sourceRoot":"","sources":["../../src/api/currency.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAyC1D;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,cAAc,EAAE,MAAM,GAAG,iBAAiB,CAAC,SAAS,CAsBpF;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,iBAAiB,CAAC,SAAS,GAAG,MAAM,CA2B9E;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,iBAAiB,CAAC,SAAS,GAAG,MAAM,CAsBpF;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,IAAI;IAC3C,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC7F,CA8BA;;;;;;;AAED,wBAKE"}
|
package/dist/api/currency.js
DELETED
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getAllSupportedCurrencies = exports.getDecimalsForCurrency = exports.currencyToString = exports.stringToCurrency = void 0;
|
|
4
|
-
const types_1 = require("@requestnetwork/types");
|
|
5
|
-
const isoCurrencyCodes = require("currency-codes");
|
|
6
|
-
const erc20_1 = require("./currency/erc20");
|
|
7
|
-
// Simple function to get the currency from the value alone
|
|
8
|
-
const getCurrency = (currencyValue, network) => {
|
|
9
|
-
// Check if it's a supported cryptocurrency
|
|
10
|
-
if (currencyValue === 'BTC') {
|
|
11
|
-
return {
|
|
12
|
-
type: types_1.RequestLogicTypes.CURRENCY.BTC,
|
|
13
|
-
value: 'BTC',
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
if (currencyValue === 'ETH') {
|
|
17
|
-
return {
|
|
18
|
-
type: types_1.RequestLogicTypes.CURRENCY.ETH,
|
|
19
|
-
value: 'ETH',
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
// Check if it's an ERC20 token and return it if found
|
|
23
|
-
const erc20Currency = erc20_1.getErc20Currency(currencyValue, network);
|
|
24
|
-
if (erc20Currency) {
|
|
25
|
-
return erc20Currency;
|
|
26
|
-
}
|
|
27
|
-
// Check if it's one of ISO4217 currencies
|
|
28
|
-
if (isoCurrencyCodes.codes().includes(currencyValue)) {
|
|
29
|
-
return {
|
|
30
|
-
type: types_1.RequestLogicTypes.CURRENCY.ISO4217,
|
|
31
|
-
value: currencyValue,
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
throw new Error(`The currency ${currencyValue} is not supported`);
|
|
35
|
-
};
|
|
36
|
-
/**
|
|
37
|
-
* Returns a Currency object from a user-friendly currency string.
|
|
38
|
-
* The string format is: [CURRENCY_NAME]-[network].
|
|
39
|
-
* The network is optional.
|
|
40
|
-
* E.g: BTC, ETH, ETH-rinkeby, SAI, USD, EUR
|
|
41
|
-
*
|
|
42
|
-
* @param currencyString The currency string to be formatted
|
|
43
|
-
*/
|
|
44
|
-
function stringToCurrency(currencyString) {
|
|
45
|
-
// Check the string
|
|
46
|
-
if (!currencyString) {
|
|
47
|
-
throw new Error(`Currency string can't be empty.`);
|
|
48
|
-
}
|
|
49
|
-
// Split the currency string value and network (if available)
|
|
50
|
-
const [value, network] = currencyString.split('-');
|
|
51
|
-
const currency = getCurrency(value, network);
|
|
52
|
-
// If a network was declared, add it to the currency object
|
|
53
|
-
if (network) {
|
|
54
|
-
if (currency.network && currency.network !== network) {
|
|
55
|
-
throw new Error(`You can't declare a network with currency ${value}. It's only available on the network: ${currency.network} `);
|
|
56
|
-
}
|
|
57
|
-
currency.network = network;
|
|
58
|
-
}
|
|
59
|
-
return currency;
|
|
60
|
-
}
|
|
61
|
-
exports.stringToCurrency = stringToCurrency;
|
|
62
|
-
/**
|
|
63
|
-
* Converts a Currency object to a readable currency string
|
|
64
|
-
*
|
|
65
|
-
* @param currency The currency object to get the string from
|
|
66
|
-
* @returns The currency string identifier
|
|
67
|
-
*/
|
|
68
|
-
function currencyToString(currency) {
|
|
69
|
-
let symbol;
|
|
70
|
-
switch (currency.type) {
|
|
71
|
-
case types_1.RequestLogicTypes.CURRENCY.BTC:
|
|
72
|
-
case types_1.RequestLogicTypes.CURRENCY.ETH:
|
|
73
|
-
symbol = currency.type;
|
|
74
|
-
break;
|
|
75
|
-
case types_1.RequestLogicTypes.CURRENCY.ISO4217:
|
|
76
|
-
symbol = currency.value;
|
|
77
|
-
break;
|
|
78
|
-
case types_1.RequestLogicTypes.CURRENCY.ERC20:
|
|
79
|
-
symbol = erc20_1.getErc20Symbol(currency) || 'unknown';
|
|
80
|
-
break;
|
|
81
|
-
default:
|
|
82
|
-
symbol = 'unknown';
|
|
83
|
-
}
|
|
84
|
-
// Return without network if we don't recognize the symbol
|
|
85
|
-
if (symbol === 'unknown') {
|
|
86
|
-
return symbol;
|
|
87
|
-
}
|
|
88
|
-
// If the currency have a network, append it to the currency symbol
|
|
89
|
-
const network = currency.network && currency.network !== 'mainnet' ? `-${currency.network}` : '';
|
|
90
|
-
return symbol + network;
|
|
91
|
-
}
|
|
92
|
-
exports.currencyToString = currencyToString;
|
|
93
|
-
/**
|
|
94
|
-
* Returns the number of decimals for a currency
|
|
95
|
-
*
|
|
96
|
-
* @param currency The currency
|
|
97
|
-
* @returns The number of decimals
|
|
98
|
-
*/
|
|
99
|
-
function getDecimalsForCurrency(currency) {
|
|
100
|
-
if (currency.type === types_1.RequestLogicTypes.CURRENCY.ERC20) {
|
|
101
|
-
return erc20_1.getErc20Decimals(currency);
|
|
102
|
-
}
|
|
103
|
-
// Return the number of decimals for ISO-4217 currencies
|
|
104
|
-
if (currency.type === types_1.RequestLogicTypes.CURRENCY.ISO4217) {
|
|
105
|
-
const iso = isoCurrencyCodes.code(currency.value);
|
|
106
|
-
if (!iso) {
|
|
107
|
-
throw new Error(`Unsupported ISO currency ${currency.value}`);
|
|
108
|
-
}
|
|
109
|
-
return iso.digits;
|
|
110
|
-
}
|
|
111
|
-
const decimals = {
|
|
112
|
-
[types_1.RequestLogicTypes.CURRENCY.ETH]: 18,
|
|
113
|
-
[types_1.RequestLogicTypes.CURRENCY.BTC]: 8,
|
|
114
|
-
}[currency.type];
|
|
115
|
-
if (!decimals) {
|
|
116
|
-
throw new Error(`Currency ${currency.type} not implemented`);
|
|
117
|
-
}
|
|
118
|
-
return decimals;
|
|
119
|
-
}
|
|
120
|
-
exports.getDecimalsForCurrency = getDecimalsForCurrency;
|
|
121
|
-
/**
|
|
122
|
-
* Returns an object with all the supported currency by type
|
|
123
|
-
*
|
|
124
|
-
* @returns List of all supported currencies
|
|
125
|
-
*/
|
|
126
|
-
function getAllSupportedCurrencies() {
|
|
127
|
-
// Creates the list of ISO currencies
|
|
128
|
-
const isoCurrencyData = require('currency-codes/data');
|
|
129
|
-
const isoCurrencies = isoCurrencyData.map(cc => ({
|
|
130
|
-
decimals: cc.digits,
|
|
131
|
-
name: cc.currency,
|
|
132
|
-
symbol: cc.code,
|
|
133
|
-
}));
|
|
134
|
-
// Gets the list of ERC20 currencies
|
|
135
|
-
const erc20Currencies = erc20_1.getSupportedERC20Tokens();
|
|
136
|
-
return {
|
|
137
|
-
[types_1.RequestLogicTypes.CURRENCY.ETH]: [
|
|
138
|
-
{
|
|
139
|
-
decimals: 18,
|
|
140
|
-
name: 'Ether',
|
|
141
|
-
symbol: 'ETH',
|
|
142
|
-
},
|
|
143
|
-
],
|
|
144
|
-
[types_1.RequestLogicTypes.CURRENCY.BTC]: [
|
|
145
|
-
{
|
|
146
|
-
decimals: 8,
|
|
147
|
-
name: 'Bitcoin',
|
|
148
|
-
symbol: 'BTC',
|
|
149
|
-
},
|
|
150
|
-
],
|
|
151
|
-
[types_1.RequestLogicTypes.CURRENCY.ISO4217]: isoCurrencies,
|
|
152
|
-
[types_1.RequestLogicTypes.CURRENCY.ERC20]: erc20Currencies,
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
exports.getAllSupportedCurrencies = getAllSupportedCurrencies;
|
|
156
|
-
exports.default = {
|
|
157
|
-
currencyToString,
|
|
158
|
-
getAllSupportedCurrencies,
|
|
159
|
-
getDecimalsForCurrency,
|
|
160
|
-
stringToCurrency,
|
|
161
|
-
};
|
|
162
|
-
//# sourceMappingURL=currency.js.map
|
package/dist/api/currency.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"currency.js","sourceRoot":"","sources":["../../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IAAI,EAAE,OAAO;gBACb,MAAM,EAAE,KAAK;aACd;SACF;QACD,CAAC,yBAAiB,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;YAChC;gBACE,QAAQ,EAAE,CAAC;gBACX,IAAI,EAAE,SAAS;gBACf,MAAM,EAAE,KAAK;aACd;SACF;QACD,CAAC,yBAAiB,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,aAAa;QACnD,CAAC,yBAAiB,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,eAAe;KACpD,CAAC;AACJ,CAAC;AAhCD,8DAgCC;AAED,kBAAe;IACb,gBAAgB;IAChB,yBAAyB;IACzB,sBAAsB;IACtB,gBAAgB;CACjB,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { DataAccess } from '@requestnetwork/data-access';
|
|
2
|
-
import { StorageTypes } from '@requestnetwork/types';
|
|
3
|
-
/**
|
|
4
|
-
* Mock Data access that bypasses the initialization.
|
|
5
|
-
* This class is meant to be used with HttpRequestNetwork and useMockStorage=true.
|
|
6
|
-
* Data-access initialization is asynchronous and this class is a hack to avoid having an asynchronous operation in the HttpRequestNetwork constructor.
|
|
7
|
-
*/
|
|
8
|
-
export default class MockDataAccess extends DataAccess {
|
|
9
|
-
constructor(storage: StorageTypes.IStorage);
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=mock-data-access.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mock-data-access.d.ts","sourceRoot":"","sources":["../src/mock-data-access.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,UAAU;gBACxC,OAAO,EAAE,YAAY,CAAC,QAAQ;CAI3C"}
|
package/dist/mock-data-access.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const data_access_1 = require("@requestnetwork/data-access");
|
|
4
|
-
/**
|
|
5
|
-
* Mock Data access that bypasses the initialization.
|
|
6
|
-
* This class is meant to be used with HttpRequestNetwork and useMockStorage=true.
|
|
7
|
-
* Data-access initialization is asynchronous and this class is a hack to avoid having an asynchronous operation in the HttpRequestNetwork constructor.
|
|
8
|
-
*/
|
|
9
|
-
class MockDataAccess extends data_access_1.DataAccess {
|
|
10
|
-
constructor(storage) {
|
|
11
|
-
super(storage);
|
|
12
|
-
this.isInitialized = true;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
exports.default = MockDataAccess;
|
|
16
|
-
//# sourceMappingURL=mock-data-access.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mock-data-access.js","sourceRoot":"","sources":["../src/mock-data-access.ts"],"names":[],"mappings":";;AAAA,6DAAyD;AAGzD;;;;GAIG;AACH,MAAqB,cAAe,SAAQ,wBAAU;IACpD,YAAY,OAA8B;QACxC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;IAC5B,CAAC;CACF;AALD,iCAKC"}
|