@cryptorubic/web3 1.1.0-alpha-stellar.7 → 1.1.0-alpha-stellar.9

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cryptorubic/web3",
3
- "version": "1.1.0-alpha-stellar.7",
3
+ "version": "1.1.0-alpha-stellar.9",
4
4
  "dependencies": {
5
5
  "@ethersproject/bignumber": "^5.8.0",
6
6
  "@mysten/sui": "^1.24.0",
@@ -22,43 +22,30 @@ class StellarAdapter extends abstract_adapter_1.AbstractAdapter {
22
22
  }
23
23
  async getTokensBalances(userAddress, tokensAddresses) {
24
24
  const sacTokenAddresses = tokensAddresses.map(this.convertTokenAddressToSAC);
25
- // const balancePromises = sacTokenAddresses.map(async (contractId) => {
26
- // const contract = new Contract(contractId);
27
- // const operation = contract.call('balance', nativeToScVal(userAddress, { type: 'address' }));
28
- // const tx = new TransactionBuilder(new Account(userAddress, '0'), {
29
- // fee: BASE_FEE,
30
- // networkPassphrase: Networks.PUBLIC
31
- // })
32
- // .addOperation(operation)
33
- // .setTimeout(30)
34
- // .build();
35
- // try {
36
- // const resp = await this.public.simulateTransaction(tx);
37
- // //@ts-ignore
38
- // const rawRetval = resp.results.retval;
39
- // const balanceBigInt = scValToBigInt(rawRetval);
40
- // this.public.getSACBalance()
41
- // return new BigNumber(balanceScVal.toString());
42
- // } catch (err) {
43
- // console.log(err);
44
- // return new BigNumber('0');
45
- // }
46
- // });
47
- const assets = tokensAddresses.map((address) => {
48
- if (address === '0x0000000000000000000000000000000000000000') {
49
- return stellar_sdk_1.Asset.native();
50
- }
51
- const [code, issuer] = address.split('-');
52
- return new stellar_sdk_1.Asset(code, issuer);
53
- });
54
- const balancePromises = assets.map(async (asset) => {
25
+ const balancePromises = sacTokenAddresses.map(async (contractId) => {
26
+ const contract = new stellar_sdk_1.Contract(contractId);
27
+ const operation = contract.call('balance', (0, stellar_sdk_1.nativeToScVal)(userAddress, { type: 'address' }));
28
+ const tx = new stellar_sdk_1.TransactionBuilder(new stellar_sdk_1.Account(userAddress, '0'), {
29
+ fee: stellar_sdk_1.BASE_FEE,
30
+ networkPassphrase: stellar_sdk_1.Networks.PUBLIC
31
+ })
32
+ .addOperation(operation)
33
+ .setTimeout(30)
34
+ .build();
55
35
  try {
56
- const resp = await this.public.getTrustline(userAddress, asset);
57
- return new bignumber_js_1.default(resp.balance().toString());
36
+ const resp = await this.public.simulateTransaction(tx);
37
+ //@ts-ignore
38
+ if (resp.error) {
39
+ return new bignumber_js_1.default(0);
40
+ }
41
+ //@ts-ignore
42
+ const rawRetval = resp.result.retval;
43
+ const balance = (0, stellar_sdk_1.scValToBigInt)(rawRetval);
44
+ return new bignumber_js_1.default(balance.toString());
58
45
  }
59
46
  catch (err) {
60
- console.error(err);
61
- return new bignumber_js_1.default(0);
47
+ console.log(err);
48
+ return new bignumber_js_1.default('0');
62
49
  }
63
50
  });
64
51
  try {