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

feat: add methods in sdk #10

Merged
merged 2 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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