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: new CheckConnection method #2

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
19 changes: 18 additions & 1 deletion packages/sdk/src/methods/general.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { EAdenaResponseStatus } from '../types/common';
import { getAdena } from '../utils';
import { AddEstablishResponse, AddEstablishResponseType, GetAccountResponseData } from '../types/methods/general';
import {
AddEstablishResponse,
AddEstablishResponseType,
CheckConnectionResponse,
GetAccountResponseData,
} from '../types/methods/general';

/**
* Establish a connection to your site from Adena
Expand Down Expand Up @@ -28,6 +33,18 @@ export const establishConnection = async (name: string): Promise<AddEstablishRes
throw new Error(`Unable to establish connection: ${response.message}`);
};

/**
* Check if the status of the connection between your site and Adena
* @async
* @param {string} name - The name of the website
* @returns Original Adena response with the type of connection
*/
export const checkConnection = async (name: string): Promise<CheckConnectionResponse> => {
const adena = getAdena();

return await adena.CheckConnection(name);
};

/**
* Fetch information about the current connected account
* @async
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/methods/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { addNetwork, switchNetwork } from './network';
export { signAndSendTransaction, signTransaction } from './transactions';
export { establishConnection, getAccountInfo } from './general';
export { establishConnection, checkConnection, getAccountInfo } from './general';
export { onAccountChange, onNetworkChange } from './events';
7 changes: 4 additions & 3 deletions packages/sdk/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { AdenaDoContract, AdenaSignTx } from './methods/transactions';
import { AdenaAddNetwork, AdenaSwitchNetwork } from './methods/network';
import { AdenaAddEstablish, AdenaGetAccount } from './methods/general';
import { AdenaOnEvent } from './methods/events';
import { AdenaAddEstablish, AdenaCheckConnection, AdenaGetAccount } from './methods/general';
import { AdenaAddNetwork, AdenaSwitchNetwork } from './methods/network';
import { AdenaDoContract, AdenaSignTx } from './methods/transactions';

export type AdenaWallet = {
// General
AddEstablish: AdenaAddEstablish;
CheckConnection: AdenaCheckConnection;
GetAccount: AdenaGetAccount;

// Network
Expand Down
10 changes: 10 additions & 0 deletions packages/sdk/src/types/methods/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ export type AddEstablishResponse = IAdenaResponse<AddEstablishResponseType, Reco

export type AdenaAddEstablish = (name: string) => Promise<AddEstablishResponse>;

export enum CheckConnectionResponseType {
WALLET_LOCKED = 'WALLET_LOCKED',
NOT_CONNECTED = 'NOT_CONNECTED',
ALREADY_CONNECTED = 'ALREADY_CONNECTED',
}

export type CheckConnectionResponse = IAdenaResponse<CheckConnectionResponseType, Record<string, never>>;

export type AdenaCheckConnection = (name: string) => Promise<CheckConnectionResponse>;

enum GetAccountResponseType {
GET_ACCOUNT = 'GET_ACCOUNT',
NO_ACCOUNT = 'NO_ACCOUNT',
Expand Down