Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ALL-2835 - Extension Ecosystem enabler #933

Merged
merged 11 commits into from
Sep 22, 2023

Conversation

Smrecz
Copy link
Member

@Smrecz Smrecz commented Sep 22, 2023

Part of the Extension Ecosystem that doesn't introduce any breaking changes

Usage will look as follows:

const tatumSdk = await TatumSDK.init<Ethereum>({
        network: Network.ETHEREUM_SEPOLIA,
        configureExtensions: [
            HelloWorldExtension,
            {type: ConfigurableExtension, config: {configurationValue: 'Some configuration string 3'}},
        ]
    })

With this approach we don't enforce any dependencies on the extensions, we are encapsulating typedi functionalities in our TatumSdkContainer.

Extensions have to be explicitly registered via configuration and users can pass their own config depending on the extension.

Async init() is being called for each extension.

This is the basic extension code - just extend TatumSdkExtension.
All other registered sub-services or extensions can be grabbed from TatumSdkContainer.

import { FeeEvm, TatumConfig, CONFIG, TatumSdkExtension, TatumSdkContainer } from "@tatumio/tatum";

export class HelloWorldExtension extends TatumSdkExtension {
  private readonly fee: FeeEvm
  private readonly sdkConfig: TatumConfig

  constructor(tatumSdkContainer: TatumSdkContainer) {
    super(tatumSdkContainer)
    this.fee = this.tatumSdkContainer.get(FeeEvm)
    this.sdkConfig = this.tatumSdkContainer.getConfig()
  }

  async sayHello(){
    const fee = await this.fee.getCurrentFee()
    console.log(`Hello World`)
    console.log(`Base Fee for ${this.sdkConfig.network} is ${fee.data.gasPrice.baseFee})`)
  }

  init(): Promise<void> {
    console.log(`HelloWorldExtension initialised`)
    return Promise.resolve(undefined);
  }

  destroy(): void {
    console.log(`HelloWorldExtension disposed`)
  }
}

@TatumBot
Copy link
Collaborator

package.json Outdated Show resolved Hide resolved
@Hathoriel
Copy link
Member

Good job @Smrecz.

CHANGELOG.md Outdated Show resolved Hide resolved
# Conflicts:
#	CHANGELOG.md
#	package.json
CHANGELOG.md Outdated Show resolved Hide resolved
@Hathoriel
Copy link
Member

Hathoriel commented Sep 22, 2023

What do you think about sending the config options when call the extension() method and not when creating tatum core class? For instance like this:
await tatumSdk.extension(HelloWorldExtension, extensionConfig).sayHello()

@Smrecz
Copy link
Member Author

Smrecz commented Sep 22, 2023

What do you think about sending the config options when call the extension() method and not when creating tatum core class? For instance like this: await tatumSdk.extension(HelloWorldExtension, extensionConfig).sayHello()

@Hathoriel we've been discussing it with Alex and we would like to preserve this fluent interface for users to use like it is for other modules, eg. each time they want to get the fee they can just await tatumSdk.fee.getCurrentFee() they don't have to const tatumSdkFee = tatumSdk.fee before which would be the case for extensions if configured inside the method.

@Smrecz Smrecz merged commit d544539 into master Sep 22, 2023
7 checks passed
@Smrecz Smrecz deleted the feature/ALL-2835_extension_ecosystem branch September 22, 2023 15:01
@Hathoriel
Copy link
Member

@Smrecz It is possible to add some simple test to check if extension enabler functionality is working?

@Hathoriel
Copy link
Member

What do you think about sending the config options when call the extension() method and not when creating tatum core class? For instance like this: await tatumSdk.extension(HelloWorldExtension, extensionConfig).sayHello()

@Hathoriel we've been discussing it with Alex and we would like to preserve this fluent interface for users to use like it is for other modules, eg. each time they want to get the fee they can just await tatumSdk.fee.getCurrentFee() they don't have to const tatumSdkFee = tatumSdk.fee before which would be the case for extensions if configured inside the method.

And why it is not possible or problematic do just following?

const metamask = tatumSdk.walletProvider.use(MetaMask, myConfig, etc)
const result = metamask.connect()

@Smrecz
Copy link
Member Author

Smrecz commented Sep 22, 2023

What do you think about sending the config options when call the extension() method and not when creating tatum core class? For instance like this: await tatumSdk.extension(HelloWorldExtension, extensionConfig).sayHello()

@Hathoriel we've been discussing it with Alex and we would like to preserve this fluent interface for users to use like it is for other modules, eg. each time they want to get the fee they can just await tatumSdk.fee.getCurrentFee() they don't have to const tatumSdkFee = tatumSdk.fee before which would be the case for extensions if configured inside the method.

And why it is not possible or problematic do just following?

const metamask = tatumSdk.walletProvider.use(MetaMask, myConfig, etc)
const result = metamask.connect()

It's not problematic at all, users have this option in both cases now.

I don't see any benefit of moving config from SDK init to method call, won't make dealing with config types any more strict and will still require calling somewhere async init of the extension. We've been considering this approach but we've settled on nest.js like experience :)

@Hathoriel
Copy link
Member

@Smrecz Ok makes sense. Thank you for the clarification!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants