@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.
- package/dist/lib/shared/index.d.ts +0 -2
- package/dist/lib/shared/index.js +0 -2
- package/dist/reown/adapter.js +4 -5
- package/dist/reown/utils/account.d.ts +2 -0
- package/dist/reown/utils/account.js +20 -0
- package/dist/reown/utils/index.d.ts +1 -0
- package/dist/reown/utils/index.js +1 -0
- package/package.json +1 -1
- package/dist/lib/shared/accountInfo.d.ts +0 -30
- package/dist/lib/shared/accountInfo.js +0 -1
- package/dist/lib/shared/mirrorNode.d.ts +0 -3
- package/dist/lib/shared/mirrorNode.js +0 -17
package/dist/lib/shared/index.js
CHANGED
package/dist/reown/adapter.js
CHANGED
@@ -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
|
75
|
+
const accountBalance = await getAccountBalance(caipNetwork.testnet ? LedgerId.TESTNET : LedgerId.MAINNET, address);
|
77
76
|
return Promise.resolve({
|
78
|
-
balance:
|
79
|
-
? formatUnits(
|
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,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
|
+
}
|
package/package.json
CHANGED
@@ -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,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
|
-
}
|