import { PaymentsFactory } from '@bitaccess/coinlib-common' ; import { assertType } from '@faast/ts-common' ; import { EthereumPaymentsUtilsConfig , EthereumPaymentsConfig , HdEthereumPaymentsConfig , KeyPairEthereumPaymentsConfig , HdErc20PaymentsConfig , KeyPairErc20PaymentsConfig , } from './types' ; import { PACKAGE_NAME } from './constants' ; import { EthereumConnectionManager } from './EthereumConnectionManager' ; import { BaseEthereumPayments } from './BaseEthereumPayments' ; import { EthereumPaymentsUtils } from './EthereumPaymentsUtils' ; import { HdEthereumPayments } from './HdEthereumPayments' ; import { KeyPairEthereumPayments } from './KeyPairEthereumPayments' ; import { HdErc20Payments } from './erc20/HdErc20Payments' ; import { KeyPairErc20Payments } from './erc20/KeyPairErc20Payments' ; export class EthereumPaymentsFactory extends PaymentsFactory < EthereumPaymentsUtilsConfig , EthereumPaymentsUtils , BaseEthereumPayments < EthereumPaymentsUtilsConfig > > { readonly packageName = PACKAGE_NAME ; newPayments ( config ) ; newPayments ( config ) ; newPayments ( config ) ; newPayments ( config ) ; newPayments ( config ) { if ( HdErc20PaymentsConfig . is ( config ) ) { return new HdErc20Payments ( config ) ; } if ( KeyPairErc20PaymentsConfig . is ( config ) ) { throw new Error ( `Cannot instantiate ${ this . packageName } for unsupported KeyPairErc20PaymentsConfig` ) ; } if ( HdEthereumPaymentsConfig . is ( config ) ) { return new HdEthereumPayments ( config ) ; } if ( KeyPairEthereumPaymentsConfig . is ( config ) ) { return new KeyPairEthereumPayments ( config ) ; } throw new Error ( `Cannot instantiate ${ this . packageName } for unsupported config` ) ; } newUtils ( config ) { return new EthereumPaymentsUtils ( assertType ( EthereumPaymentsUtilsConfig , config , 'config' ) ) ; } connectionManager = new EthereumConnectionManager ( ) ; } export default EthereumPaymentsFactory ;