@ledgerhq/context-module 0.0.2-nightly.0 → 0.0.2-nightly.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/ContextModule.d.ts +7 -0
- package/lib/ContextModule.d.ts.map +1 -0
- package/lib/ContextModule.js +3 -0
- package/lib/ContextModule.js.map +1 -0
- package/lib/DefaultContextModule.d.ts +15 -0
- package/lib/DefaultContextModule.d.ts.map +1 -0
- package/lib/DefaultContextModule.js +26 -0
- package/lib/DefaultContextModule.js.map +1 -0
- package/lib/DefaultContextModule.test.d.ts +2 -0
- package/lib/DefaultContextModule.test.d.ts.map +1 -0
- package/lib/DefaultContextModule.test.js +45 -0
- package/lib/DefaultContextModule.test.js.map +1 -0
- package/lib/external-plugin/__tests__/abi.json +92 -0
- package/lib/external-plugin/data/DAppDto.d.ts +38 -0
- package/lib/external-plugin/data/DAppDto.d.ts.map +1 -0
- package/lib/external-plugin/data/DAppDto.js +3 -0
- package/lib/external-plugin/data/DAppDto.js.map +1 -0
- package/lib/external-plugin/data/ExternalPluginDataSource.d.ts +10 -0
- package/lib/external-plugin/data/ExternalPluginDataSource.d.ts.map +1 -0
- package/lib/external-plugin/data/ExternalPluginDataSource.js +3 -0
- package/lib/external-plugin/data/ExternalPluginDataSource.js.map +1 -0
- package/lib/external-plugin/data/HttpExternalPluginDataSource.d.ts +7 -0
- package/lib/external-plugin/data/HttpExternalPluginDataSource.d.ts.map +1 -0
- package/lib/external-plugin/data/HttpExternalPluginDataSource.js +50 -0
- package/lib/external-plugin/data/HttpExternalPluginDataSource.js.map +1 -0
- package/lib/external-plugin/data/HttpExternalPluginDataSource.test.d.ts +2 -0
- package/lib/external-plugin/data/HttpExternalPluginDataSource.test.d.ts.map +1 -0
- package/lib/external-plugin/data/HttpExternalPluginDataSource.test.js +260 -0
- package/lib/external-plugin/data/HttpExternalPluginDataSource.test.js.map +1 -0
- package/lib/external-plugin/domain/ExternalPluginContextLoader.d.ts +15 -0
- package/lib/external-plugin/domain/ExternalPluginContextLoader.d.ts.map +1 -0
- package/lib/external-plugin/domain/ExternalPluginContextLoader.js +96 -0
- package/lib/external-plugin/domain/ExternalPluginContextLoader.js.map +1 -0
- package/lib/external-plugin/domain/ExternalPluginContextLoader.test.d.ts +2 -0
- package/lib/external-plugin/domain/ExternalPluginContextLoader.test.d.ts.map +1 -0
- package/lib/external-plugin/domain/ExternalPluginContextLoader.test.js +345 -0
- package/lib/external-plugin/domain/ExternalPluginContextLoader.test.js.map +1 -0
- package/lib/external-plugin/model/DappInfos.d.ts +6 -0
- package/lib/external-plugin/model/DappInfos.d.ts.map +1 -0
- package/lib/external-plugin/model/DappInfos.js +3 -0
- package/lib/external-plugin/model/DappInfos.js.map +1 -0
- package/lib/external-plugin/model/SelectorDetails.d.ts +8 -0
- package/lib/external-plugin/model/SelectorDetails.d.ts.map +1 -0
- package/lib/external-plugin/model/SelectorDetails.js +3 -0
- package/lib/external-plugin/model/SelectorDetails.js.map +1 -0
- package/lib/forward-domain/data/ForwardDomainDataSource.d.ts +8 -0
- package/lib/forward-domain/data/ForwardDomainDataSource.d.ts.map +1 -0
- package/lib/forward-domain/data/ForwardDomainDataSource.js +3 -0
- package/lib/forward-domain/data/ForwardDomainDataSource.js.map +1 -0
- package/lib/forward-domain/data/HttpForwardDomainDataSource.d.ts +5 -0
- package/lib/forward-domain/data/HttpForwardDomainDataSource.d.ts.map +1 -0
- package/lib/forward-domain/data/HttpForwardDomainDataSource.js +31 -0
- package/lib/forward-domain/data/HttpForwardDomainDataSource.js.map +1 -0
- package/lib/forward-domain/data/HttpForwardDomainDataSource.test.d.ts +2 -0
- package/lib/forward-domain/data/HttpForwardDomainDataSource.test.d.ts.map +1 -0
- package/lib/forward-domain/data/HttpForwardDomainDataSource.test.js +36 -0
- package/lib/forward-domain/data/HttpForwardDomainDataSource.test.js.map +1 -0
- package/lib/forward-domain/domain/ForwardDomainContextLoader.d.ts +12 -0
- package/lib/forward-domain/domain/ForwardDomainContextLoader.d.ts.map +1 -0
- package/lib/forward-domain/domain/ForwardDomainContextLoader.js +50 -0
- package/lib/forward-domain/domain/ForwardDomainContextLoader.js.map +1 -0
- package/lib/forward-domain/domain/ForwardDomainContextLoader.test.d.ts +2 -0
- package/lib/forward-domain/domain/ForwardDomainContextLoader.test.d.ts.map +1 -0
- package/lib/forward-domain/domain/ForwardDomainContextLoader.test.js +85 -0
- package/lib/forward-domain/domain/ForwardDomainContextLoader.test.js.map +1 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +20 -0
- package/lib/index.js.map +1 -0
- package/lib/nft/data/HttpNftDataSource.d.ts +6 -0
- package/lib/nft/data/HttpNftDataSource.d.ts.map +1 -0
- package/lib/nft/data/HttpNftDataSource.js +41 -0
- package/lib/nft/data/HttpNftDataSource.js.map +1 -0
- package/lib/nft/data/HttpNftDataSource.test.d.ts +2 -0
- package/lib/nft/data/HttpNftDataSource.test.d.ts.map +1 -0
- package/lib/nft/data/HttpNftDataSource.test.js +38 -0
- package/lib/nft/data/HttpNftDataSource.test.js.map +1 -0
- package/lib/nft/data/NftDataSource.d.ts +14 -0
- package/lib/nft/data/NftDataSource.d.ts.map +1 -0
- package/lib/nft/data/NftDataSource.js +3 -0
- package/lib/nft/data/NftDataSource.js.map +1 -0
- package/lib/nft/domain/NftContextLoader.d.ts +12 -0
- package/lib/nft/domain/NftContextLoader.d.ts.map +1 -0
- package/lib/nft/domain/NftContextLoader.js +79 -0
- package/lib/nft/domain/NftContextLoader.js.map +1 -0
- package/lib/nft/domain/NftContextLoader.test.d.ts +2 -0
- package/lib/nft/domain/NftContextLoader.test.d.ts.map +1 -0
- package/lib/nft/domain/NftContextLoader.test.js +113 -0
- package/lib/nft/domain/NftContextLoader.test.js.map +1 -0
- package/lib/shared/domain/ContextLoader.d.ts +7 -0
- package/lib/shared/domain/ContextLoader.d.ts.map +1 -0
- package/lib/shared/domain/ContextLoader.js +3 -0
- package/lib/shared/domain/ContextLoader.js.map +1 -0
- package/lib/shared/model/ContextResponse.d.ts +11 -0
- package/lib/shared/model/ContextResponse.d.ts.map +1 -0
- package/lib/shared/model/ContextResponse.js +3 -0
- package/lib/shared/model/ContextResponse.js.map +1 -0
- package/lib/shared/model/LoaderOptions.d.ts +10 -0
- package/lib/shared/model/LoaderOptions.d.ts.map +1 -0
- package/lib/shared/model/LoaderOptions.js +3 -0
- package/lib/shared/model/LoaderOptions.js.map +1 -0
- package/lib/shared/model/Transaction.d.ts +2 -0
- package/lib/shared/model/Transaction.d.ts.map +1 -0
- package/lib/shared/model/Transaction.js +3 -0
- package/lib/shared/model/Transaction.js.map +1 -0
- package/lib/token/data/HttpTokenDataSource.d.ts +5 -0
- package/lib/token/data/HttpTokenDataSource.d.ts.map +1 -0
- package/lib/token/data/HttpTokenDataSource.js +33 -0
- package/lib/token/data/HttpTokenDataSource.js.map +1 -0
- package/lib/token/data/HttpTokenDataSource.test.d.ts +2 -0
- package/lib/token/data/HttpTokenDataSource.test.d.ts.map +1 -0
- package/lib/token/data/HttpTokenDataSource.test.js +61 -0
- package/lib/token/data/HttpTokenDataSource.test.js.map +1 -0
- package/lib/token/data/TokenDataSource.d.ts +8 -0
- package/lib/token/data/TokenDataSource.d.ts.map +1 -0
- package/lib/token/data/TokenDataSource.js +3 -0
- package/lib/token/data/TokenDataSource.js.map +1 -0
- package/lib/token/data/TokenDto.d.ts +4 -0
- package/lib/token/data/TokenDto.d.ts.map +1 -0
- package/lib/token/data/TokenDto.js +3 -0
- package/lib/token/data/TokenDto.js.map +1 -0
- package/lib/token/domain/TokenContextLoader.d.ts +16 -0
- package/lib/token/domain/TokenContextLoader.d.ts.map +1 -0
- package/lib/token/domain/TokenContextLoader.js +52 -0
- package/lib/token/domain/TokenContextLoader.js.map +1 -0
- package/lib/token/domain/TokenContextLoader.test.d.ts +2 -0
- package/lib/token/domain/TokenContextLoader.test.d.ts.map +1 -0
- package/lib/token/domain/TokenContextLoader.test.js +97 -0
- package/lib/token/domain/TokenContextLoader.test.js.map +1 -0
- package/package.json +3 -2
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ContextResponse } from "./shared/model/ContextResponse";
|
|
2
|
+
import { LoaderOptions } from "./shared/model/LoaderOptions";
|
|
3
|
+
import { Transaction } from "./shared/model/Transaction";
|
|
4
|
+
export interface ContextModule {
|
|
5
|
+
getContexts(transaction: Transaction, options: LoaderOptions): Promise<ContextResponse[]>;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=ContextModule.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContextModule.d.ts","sourceRoot":"","sources":["../src/ContextModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAEzD,MAAM,WAAW,aAAa;IAC5B,WAAW,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC,CAAC;CAC3F"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContextModule.js","sourceRoot":"","sources":["../src/ContextModule.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ContextModule } from "./ContextModule";
|
|
2
|
+
import { ContextLoader } from "./shared/domain/ContextLoader";
|
|
3
|
+
import { ContextResponse } from "./shared/model/ContextResponse";
|
|
4
|
+
import { LoaderOptions } from "./shared/model/LoaderOptions";
|
|
5
|
+
import { Transaction } from "./shared/model/Transaction";
|
|
6
|
+
type DefaultContextModuleConstructorArgs = {
|
|
7
|
+
loaders: ContextLoader[];
|
|
8
|
+
};
|
|
9
|
+
export declare class DefaultContextModule implements ContextModule {
|
|
10
|
+
private _loaders;
|
|
11
|
+
constructor({ loaders: loaders }: DefaultContextModuleConstructorArgs);
|
|
12
|
+
getContexts(transaction: Transaction, options: LoaderOptions): Promise<ContextResponse[]>;
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=DefaultContextModule.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DefaultContextModule.d.ts","sourceRoot":"","sources":["../src/DefaultContextModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAEzD,KAAK,mCAAmC,GAAG;IACzC,OAAO,EAAE,aAAa,EAAE,CAAC;CAC1B,CAAC;AAEF,qBAAa,oBAAqB,YAAW,aAAa;IACxD,OAAO,CAAC,QAAQ,CAAkB;gBAEtB,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,mCAAmC;IAIxD,WAAW,CACtB,WAAW,EAAE,WAAW,EACxB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,eAAe,EAAE,CAAC;CAK9B"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.DefaultContextModule = void 0;
|
|
13
|
+
class DefaultContextModule {
|
|
14
|
+
constructor({ loaders: loaders }) {
|
|
15
|
+
this._loaders = loaders;
|
|
16
|
+
}
|
|
17
|
+
getContexts(transaction, options) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
const promises = this._loaders.map(fetcher => fetcher.load(transaction, options));
|
|
20
|
+
const responses = yield Promise.all(promises);
|
|
21
|
+
return responses.flat();
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.DefaultContextModule = DefaultContextModule;
|
|
26
|
+
//# sourceMappingURL=DefaultContextModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DefaultContextModule.js","sourceRoot":"","sources":["../src/DefaultContextModule.ts"],"names":[],"mappings":";;;;;;;;;;;;AAUA,MAAa,oBAAoB;IAG/B,YAAY,EAAE,OAAO,EAAE,OAAO,EAAuC;QACnE,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAEY,WAAW,CACtB,WAAwB,EACxB,OAAsB;;YAEtB,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC;YAClF,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YAC9C,OAAO,SAAS,CAAC,IAAI,EAAE,CAAC;QAC1B,CAAC;KAAA;CACF;AAfD,oDAeC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DefaultContextModule.test.d.ts","sourceRoot":"","sources":["../src/DefaultContextModule.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const DefaultContextModule_1 = require("./DefaultContextModule");
|
|
13
|
+
const contextLoaderStubBuilder = () => {
|
|
14
|
+
return { load: jest.fn() };
|
|
15
|
+
};
|
|
16
|
+
describe("DefaultContextModule", () => {
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
jest.restoreAllMocks();
|
|
19
|
+
});
|
|
20
|
+
it("should call all fetch method from metadata fetcher", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
+
const loader = contextLoaderStubBuilder();
|
|
22
|
+
const contextModule = new DefaultContextModule_1.DefaultContextModule({ loaders: [loader, loader] });
|
|
23
|
+
yield contextModule.getContexts({}, {});
|
|
24
|
+
expect(loader.load).toHaveBeenCalledTimes(2);
|
|
25
|
+
}));
|
|
26
|
+
it("should return an array of context response", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
+
const loader = contextLoaderStubBuilder();
|
|
28
|
+
const responses = [
|
|
29
|
+
[{ type: "provideERC20Info", payload: "payload1" }],
|
|
30
|
+
[
|
|
31
|
+
{ type: "provideERC20Info", payload: "payload2" },
|
|
32
|
+
{ type: "setPlugin", payload: "payload3" },
|
|
33
|
+
],
|
|
34
|
+
];
|
|
35
|
+
jest
|
|
36
|
+
.spyOn(loader, "load")
|
|
37
|
+
.mockResolvedValueOnce(responses[0])
|
|
38
|
+
.mockResolvedValueOnce(responses[1]);
|
|
39
|
+
const contextModule = new DefaultContextModule_1.DefaultContextModule({ loaders: [loader, loader] });
|
|
40
|
+
const res = yield contextModule.getContexts({}, {});
|
|
41
|
+
expect(loader.load).toHaveBeenCalledTimes(2);
|
|
42
|
+
expect(res).toEqual(responses.flat());
|
|
43
|
+
}));
|
|
44
|
+
});
|
|
45
|
+
//# sourceMappingURL=DefaultContextModule.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DefaultContextModule.test.js","sourceRoot":"","sources":["../src/DefaultContextModule.test.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,iEAA8D;AAI9D,MAAM,wBAAwB,GAAG,GAAG,EAAE;IACpC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC;AAC7B,CAAC,CAAC;AAEF,QAAQ,CAAC,sBAAsB,EAAE,GAAG,EAAE;IACpC,UAAU,CAAC,GAAG,EAAE;QACd,IAAI,CAAC,eAAe,EAAE,CAAC;IACzB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,oDAAoD,EAAE,GAAS,EAAE;QAClE,MAAM,MAAM,GAAG,wBAAwB,EAAE,CAAC;QAC1C,MAAM,aAAa,GAAG,IAAI,2CAAoB,CAAC,EAAE,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;QAE9E,MAAM,aAAa,CAAC,WAAW,CAAC,EAAiB,EAAE,EAAmB,CAAC,CAAC;QAExE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;IAC/C,CAAC,CAAA,CAAC,CAAC;IAEH,EAAE,CAAC,4CAA4C,EAAE,GAAS,EAAE;QAC1D,MAAM,MAAM,GAAG,wBAAwB,EAAE,CAAC;QAC1C,MAAM,SAAS,GAAG;YAChB,CAAC,EAAE,IAAI,EAAE,kBAAkB,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC;YACnD;gBACE,EAAE,IAAI,EAAE,kBAAkB,EAAE,OAAO,EAAE,UAAU,EAAE;gBACjD,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,UAAU,EAAE;aAC3C;SACF,CAAC;QACF,IAAI;aACD,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC;aACrB,qBAAqB,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;aACnC,qBAAqB,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;QACvC,MAAM,aAAa,GAAG,IAAI,2CAAoB,CAAC,EAAE,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;QAE9E,MAAM,GAAG,GAAG,MAAM,aAAa,CAAC,WAAW,CAAC,EAAiB,EAAE,EAAmB,CAAC,CAAC;QAEpF,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;QAC7C,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC;IACxC,CAAC,CAAA,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"inputs": [
|
|
4
|
+
{
|
|
5
|
+
"internalType": "address[]",
|
|
6
|
+
"name": "fromToken",
|
|
7
|
+
"type": "address[]"
|
|
8
|
+
}
|
|
9
|
+
],
|
|
10
|
+
"name": "arrayParam",
|
|
11
|
+
"outputs": [],
|
|
12
|
+
"stateMutability": "nonpayable",
|
|
13
|
+
"type": "function"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"inputs": [
|
|
17
|
+
{
|
|
18
|
+
"components": [
|
|
19
|
+
{
|
|
20
|
+
"internalType": "address",
|
|
21
|
+
"name": "address1",
|
|
22
|
+
"type": "address"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"components": [
|
|
26
|
+
{
|
|
27
|
+
"components": [
|
|
28
|
+
{
|
|
29
|
+
"components": [
|
|
30
|
+
{
|
|
31
|
+
"internalType": "address[]",
|
|
32
|
+
"name": "addresses",
|
|
33
|
+
"type": "address[]"
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
"internalType": "struct SimpleContract.Struct3",
|
|
37
|
+
"name": "param3",
|
|
38
|
+
"type": "tuple"
|
|
39
|
+
}
|
|
40
|
+
],
|
|
41
|
+
"internalType": "struct SimpleContract.Struct2[]",
|
|
42
|
+
"name": "param2",
|
|
43
|
+
"type": "tuple[]"
|
|
44
|
+
}
|
|
45
|
+
],
|
|
46
|
+
"internalType": "struct SimpleContract.Struct1",
|
|
47
|
+
"name": "param1",
|
|
48
|
+
"type": "tuple"
|
|
49
|
+
}
|
|
50
|
+
],
|
|
51
|
+
"internalType": "struct SimpleContract.ComplexStruct",
|
|
52
|
+
"name": "complexStruct",
|
|
53
|
+
"type": "tuple"
|
|
54
|
+
}
|
|
55
|
+
],
|
|
56
|
+
"name": "complexStructParam",
|
|
57
|
+
"outputs": [],
|
|
58
|
+
"stateMutability": "nonpayable",
|
|
59
|
+
"type": "function"
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"inputs": [
|
|
63
|
+
{
|
|
64
|
+
"internalType": "address",
|
|
65
|
+
"name": "fromToken",
|
|
66
|
+
"type": "address"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"internalType": "address",
|
|
70
|
+
"name": "toToken",
|
|
71
|
+
"type": "address"
|
|
72
|
+
}
|
|
73
|
+
],
|
|
74
|
+
"name": "multipleParams",
|
|
75
|
+
"outputs": [],
|
|
76
|
+
"stateMutability": "nonpayable",
|
|
77
|
+
"type": "function"
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"inputs": [
|
|
81
|
+
{
|
|
82
|
+
"internalType": "address",
|
|
83
|
+
"name": "fromToken",
|
|
84
|
+
"type": "address"
|
|
85
|
+
}
|
|
86
|
+
],
|
|
87
|
+
"name": "singleParam",
|
|
88
|
+
"outputs": [],
|
|
89
|
+
"stateMutability": "nonpayable",
|
|
90
|
+
"type": "function"
|
|
91
|
+
}
|
|
92
|
+
]
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export interface DAppDto {
|
|
2
|
+
b2c: B2c;
|
|
3
|
+
abis: Abis;
|
|
4
|
+
b2c_signatures: B2cSignatures;
|
|
5
|
+
}
|
|
6
|
+
export interface B2c {
|
|
7
|
+
blockchainName: string;
|
|
8
|
+
chainId: number;
|
|
9
|
+
contracts: Contract[];
|
|
10
|
+
name: string;
|
|
11
|
+
}
|
|
12
|
+
interface Contract {
|
|
13
|
+
address: string;
|
|
14
|
+
contractName: string;
|
|
15
|
+
selectors: {
|
|
16
|
+
[selector: string]: ContractSelector;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
interface ContractSelector {
|
|
20
|
+
erc20OfInterest: string[];
|
|
21
|
+
method: string;
|
|
22
|
+
plugin: string;
|
|
23
|
+
}
|
|
24
|
+
export interface Abis {
|
|
25
|
+
[address: string]: object[];
|
|
26
|
+
}
|
|
27
|
+
export interface B2cSignatures {
|
|
28
|
+
[address: string]: {
|
|
29
|
+
[selector: string]: B2cSignature;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
interface B2cSignature {
|
|
33
|
+
plugin: string;
|
|
34
|
+
serialized_data: string;
|
|
35
|
+
signature: string;
|
|
36
|
+
}
|
|
37
|
+
export {};
|
|
38
|
+
//# sourceMappingURL=DAppDto.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DAppDto.d.ts","sourceRoot":"","sources":["../../../src/external-plugin/data/DAppDto.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,OAAO;IACtB,GAAG,EAAE,GAAG,CAAC;IACT,IAAI,EAAE,IAAI,CAAC;IACX,cAAc,EAAE,aAAa,CAAC;CAC/B;AAED,MAAM,WAAW,GAAG;IAClB,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,QAAQ,EAAE,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,UAAU,QAAQ;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE;QAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,gBAAgB,CAAA;KAAE,CAAC;CACrD;AAED,UAAU,gBAAgB;IACxB,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,IAAI;IACnB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAC7B;AAED,MAAM,WAAW,aAAa;IAC5B,CAAC,OAAO,EAAE,MAAM,GAAG;QACjB,CAAC,QAAQ,EAAE,MAAM,GAAG,YAAY,CAAC;KAClC,CAAC;CACH;AAED,UAAU,YAAY;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;CACnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DAppDto.js","sourceRoot":"","sources":["../../../src/external-plugin/data/DAppDto.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DappInfos } from "../model/DappInfos";
|
|
2
|
+
export type GetDappInfos = {
|
|
3
|
+
address: string;
|
|
4
|
+
selector: `0x${string}`;
|
|
5
|
+
chainId: number;
|
|
6
|
+
};
|
|
7
|
+
export interface ExternalPluginDataSource {
|
|
8
|
+
getDappInfos(params: GetDappInfos): Promise<DappInfos | undefined>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=ExternalPluginDataSource.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExternalPluginDataSource.d.ts","sourceRoot":"","sources":["../../../src/external-plugin/data/ExternalPluginDataSource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,MAAM,MAAM,YAAY,GAAG;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,KAAK,MAAM,EAAE,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,WAAW,wBAAwB;IACvC,YAAY,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC,CAAC;CACpE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExternalPluginDataSource.js","sourceRoot":"","sources":["../../../src/external-plugin/data/ExternalPluginDataSource.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ExternalPluginDataSource, GetDappInfos } from "./ExternalPluginDataSource";
|
|
2
|
+
import { DappInfos } from "../model/DappInfos";
|
|
3
|
+
export declare class HttpExternalPluginDataSource implements ExternalPluginDataSource {
|
|
4
|
+
constructor();
|
|
5
|
+
getDappInfos({ chainId, address, selector }: GetDappInfos): Promise<DappInfos | undefined>;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=HttpExternalPluginDataSource.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpExternalPluginDataSource.d.ts","sourceRoot":"","sources":["../../../src/external-plugin/data/HttpExternalPluginDataSource.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAEpF,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAI/C,qBAAa,4BAA6B,YAAW,wBAAwB;;IAGrE,YAAY,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,YAAY,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;CAiCjG"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.HttpExternalPluginDataSource = void 0;
|
|
16
|
+
const axios_1 = __importDefault(require("axios"));
|
|
17
|
+
const package_json_1 = __importDefault(require("../../../package.json"));
|
|
18
|
+
class HttpExternalPluginDataSource {
|
|
19
|
+
constructor() { }
|
|
20
|
+
getDappInfos(_a) {
|
|
21
|
+
return __awaiter(this, arguments, void 0, function* ({ chainId, address, selector }) {
|
|
22
|
+
var _b, _c, _d, _e, _f, _g, _h, _j;
|
|
23
|
+
const dappInfos = yield axios_1.default.request({
|
|
24
|
+
method: "GET",
|
|
25
|
+
url: "https://crypto-assets-service.api.ledger.com/v1/dapps",
|
|
26
|
+
params: { output: "b2c,b2c_signatures,abis", chain_id: chainId, contracts: address },
|
|
27
|
+
headers: { "X-Ledger-Client-Version": `context-module/${package_json_1.default.version}` },
|
|
28
|
+
});
|
|
29
|
+
const { erc20OfInterest, method, plugin } = ((_e = (_d = (_c = (_b = dappInfos.data[0]) === null || _b === void 0 ? void 0 : _b.b2c.contracts) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.selectors) === null || _e === void 0 ? void 0 : _e[selector]) || {};
|
|
30
|
+
const { signature, serialized_data: serializedData } = ((_h = (_g = (_f = dappInfos.data[0]) === null || _f === void 0 ? void 0 : _f.b2c_signatures) === null || _g === void 0 ? void 0 : _g[address]) === null || _h === void 0 ? void 0 : _h[selector]) || {};
|
|
31
|
+
if (!erc20OfInterest || !method || !plugin || !signature || !serializedData) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const abi = (_j = dappInfos.data[0].abis) === null || _j === void 0 ? void 0 : _j[address];
|
|
35
|
+
if (!abi) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const selectorDetails = {
|
|
39
|
+
method,
|
|
40
|
+
plugin,
|
|
41
|
+
erc20OfInterest,
|
|
42
|
+
signature,
|
|
43
|
+
serializedData,
|
|
44
|
+
};
|
|
45
|
+
return { selectorDetails, abi };
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.HttpExternalPluginDataSource = HttpExternalPluginDataSource;
|
|
50
|
+
//# sourceMappingURL=HttpExternalPluginDataSource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpExternalPluginDataSource.js","sourceRoot":"","sources":["../../../src/external-plugin/data/HttpExternalPluginDataSource.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kDAA0B;AAK1B,yEAA4C;AAE5C,MAAa,4BAA4B;IACvC,gBAAe,CAAC;IAEV,YAAY;6DAAC,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAgB;;YAC7D,MAAM,SAAS,GAAG,MAAM,eAAK,CAAC,OAAO,CAAY;gBAC/C,MAAM,EAAE,KAAK;gBACb,GAAG,EAAE,uDAAuD;gBAC5D,MAAM,EAAE,EAAE,MAAM,EAAE,yBAAyB,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE;gBACpF,OAAO,EAAE,EAAE,yBAAyB,EAAE,kBAAkB,sBAAO,CAAC,OAAO,EAAE,EAAE;aAC5E,CAAC,CAAC;YAEH,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,EAAE,GACvC,CAAA,MAAA,MAAA,MAAA,MAAA,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,0CAAE,GAAG,CAAC,SAAS,0CAAG,CAAC,CAAC,0CAAE,SAAS,0CAAG,QAAQ,CAAC,KAAI,EAAE,CAAC;YACrE,MAAM,EAAE,SAAS,EAAE,eAAe,EAAE,cAAc,EAAE,GAClD,CAAA,MAAA,MAAA,MAAA,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,0CAAE,cAAc,0CAAG,OAAO,CAAC,0CAAG,QAAQ,CAAC,KAAI,EAAE,CAAC;YAEjE,IAAI,CAAC,eAAe,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,IAAI,CAAC,SAAS,IAAI,CAAC,cAAc,EAAE,CAAC;gBAC5E,OAAO;YACT,CAAC;YAED,MAAM,GAAG,GAAG,MAAA,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,0CAAG,OAAO,CAAC,CAAC;YAE9C,IAAI,CAAC,GAAG,EAAE,CAAC;gBACT,OAAO;YACT,CAAC;YAED,MAAM,eAAe,GAAoB;gBACvC,MAAM;gBACN,MAAM;gBACN,eAAe;gBACf,SAAS;gBACT,cAAc;aACf,CAAC;YAEF,OAAO,EAAE,eAAe,EAAE,GAAG,EAAE,CAAC;QAClC,CAAC;KAAA;CACF;AApCD,oEAoCC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpExternalPluginDataSource.test.d.ts","sourceRoot":"","sources":["../../../src/external-plugin/data/HttpExternalPluginDataSource.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const axios_1 = __importDefault(require("axios"));
|
|
16
|
+
const HttpExternalPluginDataSource_1 = require("./HttpExternalPluginDataSource");
|
|
17
|
+
const abi_json_1 = __importDefault(require("../__tests__/abi.json"));
|
|
18
|
+
const package_json_1 = __importDefault(require("../../../package.json"));
|
|
19
|
+
jest.mock("axios");
|
|
20
|
+
const axiosResponseBuilder = (dto) => {
|
|
21
|
+
return { data: dto };
|
|
22
|
+
};
|
|
23
|
+
describe("HttpExternalPuginDataSource", () => {
|
|
24
|
+
let datasource;
|
|
25
|
+
const exampleB2c = {
|
|
26
|
+
blockchainName: "ethereum",
|
|
27
|
+
chainId: 1,
|
|
28
|
+
contracts: [
|
|
29
|
+
{
|
|
30
|
+
address: "0x0",
|
|
31
|
+
contractName: "name",
|
|
32
|
+
selectors: { "0x01": { erc20OfInterest: ["fromToken"], method: "swap", plugin: "plugin" } },
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
name: "test",
|
|
36
|
+
};
|
|
37
|
+
const exampleAbis = { "0x0": abi_json_1.default };
|
|
38
|
+
const exampleB2cSignatures = {
|
|
39
|
+
"0x0": { "0x01": { plugin: "plugin", serialized_data: "0x001", signature: "0x002" } },
|
|
40
|
+
};
|
|
41
|
+
beforeAll(() => {
|
|
42
|
+
datasource = new HttpExternalPluginDataSource_1.HttpExternalPluginDataSource();
|
|
43
|
+
jest.clearAllMocks();
|
|
44
|
+
});
|
|
45
|
+
it("should call axios with the ledger client version header", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
+
// GIVEN
|
|
47
|
+
const version = `context-module/${package_json_1.default.version}`;
|
|
48
|
+
const requestSpy = jest.fn(() => Promise.resolve({ data: [] }));
|
|
49
|
+
jest.spyOn(axios_1.default, "request").mockImplementation(requestSpy);
|
|
50
|
+
// WHEN
|
|
51
|
+
yield datasource.getDappInfos({ chainId: 1, address: "0x0", selector: "0x01" });
|
|
52
|
+
// THEN
|
|
53
|
+
expect(requestSpy).toHaveBeenCalledWith(expect.objectContaining({ headers: { "X-Ledger-Client-Version": version } }));
|
|
54
|
+
}));
|
|
55
|
+
it("should return undefined when no abis is undefined", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
56
|
+
// GIVEN
|
|
57
|
+
const response = axiosResponseBuilder([
|
|
58
|
+
{ b2c: exampleB2c, b2c_signatures: exampleB2cSignatures },
|
|
59
|
+
]);
|
|
60
|
+
jest.spyOn(axios_1.default, "request").mockResolvedValue(response);
|
|
61
|
+
// WHEN
|
|
62
|
+
const result = yield datasource.getDappInfos({ chainId: 1, address: "0x0", selector: "0x01" });
|
|
63
|
+
// THEN
|
|
64
|
+
expect(result).toEqual(undefined);
|
|
65
|
+
}));
|
|
66
|
+
it("should return undefined when no abis data", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
67
|
+
// GIVEN
|
|
68
|
+
const response = axiosResponseBuilder([
|
|
69
|
+
{ abis: {}, b2c: exampleB2c, b2c_signatures: exampleB2cSignatures },
|
|
70
|
+
]);
|
|
71
|
+
jest.spyOn(axios_1.default, "request").mockResolvedValue(response);
|
|
72
|
+
// WHEN
|
|
73
|
+
const result = yield datasource.getDappInfos({ chainId: 1, address: "0x0", selector: "0x01" });
|
|
74
|
+
// THEN
|
|
75
|
+
expect(result).toEqual(undefined);
|
|
76
|
+
}));
|
|
77
|
+
it("should return undefined when no abis data", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
78
|
+
// GIVEN
|
|
79
|
+
const response = axiosResponseBuilder([
|
|
80
|
+
{ abis: {}, b2c: exampleB2c, b2c_signatures: exampleB2cSignatures },
|
|
81
|
+
]);
|
|
82
|
+
jest.spyOn(axios_1.default, "request").mockResolvedValue(response);
|
|
83
|
+
// WHEN
|
|
84
|
+
const result = yield datasource.getDappInfos({ chainId: 1, address: "0x0", selector: "0x01" });
|
|
85
|
+
// THEN
|
|
86
|
+
expect(result).toEqual(undefined);
|
|
87
|
+
}));
|
|
88
|
+
it("should return undefined when no abis data for the contract address", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
89
|
+
// GIVEN
|
|
90
|
+
const abis = { "0x1": abi_json_1.default };
|
|
91
|
+
const response = axiosResponseBuilder([
|
|
92
|
+
{ abis, b2c: exampleB2c, b2c_signatures: exampleB2cSignatures },
|
|
93
|
+
]);
|
|
94
|
+
jest.spyOn(axios_1.default, "request").mockResolvedValue(response);
|
|
95
|
+
// WHEN
|
|
96
|
+
const result = yield datasource.getDappInfos({ chainId: 1, address: "0x0", selector: "0x01" });
|
|
97
|
+
// THEN
|
|
98
|
+
expect(result).toEqual(undefined);
|
|
99
|
+
}));
|
|
100
|
+
it("should return undefined when no b2c signature", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
101
|
+
// GIVEN
|
|
102
|
+
const response = axiosResponseBuilder([{ b2c: exampleB2c, abis: exampleAbis }]);
|
|
103
|
+
jest.spyOn(axios_1.default, "request").mockResolvedValue(response);
|
|
104
|
+
// WHEN
|
|
105
|
+
const result = yield datasource.getDappInfos({ chainId: 1, address: "0x0", selector: "0x01" });
|
|
106
|
+
// THEN
|
|
107
|
+
expect(result).toEqual(undefined);
|
|
108
|
+
}));
|
|
109
|
+
it("should return undefined when no ecc20OfInterest", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
110
|
+
// GIVEN
|
|
111
|
+
const b2c = {
|
|
112
|
+
blockchainName: "ethereum",
|
|
113
|
+
chainId: 1,
|
|
114
|
+
contracts: [
|
|
115
|
+
{
|
|
116
|
+
address: "0x0",
|
|
117
|
+
contractName: "name",
|
|
118
|
+
selectors: {
|
|
119
|
+
"0x01": { method: "swap", plugin: "plugin" },
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
name: "test",
|
|
124
|
+
};
|
|
125
|
+
const response = axiosResponseBuilder([
|
|
126
|
+
{ b2c, abis: exampleAbis, b2c_signatures: exampleB2cSignatures },
|
|
127
|
+
]);
|
|
128
|
+
jest.spyOn(axios_1.default, "request").mockResolvedValue(response);
|
|
129
|
+
// WHEN
|
|
130
|
+
const result = yield datasource.getDappInfos({ chainId: 1, address: "0x0", selector: "0x01" });
|
|
131
|
+
// THEN
|
|
132
|
+
expect(result).toEqual(undefined);
|
|
133
|
+
}));
|
|
134
|
+
it("should return undefined when no method", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
135
|
+
// GIVEN
|
|
136
|
+
const b2c = {
|
|
137
|
+
blockchainName: "ethereum",
|
|
138
|
+
chainId: 1,
|
|
139
|
+
contracts: [
|
|
140
|
+
{
|
|
141
|
+
address: "0x0",
|
|
142
|
+
contractName: "name",
|
|
143
|
+
selectors: {
|
|
144
|
+
"0x01": { erc20OfInterest: ["fromToken"], plugin: "plugin" },
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
],
|
|
148
|
+
name: "test",
|
|
149
|
+
};
|
|
150
|
+
const response = axiosResponseBuilder([
|
|
151
|
+
{ b2c, abis: exampleAbis, b2c_signatures: exampleB2cSignatures },
|
|
152
|
+
]);
|
|
153
|
+
jest.spyOn(axios_1.default, "request").mockResolvedValue(response);
|
|
154
|
+
// WHEN
|
|
155
|
+
const result = yield datasource.getDappInfos({ chainId: 1, address: "0x0", selector: "0x01" });
|
|
156
|
+
// THEN
|
|
157
|
+
expect(result).toEqual(undefined);
|
|
158
|
+
}));
|
|
159
|
+
it("should return undefined when no plugin", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
160
|
+
// GIVEN
|
|
161
|
+
const b2c = {
|
|
162
|
+
blockchainName: "ethereum",
|
|
163
|
+
chainId: 1,
|
|
164
|
+
contracts: [
|
|
165
|
+
{
|
|
166
|
+
address: "0x0",
|
|
167
|
+
contractName: "name",
|
|
168
|
+
selectors: {
|
|
169
|
+
"0x01": { erc20OfInterest: ["fromToken"], method: "swap" },
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
],
|
|
173
|
+
name: "test",
|
|
174
|
+
};
|
|
175
|
+
const response = axiosResponseBuilder([
|
|
176
|
+
{ b2c, abis: exampleAbis, b2c_signatures: exampleB2cSignatures },
|
|
177
|
+
]);
|
|
178
|
+
jest.spyOn(axios_1.default, "request").mockResolvedValue(response);
|
|
179
|
+
// WHEN
|
|
180
|
+
const result = yield datasource.getDappInfos({ chainId: 1, address: "0x0", selector: "0x01" });
|
|
181
|
+
// THEN
|
|
182
|
+
expect(result).toEqual(undefined);
|
|
183
|
+
}));
|
|
184
|
+
it("should return undefined when no method", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
185
|
+
// GIVEN
|
|
186
|
+
const b2c = {
|
|
187
|
+
blockchainName: "ethereum",
|
|
188
|
+
chainId: 1,
|
|
189
|
+
contracts: [
|
|
190
|
+
{
|
|
191
|
+
address: "0x0",
|
|
192
|
+
contractName: "name",
|
|
193
|
+
selectors: {
|
|
194
|
+
"0x01": { erc20OfInterest: ["fromToken"], plugin: "plugin" },
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
],
|
|
198
|
+
name: "test",
|
|
199
|
+
};
|
|
200
|
+
const response = axiosResponseBuilder([
|
|
201
|
+
{ b2c, abis: exampleAbis, b2c_signatures: exampleB2cSignatures },
|
|
202
|
+
]);
|
|
203
|
+
jest.spyOn(axios_1.default, "request").mockResolvedValue(response);
|
|
204
|
+
// WHEN
|
|
205
|
+
const result = yield datasource.getDappInfos({ chainId: 1, address: "0x0", selector: "0x01" });
|
|
206
|
+
// THEN
|
|
207
|
+
expect(result).toEqual(undefined);
|
|
208
|
+
}));
|
|
209
|
+
it("should return undefined when no signature", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
210
|
+
// GIVEN
|
|
211
|
+
const B2CSignature = {
|
|
212
|
+
"0x0": { "0x01": { plugin: "plugin", serialized_data: "0x001" } },
|
|
213
|
+
};
|
|
214
|
+
// FIXME
|
|
215
|
+
const response = axiosResponseBuilder([
|
|
216
|
+
{ b2c: exampleB2c, abis: exampleAbis, b2c_signatures: B2CSignature },
|
|
217
|
+
]);
|
|
218
|
+
jest.spyOn(axios_1.default, "request").mockResolvedValue(response);
|
|
219
|
+
// WHEN
|
|
220
|
+
const result = yield datasource.getDappInfos({ chainId: 1, address: "0x0", selector: "0x01" });
|
|
221
|
+
// THEN
|
|
222
|
+
expect(result).toEqual(undefined);
|
|
223
|
+
}));
|
|
224
|
+
it("should return undefined when no serialized data", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
225
|
+
// GIVEN
|
|
226
|
+
const B2CSignature = {
|
|
227
|
+
"0x0": { "0x01": { plugin: "plugin", signature: "0x002" } },
|
|
228
|
+
};
|
|
229
|
+
// FIXME
|
|
230
|
+
const response = axiosResponseBuilder([
|
|
231
|
+
{ b2c: exampleB2c, abis: exampleAbis, b2c_signatures: B2CSignature },
|
|
232
|
+
]);
|
|
233
|
+
jest.spyOn(axios_1.default, "request").mockResolvedValue(response);
|
|
234
|
+
// WHEN
|
|
235
|
+
const result = yield datasource.getDappInfos({ chainId: 1, address: "0x0", selector: "0x01" });
|
|
236
|
+
// THEN
|
|
237
|
+
expect(result).toEqual(undefined);
|
|
238
|
+
}));
|
|
239
|
+
it("should return a correct response", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
240
|
+
// GIVEN
|
|
241
|
+
const response = axiosResponseBuilder([
|
|
242
|
+
{ b2c: exampleB2c, abis: exampleAbis, b2c_signatures: exampleB2cSignatures },
|
|
243
|
+
]);
|
|
244
|
+
jest.spyOn(axios_1.default, "request").mockResolvedValue(response);
|
|
245
|
+
// WHEN
|
|
246
|
+
const result = yield datasource.getDappInfos({ chainId: 1, address: "0x0", selector: "0x01" });
|
|
247
|
+
// THEN
|
|
248
|
+
expect(result).toEqual({
|
|
249
|
+
abi: abi_json_1.default,
|
|
250
|
+
selectorDetails: {
|
|
251
|
+
erc20OfInterest: ["fromToken"],
|
|
252
|
+
method: "swap",
|
|
253
|
+
plugin: "plugin",
|
|
254
|
+
serializedData: "0x001",
|
|
255
|
+
signature: "0x002",
|
|
256
|
+
},
|
|
257
|
+
});
|
|
258
|
+
}));
|
|
259
|
+
});
|
|
260
|
+
//# sourceMappingURL=HttpExternalPluginDataSource.test.js.map
|