@hashgraph/hedera-wallet-connect 2.0.1-canary.5214d14.0 → 2.0.1-canary.5567151.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,5 +5,3 @@ export * from './methods';
5
5
  export * from './payloads';
6
6
  export * from './utils';
7
7
  export * from './extensionController';
8
- export * from './mirrorNode';
9
- export * from './accountInfo';
@@ -24,5 +24,3 @@ export * from './methods';
24
24
  export * from './payloads';
25
25
  export * from './utils';
26
26
  export * from './extensionController';
27
- export * from './mirrorNode';
28
- export * from './accountInfo';
@@ -5,8 +5,7 @@ import { ProviderUtil } from '@reown/appkit/store';
5
5
  import { LedgerId } from '@hashgraph/sdk';
6
6
  import { BrowserProvider, Contract, formatUnits, JsonRpcSigner, parseUnits } from 'ethers';
7
7
  import { HederaConnector } from './connectors';
8
- import { hederaNamespace } from './utils';
9
- import { getAccountInfo } from '..';
8
+ import { hederaNamespace, getAccountBalance } from './utils';
10
9
  export class HederaAdapter extends AdapterBlueprint {
11
10
  constructor(params) {
12
11
  var _a, _b;
@@ -73,10 +72,10 @@ export class HederaAdapter extends AdapterBlueprint {
73
72
  symbol: '',
74
73
  });
75
74
  }
76
- const accountInfo = await getAccountInfo(caipNetwork.testnet ? LedgerId.TESTNET : LedgerId.MAINNET, address);
75
+ const accountBalance = await getAccountBalance(caipNetwork.testnet ? LedgerId.TESTNET : LedgerId.MAINNET, address);
77
76
  return Promise.resolve({
78
- balance: (accountInfo === null || accountInfo === void 0 ? void 0 : accountInfo.balance)
79
- ? formatUnits(accountInfo.balance.balance, 8).toString()
77
+ balance: accountBalance
78
+ ? formatUnits(accountBalance.hbars.toTinybars().toString(), 8).toString()
80
79
  : '0',
81
80
  decimals: caipNetwork.nativeCurrency.decimals,
82
81
  symbol: caipNetwork.nativeCurrency.symbol,
@@ -0,0 +1,2 @@
1
+ import { AccountBalance, LedgerId } from '@hashgraph/sdk';
2
+ export declare function getAccountBalance(ledgerId: LedgerId, address: string): Promise<AccountBalance | null>;
@@ -0,0 +1,20 @@
1
+ import { AccountBalanceQuery, AccountId, Client, LedgerId, } from '@hashgraph/sdk';
2
+ export async function getAccountBalance(ledgerId, address) {
3
+ const client = ledgerId === LedgerId.TESTNET ? Client.forTestnet() : Client.forMainnet();
4
+ let accountId;
5
+ try {
6
+ accountId = AccountId.fromString(address);
7
+ }
8
+ catch (e) {
9
+ accountId = AccountId.fromEvmAddress(0, 0, address);
10
+ }
11
+ if (accountId.num.isZero() && accountId.evmAddress != null) {
12
+ await accountId.populateAccountNum(client);
13
+ }
14
+ try {
15
+ return await new AccountBalanceQuery().setAccountId(accountId).execute(client);
16
+ }
17
+ catch (e) {
18
+ return null;
19
+ }
20
+ }
@@ -2,3 +2,4 @@ export * from './chains';
2
2
  export * from './constants';
3
3
  export * from './types';
4
4
  export * from './helpers';
5
+ export * from './account';
@@ -2,3 +2,4 @@ export * from './chains';
2
2
  export * from './constants';
3
3
  export * from './types';
4
4
  export * from './helpers';
5
+ export * from './account';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hashgraph/hedera-wallet-connect",
3
- "version": "2.0.1-canary.5214d14.0",
3
+ "version": "2.0.1-canary.5567151.0",
4
4
  "description": "A library to facilitate integrating Hedera with WalletConnect",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,30 +0,0 @@
1
- export interface AccountInfo {
2
- account: string;
3
- alias: string;
4
- auto_renew_period: number;
5
- balance: Balance;
6
- created_timestamp: string;
7
- decline_reward: boolean;
8
- deleted: boolean;
9
- ethereum_nonce: number;
10
- evm_address: string;
11
- expiry_timestamp: string;
12
- key: Key | null;
13
- max_automatic_token_associations: number;
14
- memo: string;
15
- pending_reward: number;
16
- receiver_sig_required: boolean;
17
- }
18
- export interface Balance {
19
- balance: number;
20
- timestamp: string;
21
- tokens: Token[];
22
- }
23
- export interface Token {
24
- token_id: string;
25
- balance: number;
26
- }
27
- export interface Key {
28
- _type: string;
29
- key: string;
30
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- import { LedgerId } from '@hashgraph/sdk';
2
- import { AccountInfo } from '.';
3
- export declare function getAccountInfo(ledgerId: LedgerId, address: string): Promise<AccountInfo | null>;
@@ -1,17 +0,0 @@
1
- function getMirrorNodeUrl(ledgerId) {
2
- return `https://${ledgerId.toString()}.mirrornode.hedera.com`;
3
- }
4
- export async function getAccountInfo(ledgerId, address) {
5
- const mirrorNodeApiUrl = getMirrorNodeUrl(ledgerId);
6
- const url = `${mirrorNodeApiUrl}/api/v1/accounts/${address}`;
7
- const result = await fetch(url, {
8
- headers: {
9
- accept: 'application/json',
10
- },
11
- });
12
- if (result.status !== 200) {
13
- return null;
14
- }
15
- const response = await result.json();
16
- return response;
17
- }