Allow merging modules
This commit is contained in:
parent
b5e0023b04
commit
40c7ec5146
@ -160,6 +160,41 @@ describe("LcdClient", () => {
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("can merge two extension into the same module", async () => {
|
||||
pendingWithoutWasmd();
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
function setupSupplyExtensionBasic(base: LcdClient) {
|
||||
return {
|
||||
supply: {
|
||||
totalAll: async () => {
|
||||
const path = `/supply/total`;
|
||||
return base.get(path);
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
function setupSupplyExtensionPremium(base: LcdClient) {
|
||||
return {
|
||||
supply: {
|
||||
total: async (denom: string) => {
|
||||
return base.get(`/supply/total/${denom}`);
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const client = LcdClient.withExtensions(
|
||||
{ apiUrl: wasmd.endpoint },
|
||||
setupSupplyExtensionBasic,
|
||||
setupSupplyExtensionPremium,
|
||||
);
|
||||
expect(client.supply.totalAll).toEqual(jasmine.any(Function));
|
||||
expect(client.supply.total).toEqual(jasmine.any(Function));
|
||||
});
|
||||
});
|
||||
|
||||
// The /txs endpoints
|
||||
|
||||
@ -204,8 +204,9 @@ export class LcdClient {
|
||||
if (setupExtensionH) extensions.push(setupExtensionH(client));
|
||||
for (const extension of extensions) {
|
||||
assert(isNonNullObject(extension), `Extension must be a non-null object`);
|
||||
for (const [key, value] of Object.entries(extension)) {
|
||||
(client as any)[key] = value;
|
||||
for (const [moduleKey, moduleValue] of Object.entries(extension)) {
|
||||
const current = (client as any)[moduleKey] || {};
|
||||
(client as any)[moduleKey] = Object.assign(current, moduleValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user