@f5i23q999d/cow-sdk
Version:
<p align="center"> <img width="400" src="https://github.com/cowprotocol/cow-sdk/raw/main/docs/images/CoW.png" /> </p>
33 lines • 1.11 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConditionalOrderFactory = void 0;
/**
* Factory for conditional orders.
*
* It uses a registry to instantiate the correct conditional order based on the handler.
*
* Knowing the handler, the factory will instantiate the correct conditional order using the staticInput data.
*/
class ConditionalOrderFactory {
knownOrderTypes;
constructor(registry) {
// Normalize the keys to lowercase
this.knownOrderTypes = Object.entries(registry).reduce((acc, [key, value]) => {
acc[key.toLowerCase()] = value;
return acc;
}, {});
}
/**
* Get the conditional order factory from the conditional order parameters
*/
fromParams(params) {
const { handler } = params;
const factory = this.knownOrderTypes[handler.toLocaleLowerCase()];
if (!factory) {
return undefined;
}
return factory(params);
}
}
exports.ConditionalOrderFactory = ConditionalOrderFactory;
//# sourceMappingURL=ConditionalOrderFactory.js.map