Skip to content

Commit

Permalink
feat: new CheckConnection method
Browse files Browse the repository at this point in the history
  • Loading branch information
RezaRahemtola committed Aug 19, 2024
1 parent 155f71d commit 76d1800
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
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

0 comments on commit 76d1800

Please sign in to comment.