Skip to content

Commit 87e16f9

Browse files
committed
feat: new CheckEstablish method
1 parent 155f71d commit 87e16f9

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

packages/sdk/src/methods/general.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { EAdenaResponseStatus } from '../types/common';
22
import { getAdena } from '../utils';
3-
import { AddEstablishResponse, AddEstablishResponseType, GetAccountResponseData } from '../types/methods/general';
3+
import {
4+
AddEstablishResponse,
5+
AddEstablishResponseType,
6+
CheckConnectionResponse,
7+
GetAccountResponseData,
8+
} from '../types/methods/general';
49

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

36+
/**
37+
* Check if the status of the connection between your site and Adena
38+
* @async
39+
* @param {string} name - The name of the website
40+
* @returns Original Adena response with the type of connection
41+
*/
42+
export const checkConnection = async (name: string): Promise<CheckConnectionResponse> => {
43+
const adena = getAdena();
44+
45+
return await adena.CheckConnection(name);
46+
};
47+
3148
/**
3249
* Fetch information about the current connected account
3350
* @async

packages/sdk/src/methods/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export { addNetwork, switchNetwork } from './network';
22
export { signAndSendTransaction, signTransaction } from './transactions';
3-
export { establishConnection, getAccountInfo } from './general';
3+
export { establishConnection, checkConnection, getAccountInfo } from './general';
44
export { onAccountChange, onNetworkChange } from './events';

packages/sdk/src/types/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { AdenaDoContract, AdenaSignTx } from './methods/transactions';
2-
import { AdenaAddNetwork, AdenaSwitchNetwork } from './methods/network';
3-
import { AdenaAddEstablish, AdenaGetAccount } from './methods/general';
41
import { AdenaOnEvent } from './methods/events';
2+
import { AdenaAddEstablish, AdenaCheckConnection, AdenaGetAccount } from './methods/general';
3+
import { AdenaAddNetwork, AdenaSwitchNetwork } from './methods/network';
4+
import { AdenaDoContract, AdenaSignTx } from './methods/transactions';
55

66
export type AdenaWallet = {
77
// General
88
AddEstablish: AdenaAddEstablish;
9+
CheckConnection: AdenaCheckConnection;
910
GetAccount: AdenaGetAccount;
1011

1112
// Network

packages/sdk/src/types/methods/general.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ export type AddEstablishResponse = IAdenaResponse<AddEstablishResponseType, Reco
99

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

12+
export enum CheckConnectionResponseType {
13+
WALLET_LOCKED = 'WALLET_LOCKED',
14+
NOT_CONNECTED = 'NOT_CONNECTED',
15+
ALREADY_CONNECTED = 'ALREADY_CONNECTED',
16+
}
17+
18+
export type CheckConnectionResponse = IAdenaResponse<CheckConnectionResponseType, Record<string, never>>;
19+
20+
export type AdenaCheckConnection = (name: string) => Promise<CheckConnectionResponse>;
21+
1222
enum GetAccountResponseType {
1323
GET_ACCOUNT = 'GET_ACCOUNT',
1424
NO_ACCOUNT = 'NO_ACCOUNT',

0 commit comments

Comments
 (0)