Skip to content

Commit

Permalink
feat: add methods in sdk (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
jinoosss authored Sep 10, 2024
1 parent 6a6eda6 commit 2f1bde0
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 12 deletions.
3 changes: 3 additions & 0 deletions packages/sdk/src/core/providers/tm2-wallet.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Wallet as TM2Wallet } from '@gnolang/tm2-js-client';
import { WalletProvider } from './wallet';

export interface TM2WalletProvider extends WalletProvider {
connect(): Promise<boolean>;

disconnect(): Promise<boolean>;

getWallet(): TM2Wallet | null;
}
16 changes: 15 additions & 1 deletion packages/sdk/src/core/sdk/adena-sdk.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Wallet } from '@gnolang/tm2-js-client';
import { AdenaWalletProvider, GnoSocialWalletProvider, GnoWalletProvider } from '../../providers';
import { ConnectionManager, ConnectionState } from '../connection';
import {
addEstablish,
Expand All @@ -16,7 +18,7 @@ import {
switchNetwork,
} from '../methods';
import { WalletProvider } from '../providers';
import { SDKConfigure } from '../types';
import { SDKConfigure, SocialConfigure } from '../types';
import {
AddEstablishOptions,
AddEstablishResponse,
Expand Down Expand Up @@ -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);
}
}
12 changes: 12 additions & 0 deletions packages/sdk/src/core/types/config.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}
14 changes: 3 additions & 11 deletions packages/sdk/src/providers/gno-wallet/gno-social-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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,
Expand All @@ -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,
},
Expand Down
4 changes: 4 additions & 0 deletions packages/sdk/src/providers/gno-wallet/gno-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export class GnoWalletProvider implements TM2WalletProvider {
this.wallet = wallet || null;
}

public getWallet(): TM2Wallet | null {
return this.wallet;
}

async connect(): Promise<boolean> {
return this.connectProvider();
}
Expand Down

0 comments on commit 2f1bde0

Please sign in to comment.