edge-core-js 2.41.2 → 2.42.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/lib/flow/types.js CHANGED
@@ -544,6 +544,9 @@ export type EdgeCurrencyInfo = {
544
544
  unsafeSyncNetwork?: boolean;
545
545
  usesChangeServer?: boolean;
546
546
 
547
+ /** Show the total sync percentage with this many decimal digits */
548
+ syncDisplayPrecision?: number;
549
+
547
550
  /** @deprecated The default user settings are always `{}` */
548
551
  defaultSettings?: JsonObject;
549
552
 
@@ -811,6 +814,23 @@ export type EdgeStakingStatus = {
811
814
  }>;
812
815
  }
813
816
 
817
+ /**
818
+ * Reports a currency wallet's blockchain syncing progress.
819
+ */
820
+ export type EdgeSyncStatus = {
821
+ /** A single "overview" value of the sync state from 0 to 1. */
822
+ totalRatio: number;
823
+
824
+ /** How far along the chain we are, for chains that scan by blocks. */
825
+ blockRatio?: [number, number]; // [ourHeight: number, chainHeight: number]
826
+
827
+ /**
828
+ * Free-form values to show the user, for engines with unusual info.
829
+ * For example: `{ "donwload speed": "1 KB/s" }`
830
+ */
831
+ otherParams?: { [name: string]: string }; // Record<string, string>
832
+ }
833
+
814
834
  export type EdgeTxidMap = {
815
835
  [txid: string]: number;
816
836
  }
@@ -969,7 +989,6 @@ export type EdgeSignMessageOptions = {
969
989
 
970
990
  export type EdgeCurrencyEngineCallbacks = {
971
991
  +onAddressChanged: () => void;
972
- +onAddressesChecked: (progressRatio: number) => void;
973
992
  +onNewTokens: (tokenIds: string[]) => void;
974
993
  +onSeenTxCheckpoint: (checkpoint: string) => void;
975
994
  +onStakingStatusChanged: (status: EdgeStakingStatus) => void;
@@ -979,6 +998,7 @@ export type EdgeCurrencyEngineCallbacks = {
979
998
  /** @deprecated Use the array of EdgeSubscribedAddress objects instead. */
980
999
  | string[],
981
1000
  ) => void;
1001
+ +onSyncStatusChanged: (syncStatus: EdgeSyncStatus) => void;
982
1002
  +onTokenBalanceChanged: (
983
1003
  tokenId: EdgeTokenId,
984
1004
  balance: string,
@@ -990,6 +1010,9 @@ export type EdgeCurrencyEngineCallbacks = {
990
1010
  ) => void;
991
1011
  +onWcNewContractCall: (payload: JsonObject) => void;
992
1012
 
1013
+ /** @deprecated Use onSyncStatusChanged */
1014
+ +onAddressesChecked: (progressRatio: number) => void;
1015
+
993
1016
  /** @deprecated onTransactionsChanged handles confirmation changes */
994
1017
  +onBlockHeightChanged: (blockHeight: number) => void;
995
1018
 
@@ -1333,7 +1356,7 @@ export type EdgeCurrencyWallet = {
1333
1356
  +balanceMap: EdgeBalanceMap;
1334
1357
  +balances: EdgeBalances;
1335
1358
  +blockHeight: number;
1336
- +syncRatio: number;
1359
+ +syncStatus: EdgeSyncStatus;
1337
1360
  +unactivatedTokenIds: string[];
1338
1361
 
1339
1362
  // Running state:
@@ -1393,6 +1416,9 @@ export type EdgeCurrencyWallet = {
1393
1416
  // Wallet management:
1394
1417
  +dumpData: () => Promise<EdgeDataDump>;
1395
1418
  +resyncBlockchain: () => Promise<void>;
1419
+ +split: (
1420
+ splitWallets: EdgeSplitCurrencyWallet[],
1421
+ ) => Promise<Array<EdgeResult<EdgeCurrencyWallet>>>;
1396
1422
 
1397
1423
  // URI handling:
1398
1424
  +encodeUri: (obj: EdgeEncodeUri) => Promise<string>;
@@ -1436,13 +1462,16 @@ export type EdgeCurrencyWallet = {
1436
1462
  message: string,
1437
1463
  opts?: EdgeSignMessageOptions,
1438
1464
  ) => Promise<string>;
1465
+
1466
+ /** @deprecated Use `syncStatus` instead */
1467
+ +syncRatio: number;
1439
1468
  }
1440
1469
 
1441
1470
  export type EdgeMemoryWallet = {
1442
1471
  +watch: Subscriber<EdgeMemoryWallet>;
1443
1472
  +balanceMap: EdgeBalanceMap;
1444
1473
  +detectedTokenIds: string[];
1445
- +syncRatio: number;
1474
+ +syncStatus: EdgeSyncStatus;
1446
1475
  +changeEnabledTokenIds: (tokenIds: string[]) => Promise<void>;
1447
1476
  +startEngine: () => Promise<void>;
1448
1477
  +getMaxSpendable: (spendInfo: EdgeSpendInfo) => Promise<string>;
@@ -1451,6 +1480,9 @@ export type EdgeMemoryWallet = {
1451
1480
  +broadcastTx: (tx: EdgeTransaction) => Promise<EdgeTransaction>;
1452
1481
  +saveTx: (tx: EdgeTransaction) => Promise<void>;
1453
1482
  +close: () => Promise<void>;
1483
+
1484
+ /** @deprecated Use syncStatus */
1485
+ +syncRatio: number;
1454
1486
  }
1455
1487
 
1456
1488
  // ---------------------------------------------------------------------
@@ -1643,6 +1675,12 @@ export type EdgeCreateCurrencyWallet = EdgeCreateCurrencyWalletOptions & {
1643
1675
  walletType: string;
1644
1676
  };
1645
1677
 
1678
+ export type EdgeSplitCurrencyWallet = {
1679
+ fiatCurrencyCode?: string;
1680
+ name?: string;
1681
+ walletType: string;
1682
+ }
1683
+
1646
1684
  export type EdgeCurrencyConfig = {
1647
1685
  +watch: Subscriber<EdgeCurrencyConfig>;
1648
1686
 
@@ -1848,10 +1886,6 @@ export type EdgeAccount = {
1848
1886
  +getWalletInfo: (id: string) => EdgeWalletInfoFull | void;
1849
1887
  +listWalletIds: () => string[];
1850
1888
  +listSplittableWalletTypes: (walletId: string) => Promise<string[]>;
1851
- +splitWalletInfo: (
1852
- walletId: string,
1853
- newWalletType: string,
1854
- ) => Promise<string>;
1855
1889
 
1856
1890
  // Key access:
1857
1891
  +getDisplayPrivateKey: (walletId: string) => Promise<string>;
@@ -1898,6 +1932,12 @@ export type EdgeAccount = {
1898
1932
  request: EdgeSwapRequest,
1899
1933
  opts?: EdgeSwapRequestOptions,
1900
1934
  ) => Promise<EdgeSwapQuote[]>;
1935
+
1936
+ /** @deprecated Use `EdgeCurrencyWallet.split` instead */
1937
+ +splitWalletInfo: (
1938
+ walletId: string,
1939
+ newWalletType: string,
1940
+ ) => Promise<string>;
1901
1941
  }
1902
1942
 
1903
1943
  // ---------------------------------------------------------------------
@@ -0,0 +1,35 @@
1
+ // @flow
2
+
3
+ import { Buffer } from "buffer";
4
+ import http from "http";
5
+ import { createProxyServer } from "http-proxy";
6
+
7
+ const proxy = createProxyServer({});
8
+
9
+ // Rust WebDAV server running on port 3000
10
+ const WEBDAV_TARGET = "http://localhost:3000";
11
+ const OTHER_TARGET = "http://localhost:4000";
12
+
13
+ const AUTH_USER = "william";
14
+ const AUTH_PASS = "hunter2";
15
+
16
+ const mainServer = http.createServer((req, res) => {
17
+ if (isAuthorized(req)) {
18
+ proxy.web(req, res, { target: WEBDAV_TARGET });
19
+ } else {
20
+ proxy.web(req, res, { target: OTHER_TARGET });
21
+ }
22
+ });
23
+
24
+ mainServer.listen(8080, () => {
25
+ console.log("Node proxy running on port 8080");
26
+ });
27
+
28
+ function isAuthorized(req) {
29
+ const authHeader = req.headers.authorization;
30
+ if (!authHeader || !authHeader.startsWith("Basic ")) return false;
31
+
32
+ const encoded = authHeader.slice(6);
33
+ const decoded = Buffer.from(encoded, "base64").toString("utf8");
34
+ return decoded === `${AUTH_USER}:${AUTH_PASS}`;
35
+ }