diff --git a/packages/sdk/src/core/providers/tm2-wallet.ts b/packages/sdk/src/core/providers/tm2-wallet.ts index 024106d..55c7a60 100644 --- a/packages/sdk/src/core/providers/tm2-wallet.ts +++ b/packages/sdk/src/core/providers/tm2-wallet.ts @@ -1,7 +1,10 @@ +import { Wallet as TM2Wallet } from '@gnolang/tm2-js-client'; import { WalletProvider } from './wallet'; export interface TM2WalletProvider extends WalletProvider { connect(): Promise; disconnect(): Promise; + + getWallet(): TM2Wallet | null; } diff --git a/packages/sdk/src/core/sdk/adena-sdk.ts b/packages/sdk/src/core/sdk/adena-sdk.ts index 323a69f..5ff515e 100644 --- a/packages/sdk/src/core/sdk/adena-sdk.ts +++ b/packages/sdk/src/core/sdk/adena-sdk.ts @@ -1,3 +1,5 @@ +import { Wallet } from '@gnolang/tm2-js-client'; +import { AdenaWalletProvider, GnoSocialWalletProvider, GnoWalletProvider } from '../../providers'; import { ConnectionManager, ConnectionState } from '../connection'; import { addEstablish, @@ -16,7 +18,7 @@ import { switchNetwork, } from '../methods'; import { WalletProvider } from '../providers'; -import { SDKConfigure } from '../types'; +import { SDKConfigure, SocialConfigure } from '../types'; import { AddEstablishOptions, AddEstablishResponse, @@ -122,4 +124,16 @@ export class AdenaSDK { onChangeNetwork(options: OnChangeNetworkOptions): OnChangeNetworkResponse { return onChangeNetwork(this.walletProvider, options); } + + public static createAdenaWallet(config?: SDKConfigure): AdenaSDK { + return new AdenaSDK(new AdenaWalletProvider(), config); + } + + public static createGnoWallet(wallet: Wallet, config?: SDKConfigure): AdenaSDK { + return new AdenaSDK(new GnoWalletProvider(wallet), config); + } + + public static createGnoSocialWallet(config: SocialConfigure & SDKConfigure): AdenaSDK { + return new AdenaSDK(GnoSocialWalletProvider.create(config), config); + } } diff --git a/packages/sdk/src/core/types/config.types.ts b/packages/sdk/src/core/types/config.types.ts index 291be38..4147bcb 100644 --- a/packages/sdk/src/core/types/config.types.ts +++ b/packages/sdk/src/core/types/config.types.ts @@ -5,3 +5,15 @@ export interface SDKConfigure extends SDKConnectionConfigure { export interface SDKConnectionConfigure { isSession?: boolean; } + +export interface SocialConfigure { + chainId: string; + rpcTarget: string; + network: 'mainnet' | 'testnet'; + clientId: string; + auth: { + googleName: string; + googleVerifier: string; + googleClientId: string; + }; +} diff --git a/packages/sdk/src/providers/gno-wallet/gno-social-wallet.ts b/packages/sdk/src/providers/gno-wallet/gno-social-wallet.ts index b9fd3d5..cac20fc 100644 --- a/packages/sdk/src/providers/gno-wallet/gno-social-wallet.ts +++ b/packages/sdk/src/providers/gno-wallet/gno-social-wallet.ts @@ -4,6 +4,7 @@ import { CommonPrivateKeyProvider } from '@web3auth/base-provider'; import { Web3AuthNoModal } from '@web3auth/no-modal'; import { OpenloginAdapter } from '@web3auth/openlogin-adapter'; +import { SocialConfigure } from '../../core'; import { hexToUint8Array } from '../../core/utils/encode.utils'; import { GnoWalletProvider } from './gno-wallet'; @@ -72,16 +73,7 @@ export class GnoSocialWalletProvider extends GnoWalletProvider { return `${privateKey}`; } - public static create(config: { - chainId: string; - rpcTarget: string; - network: 'mainnet' | 'testnet'; - clientId: string; - auth: { - googleVerifier: string; - googleClientId: string; - }; - }) { + public static create(config: SocialConfigure) { const chainConfig: CustomChainConfig = { chainNamespace: 'other', chainId: config.chainId, @@ -108,8 +100,8 @@ export class GnoSocialWalletProvider extends GnoWalletProvider { uxMode: 'popup', loginConfig: { google: { - name: 'Adena', typeOfLogin: 'google', + name: config.auth.googleName, verifier: config.auth.googleVerifier, clientId: config.auth.googleClientId, }, diff --git a/packages/sdk/src/providers/gno-wallet/gno-wallet.ts b/packages/sdk/src/providers/gno-wallet/gno-wallet.ts index 8f8a422..2ed797b 100644 --- a/packages/sdk/src/providers/gno-wallet/gno-wallet.ts +++ b/packages/sdk/src/providers/gno-wallet/gno-wallet.ts @@ -32,6 +32,10 @@ export class GnoWalletProvider implements TM2WalletProvider { this.wallet = wallet || null; } + public getWallet(): TM2Wallet | null { + return this.wallet; + } + async connect(): Promise { return this.connectProvider(); }