beignet 0.0.19 → 0.0.21

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.
@@ -2,7 +2,6 @@ import * as bitcoin from 'bitcoinjs-lib';
2
2
  import { Network, networks } from 'bitcoinjs-lib';
3
3
  import BIP32Factory, { BIP32Interface } from 'bip32';
4
4
  import * as ecc from '@bitcoinerlab/secp256k1';
5
- //import { getExchangeRates } from "../utils/exchange-rate";
6
5
  import {
7
6
  EAddressType,
8
7
  EAvailableNetworks,
@@ -15,7 +14,6 @@ import {
15
14
  IBoostedTransactions,
16
15
  ICustomGetAddress,
17
16
  ICustomGetScriptHash,
18
- IExchangeRates,
19
17
  IFormattedTransaction,
20
18
  IFormattedTransactions,
21
19
  IGenerateAddresses,
@@ -68,7 +66,6 @@ import {
68
66
  getDataFallback,
69
67
  getDefaultWalletData,
70
68
  getDefaultWalletDataKeys,
71
- getExchangeRates,
72
69
  getHighestUsedIndexFromTxHashes,
73
70
  getKeyDerivationPath,
74
71
  getKeyDerivationPathObject,
@@ -85,7 +82,8 @@ import {
85
82
  validateAddress,
86
83
  validateMnemonic,
87
84
  getAddressesFromPrivateKey,
88
- getAddressFromKeyPair
85
+ getAddressFromKeyPair,
86
+ getElectrumNetwork
89
87
  } from '../utils';
90
88
  import {
91
89
  addressTypes,
@@ -141,7 +139,6 @@ export class Wallet {
141
139
  };
142
140
  public electrum: Electrum;
143
141
  public addressType: EAddressType;
144
- public exchangeRates: IExchangeRates;
145
142
  public sendMessage: TOnMessage;
146
143
  public transaction: Transaction;
147
144
  public feeEstimates: IOnchainFees;
@@ -186,7 +183,6 @@ export class Wallet {
186
183
  this.id = generateWalletId(this._seed);
187
184
  this.name = name ?? this.id;
188
185
  this.addressType = addressType;
189
- this.exchangeRates = {};
190
186
  this.transaction = new Transaction({
191
187
  wallet: this
192
188
  });
@@ -233,7 +229,6 @@ export class Wallet {
233
229
  if (wallet._disableMessagesOnCreate) wallet.disableMessages = true;
234
230
  const res = await wallet.setWalletData();
235
231
  if (res.isErr()) return err(res.error.message);
236
- wallet.updateExchangeRates();
237
232
  wallet.updateFeeEstimates();
238
233
  console.log('Syncing Wallet...');
239
234
  await wallet.refreshWallet({});
@@ -470,9 +465,6 @@ export class Wallet {
470
465
  case 'selectedFeeId':
471
466
  walletData[key] = data as EFeeId;
472
467
  break;
473
- case 'exchangeRates':
474
- walletData[key] = data as IExchangeRates;
475
- break;
476
468
  case 'feeEstimates':
477
469
  walletData[key] = data as IOnchainFees;
478
470
  break;
@@ -524,7 +516,7 @@ export class Wallet {
524
516
  const data = {
525
517
  path,
526
518
  type: addressType,
527
- selectedNetwork: this.electrum.getElectrumNetwork(this._network)
519
+ selectedNetwork: getElectrumNetwork(this._network)
528
520
  };
529
521
  const res = await this._customGetAddress(data);
530
522
  if (res.isErr()) return err(res.error.message);
@@ -696,7 +688,7 @@ export class Wallet {
696
688
  network: EAvailableNetworks;
697
689
  }): Promise<string> {
698
690
  if (this._customGetScriptHash) {
699
- const selectedNetwork = this.electrum.getElectrumNetwork(network);
691
+ const selectedNetwork = getElectrumNetwork(network);
700
692
  return await this._customGetScriptHash({ address, selectedNetwork });
701
693
  }
702
694
  return getScriptHash({ address, network });
@@ -2406,22 +2398,6 @@ export class Wallet {
2406
2398
  }
2407
2399
  }
2408
2400
 
2409
- /**
2410
- * Returns exchange rate data from storage.
2411
- * @param {string} currency
2412
- * @returns {number}
2413
- */
2414
- public getExchangeRate(currency = 'EUR'): number {
2415
- try {
2416
- if (currency in this.exchangeRates) {
2417
- return this.exchangeRates[currency]?.rate ?? 0;
2418
- }
2419
- return 0;
2420
- } catch {
2421
- return 0;
2422
- }
2423
- }
2424
-
2425
2401
  /**
2426
2402
  * Attempts to validate a given address.
2427
2403
  * @param {string} address
@@ -3370,20 +3346,6 @@ export class Wallet {
3370
3346
  }
3371
3347
  }
3372
3348
 
3373
- /**
3374
- * Updates the exchange rates for the current network.
3375
- * @public
3376
- * @async
3377
- * @returns {Promise<Result<IExchangeRates>>}
3378
- */
3379
- public async updateExchangeRates(): Promise<Result<IExchangeRates>> {
3380
- const exchangeRates = await getExchangeRates();
3381
- if (exchangeRates.isErr()) return err(exchangeRates.error.message);
3382
- this.exchangeRates = exchangeRates.value;
3383
- await this.saveWalletData('exchangeRates', this.exchangeRates);
3384
- return ok(this.exchangeRates);
3385
- }
3386
-
3387
3349
  /**
3388
3350
  * Updates the fee estimates for the current network.
3389
3351
  * @public
@@ -1,70 +0,0 @@
1
- import { ok, err, Result } from './result';
2
- import { BLOCKTANK_HOST } from '../wallet/constants';
3
- import { IExchangeRates } from '../types';
4
-
5
- export const mostUsedExchangeTickers = {
6
- USD: {
7
- currencySymbol: '$',
8
- quote: 'USD',
9
- quoteName: 'US Dollar'
10
- },
11
- GBP: {
12
- currencySymbol: '£',
13
- quote: 'GBP',
14
- quoteName: 'Great British Pound'
15
- },
16
- CAD: {
17
- currencySymbol: '$',
18
- quote: 'CAD',
19
- quoteName: 'Canadian Dollar'
20
- },
21
- CNY: {
22
- currencySymbol: '¥',
23
- quote: 'CNY',
24
- quoteName: 'Chinese Yuan Renminbi'
25
- },
26
- EUR: { currencySymbol: '€', quote: 'EUR', quoteName: 'Euro' }
27
- };
28
-
29
- type TTicker = {
30
- symbol: string;
31
- lastPrice: string;
32
- base: string;
33
- baseName: string;
34
- quote: string;
35
- quoteName: string;
36
- currencySymbol: string;
37
- currencyFlag: string;
38
- lastUpdatedAt: number;
39
- };
40
-
41
- /**
42
- * Returns the exchange rate for the given currency
43
- * @returns {Promise<Result<IExchangeRates>>}
44
- */
45
- export const getExchangeRates = async (): Promise<Result<IExchangeRates>> => {
46
- try {
47
- const response = await fetch(`${BLOCKTANK_HOST}/fx/rates/btc`);
48
- const { tickers } = await response.json();
49
-
50
- const rates: IExchangeRates = tickers.reduce(
51
- (acc: IExchangeRates, ticker: TTicker) => {
52
- return {
53
- ...acc,
54
- [ticker.quote]: {
55
- currencySymbol: ticker.currencySymbol,
56
- quote: ticker.quote,
57
- quoteName: ticker.quoteName,
58
- rate: Math.round(Number(ticker.lastPrice) * 100) / 100,
59
- lastUpdatedAt: ticker.lastUpdatedAt
60
- }
61
- };
62
- },
63
- {}
64
- );
65
-
66
- return ok(rates);
67
- } catch (e) {
68
- return err(e);
69
- }
70
- };