@cryptorubic/web3 1.1.0-alpha-stellar.33 → 1.1.0-alpha-stellar.34
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/package.json
CHANGED
|
@@ -16,6 +16,7 @@ export declare class StellarAdapter extends AbstractAdapter<StellarClient, Stell
|
|
|
16
16
|
private readonly rpc;
|
|
17
17
|
readonly signer: StellarAdapterSigner;
|
|
18
18
|
private readonly horizonClient;
|
|
19
|
+
private readonly CLASSIC_TOKEN_DECIMALS;
|
|
19
20
|
constructor(rpc: StellarRpcProvider[], httpClient: HttpClient, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
|
|
20
21
|
initWeb3Client(): void;
|
|
21
22
|
getBlockNumber(): Promise<number | {
|
|
@@ -14,6 +14,7 @@ class StellarAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
14
14
|
constructor(rpc, httpClient, logger, clientParams) {
|
|
15
15
|
super(core_1.BLOCKCHAIN_NAME.STELLAR, logger);
|
|
16
16
|
this.rpc = rpc;
|
|
17
|
+
this.CLASSIC_TOKEN_DECIMALS = 7;
|
|
17
18
|
this.signer = new stellar_adapter_signer_1.StellarAdapterSigner(this.publicRef, httpClient, logger, clientParams);
|
|
18
19
|
this.horizonClient = new stellar_sdk_1.Horizon.Server(rpc[0].horizon, {
|
|
19
20
|
allowHttp: true,
|
|
@@ -32,13 +33,22 @@ class StellarAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
32
33
|
}
|
|
33
34
|
async getTokensBalances(userAddress, tokensAddresses) {
|
|
34
35
|
try {
|
|
35
|
-
const
|
|
36
|
-
|
|
36
|
+
const balances = (await this.horizonClient.loadAccount(userAddress)).balances;
|
|
37
|
+
return tokensAddresses.map((token) => {
|
|
38
|
+
const possibleBalance = balances.find((balance) => {
|
|
39
|
+
if (balance.asset_type === 'native') {
|
|
40
|
+
return web3_pure_1.Web3Pure.isNativeAddress(core_1.BLOCKCHAIN_NAME.STELLAR, token);
|
|
41
|
+
}
|
|
42
|
+
const tokenBalance = balance;
|
|
43
|
+
return (0, core_1.compareAddresses)(token, `${tokenBalance.asset_code}-${tokenBalance.asset_issuer}`);
|
|
44
|
+
});
|
|
45
|
+
return new bignumber_js_1.default(core_1.Token.toWei(possibleBalance?.balance || '0', this.CLASSIC_TOKEN_DECIMALS));
|
|
46
|
+
});
|
|
37
47
|
}
|
|
38
48
|
catch (err) {
|
|
39
49
|
console.error(err);
|
|
50
|
+
return tokensAddresses.map(() => new bignumber_js_1.default(0));
|
|
40
51
|
}
|
|
41
|
-
return Promise.all(tokensAddresses.map((address) => this.getBalance(userAddress, address)));
|
|
42
52
|
}
|
|
43
53
|
async getBalance(userAddress, tokenAddress) {
|
|
44
54
|
try {
|