edge-core-js 0.19.18 → 0.19.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.
@@ -35,6 +35,7 @@ import {
35
35
  splitWalletInfo
36
36
  } from '../login/keys.js'
37
37
  import { applyKit } from '../login/login.js'
38
+ import { deleteLogin } from '../login/login-delete.js'
38
39
  import {
39
40
  cancelOtpReset,
40
41
  disableOtp,
@@ -291,6 +292,10 @@ export function makeAccountApi(ai, accountId) {
291
292
  },
292
293
 
293
294
  // Login management:
295
+ async deleteRemoteAccount() {
296
+ const { loginTree } = accountState()
297
+ await deleteLogin(ai, loginTree)
298
+ },
294
299
  async logout() {
295
300
  ai.props.dispatch({ type: 'LOGOUT', payload: { accountId } })
296
301
  },
@@ -633,6 +633,7 @@ export function combineTxWithFile(
633
633
 
634
634
  // Copy the tx properties to the output:
635
635
  const out = {
636
+ confirmations: tx.confirmations,
636
637
  blockHeight: tx.blockHeight,
637
638
  date: tx.date,
638
639
  ourReceiveAddresses: tx.ourReceiveAddresses,
@@ -129,11 +129,56 @@ export function makeCurrencyWalletCallbacks(
129
129
  })
130
130
  },
131
131
 
132
+ // DEPRECATE: After all currency plugins implement new Confirmations API
132
133
  onBlockHeightChanged(height) {
133
134
  pushUpdate({
134
135
  id: walletId,
135
136
  action: 'onBlockHeightChanged',
136
137
  updateFunc: () => {
138
+ // Update transaction confirmation status
139
+ const { txs: reduxTxs } = input.props.walletState
140
+ const txsHack = Object.values(reduxTxs)
141
+ const reduxTxsArray = txsHack
142
+ for (const reduxTx of reduxTxsArray) {
143
+ if (
144
+ reduxTx.confirmations !== 'confirmed' &&
145
+ reduxTx.confirmations !== 'dropped'
146
+ ) {
147
+ const {
148
+ requiredConfirmations
149
+ } = input.props.walletState.currencyInfo
150
+ const { height } = input.props.walletState
151
+
152
+ reduxTx.confirmations = validateConfirmations(
153
+ reduxTx,
154
+ height,
155
+ requiredConfirmations
156
+ )
157
+
158
+ // Recreate the EdgeTransaction object
159
+ const txidHash = hashStorageWalletFilename(
160
+ input.props.state,
161
+ walletId,
162
+ reduxTx.txid
163
+ )
164
+ const { files } = input.props.walletState
165
+ const changedTx = combineTxWithFile(
166
+ input,
167
+ reduxTx,
168
+ files[txidHash],
169
+ reduxTx.currencyCode
170
+ )
171
+
172
+ // Dispatch event to update the redux transaction object
173
+ input.props.dispatch({
174
+ type: 'CHANGE_MERGE_TX',
175
+ payload: { tx: reduxTx }
176
+ })
177
+ // Dispatch event to update the EdgeTransaction object
178
+ throtteldOnTxChanged([changedTx])
179
+ }
180
+ }
181
+
137
182
  input.props.dispatch({
138
183
  type: 'CURRENCY_ENGINE_CHANGED_HEIGHT',
139
184
  payload: { height, walletId }
@@ -189,6 +234,21 @@ export function makeCurrencyWalletCallbacks(
189
234
  for (const tx of txs) {
190
235
  const { txid } = tx
191
236
 
237
+ // DEPRECATE: After all currency plugins implement new Confirmations API
238
+ if (
239
+ tx.confirmations !== 'confirmed' &&
240
+ tx.confirmations !== 'dropped'
241
+ ) {
242
+ const { requiredConfirmations } = input.props.walletState.currencyInfo
243
+ const { height } = input.props.walletState
244
+
245
+ tx.confirmations = validateConfirmations(
246
+ tx,
247
+ height,
248
+ requiredConfirmations
249
+ )
250
+ }
251
+
192
252
  // Verify that something has changed:
193
253
  const reduxTx = mergeTx(tx, defaultCurrency, reduxTxs[txid])
194
254
  if (compare(reduxTx, reduxTxs[txid])) continue
@@ -257,3 +317,27 @@ export function watchCurrencyWallet(input) {
257
317
  }
258
318
  checkChangesLoop(input.props)
259
319
  }
320
+
321
+ const validateConfirmations = (
322
+ tx,
323
+ blockHeight,
324
+ requiredConfirmations = 1 // Default confirmation rule is 1 block
325
+ ) => {
326
+ // If tx block height is 0, this means it's not yet mined in a block,
327
+ // so block confirmations is 0.
328
+ const blockConfirmations =
329
+ tx.blockHeight === 0 ? 0 : 1 + blockHeight - tx.blockHeight
330
+ /*
331
+ A negative number of block confirmations means the wallet's block
332
+ height has not caught up with the transaction's block height, or the
333
+ transaction is mined in a block which is apart of an chain fork.
334
+ Either way, the transaction is considered unconfirmed.
335
+ */
336
+ const confirmations =
337
+ blockConfirmations >= requiredConfirmations
338
+ ? 'confirmed'
339
+ : blockConfirmations <= 0
340
+ ? 'unconfirmed'
341
+ : blockConfirmations
342
+ return confirmations
343
+ }
@@ -1,4 +1,4 @@
1
- //
1
+ function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }//
2
2
 
3
3
  import {
4
4
 
@@ -89,6 +89,8 @@ import { currencyCodesToTokenIds } from './enabled-tokens.js'
89
89
 
90
90
 
91
91
 
92
+
93
+
92
94
 
93
95
 
94
96
 
@@ -320,6 +322,12 @@ const currencyWalletInner
320
322
  next
321
323
  ) {
322
324
  switch (action.type) {
325
+ case 'CHANGE_MERGE_TX': {
326
+ const { tx } = action.payload
327
+ const out = { ...state }
328
+ out[tx.txid] = tx
329
+ return out
330
+ }
323
331
  case 'CURRENCY_ENGINE_CHANGED_TXS': {
324
332
  const { txs } = action.payload
325
333
  const defaultCurrency = next.self.currencyInfo.currencyCode
@@ -393,6 +401,8 @@ export const currencyWalletReducer
393
401
  )
394
402
 
395
403
  const defaultTx = {
404
+ confirmations: 'unconfirmed',
405
+ currencyCode: '',
396
406
  blockHeight: 0,
397
407
  date: 0,
398
408
  ourReceiveAddresses: [],
@@ -411,7 +421,11 @@ export function mergeTx(
411
421
  defaultCurrency,
412
422
  oldTx = defaultTx
413
423
  ) {
424
+ const currencyCode =
425
+ tx.currencyCode != null ? tx.currencyCode : defaultCurrency
414
426
  const out = {
427
+ confirmations: _nullishCoalesce(tx.confirmations, () => ( 'unconfirmed')),
428
+ currencyCode,
415
429
  blockHeight: tx.blockHeight,
416
430
  date: tx.date,
417
431
  ourReceiveAddresses: tx.ourReceiveAddresses,
@@ -423,8 +437,6 @@ export function mergeTx(
423
437
  networkFee: { ...oldTx.networkFee }
424
438
  }
425
439
 
426
- const currencyCode =
427
- tx.currencyCode != null ? tx.currencyCode : defaultCurrency
428
440
  out.nativeAmount[currencyCode] = tx.nativeAmount
429
441
  out.networkFee[currencyCode] =
430
442
  tx.networkFee != null ? tx.networkFee.toString() : '0'
@@ -0,0 +1,23 @@
1
+
2
+
3
+
4
+ import { makeAuthJson } from './login.js'
5
+ import { loginFetch } from './login-fetch.js'
6
+ import { getStashById } from './login-selectors.js'
7
+
8
+
9
+ /**
10
+ * Deletes a login from the server.
11
+ */
12
+ export async function deleteLogin(
13
+ ai,
14
+ login
15
+ ) {
16
+ const { stashTree } = getStashById(ai, login.loginId)
17
+ await loginFetch(
18
+ ai,
19
+ 'POST',
20
+ '/v2/login/delete',
21
+ makeAuthJson(stashTree, login)
22
+ )
23
+ }
package/lib/node/index.js CHANGED
@@ -5461,6 +5461,16 @@ function makeExchangeCache(ai) {
5461
5461
  return out;
5462
5462
  }
5463
5463
 
5464
+ /**
5465
+ * Deletes a login from the server.
5466
+ */
5467
+ async function deleteLogin(ai, login) {
5468
+ const {
5469
+ stashTree
5470
+ } = getStashById(ai, login.loginId);
5471
+ await loginFetch(ai, 'POST', '/v2/login/delete', makeAuthJson(stashTree, login));
5472
+ }
5473
+
5464
5474
  const wasChangePasswordPayload = cleaners.uncleaner(asChangePasswordPayload);
5465
5475
  const passwordAuthSnrp = userIdSnrp;
5466
5476
 
@@ -7672,6 +7682,13 @@ function makeAccountApi(ai, accountId) {
7672
7682
  },
7673
7683
 
7674
7684
  // Login management:
7685
+ async deleteRemoteAccount() {
7686
+ const {
7687
+ loginTree
7688
+ } = accountState();
7689
+ await deleteLogin(ai, loginTree);
7690
+ },
7691
+
7675
7692
  async logout() {
7676
7693
  ai.props.dispatch({
7677
7694
  type: 'LOGOUT',
@@ -9649,6 +9666,17 @@ const currencyWalletInner = reduxKeto.buildReducer({
9649
9666
 
9650
9667
  txs(state = {}, action, next) {
9651
9668
  switch (action.type) {
9669
+ case 'CHANGE_MERGE_TX':
9670
+ {
9671
+ const {
9672
+ tx
9673
+ } = action.payload;
9674
+ const out = { ...state
9675
+ };
9676
+ out[tx.txid] = tx;
9677
+ return out;
9678
+ }
9679
+
9652
9680
  case 'CURRENCY_ENGINE_CHANGED_TXS':
9653
9681
  {
9654
9682
  const {
@@ -9714,6 +9742,8 @@ const currencyWalletReducer = reduxKeto.filterReducer(currencyWalletInner, (acti
9714
9742
  };
9715
9743
  });
9716
9744
  const defaultTx = {
9745
+ confirmations: 'unconfirmed',
9746
+ currencyCode: '',
9717
9747
  blockHeight: 0,
9718
9748
  date: 0,
9719
9749
  ourReceiveAddresses: [],
@@ -9728,7 +9758,10 @@ const defaultTx = {
9728
9758
  */
9729
9759
 
9730
9760
  function mergeTx(tx, defaultCurrency, oldTx = defaultTx) {
9761
+ const currencyCode = tx.currencyCode != null ? tx.currencyCode : defaultCurrency;
9731
9762
  const out = {
9763
+ confirmations: tx.confirmations ?? 'unconfirmed',
9764
+ currencyCode,
9732
9765
  blockHeight: tx.blockHeight,
9733
9766
  date: tx.date,
9734
9767
  ourReceiveAddresses: tx.ourReceiveAddresses,
@@ -9740,7 +9773,6 @@ function mergeTx(tx, defaultCurrency, oldTx = defaultTx) {
9740
9773
  networkFee: { ...oldTx.networkFee
9741
9774
  }
9742
9775
  };
9743
- const currencyCode = tx.currencyCode != null ? tx.currencyCode : defaultCurrency;
9744
9776
  out.nativeAmount[currencyCode] = tx.nativeAmount;
9745
9777
  out.networkFee[currencyCode] = tx.networkFee != null ? tx.networkFee.toString() : '0';
9746
9778
 
@@ -9849,11 +9881,46 @@ function makeCurrencyWalletCallbacks(input) {
9849
9881
  });
9850
9882
  },
9851
9883
 
9884
+ // DEPRECATE: After all currency plugins implement new Confirmations API
9852
9885
  onBlockHeightChanged(height) {
9853
9886
  pushUpdate({
9854
9887
  id: walletId,
9855
9888
  action: 'onBlockHeightChanged',
9856
9889
  updateFunc: () => {
9890
+ // Update transaction confirmation status
9891
+ const {
9892
+ txs: reduxTxs
9893
+ } = input.props.walletState;
9894
+ const txsHack = Object.values(reduxTxs);
9895
+ const reduxTxsArray = txsHack;
9896
+
9897
+ for (const reduxTx of reduxTxsArray) {
9898
+ if (reduxTx.confirmations !== 'confirmed' && reduxTx.confirmations !== 'dropped') {
9899
+ const {
9900
+ requiredConfirmations
9901
+ } = input.props.walletState.currencyInfo;
9902
+ const {
9903
+ height
9904
+ } = input.props.walletState;
9905
+ reduxTx.confirmations = validateConfirmations(reduxTx, height, requiredConfirmations); // Recreate the EdgeTransaction object
9906
+
9907
+ const txidHash = hashStorageWalletFilename(input.props.state, walletId, reduxTx.txid);
9908
+ const {
9909
+ files
9910
+ } = input.props.walletState;
9911
+ const changedTx = combineTxWithFile(input, reduxTx, files[txidHash], reduxTx.currencyCode); // Dispatch event to update the redux transaction object
9912
+
9913
+ input.props.dispatch({
9914
+ type: 'CHANGE_MERGE_TX',
9915
+ payload: {
9916
+ tx: reduxTx
9917
+ }
9918
+ }); // Dispatch event to update the EdgeTransaction object
9919
+
9920
+ throtteldOnTxChanged([changedTx]);
9921
+ }
9922
+ }
9923
+
9857
9924
  input.props.dispatch({
9858
9925
  type: 'CURRENCY_ENGINE_CHANGED_HEIGHT',
9859
9926
  payload: {
@@ -9909,7 +9976,18 @@ function makeCurrencyWalletCallbacks(input) {
9909
9976
  for (const tx of txs) {
9910
9977
  const {
9911
9978
  txid
9912
- } = tx; // Verify that something has changed:
9979
+ } = tx; // DEPRECATE: After all currency plugins implement new Confirmations API
9980
+
9981
+ if (tx.confirmations !== 'confirmed' && tx.confirmations !== 'dropped') {
9982
+ const {
9983
+ requiredConfirmations
9984
+ } = input.props.walletState.currencyInfo;
9985
+ const {
9986
+ height
9987
+ } = input.props.walletState;
9988
+ tx.confirmations = validateConfirmations(tx, height, requiredConfirmations);
9989
+ } // Verify that something has changed:
9990
+
9913
9991
 
9914
9992
  const reduxTx = mergeTx(tx, defaultCurrency, reduxTxs[txid]);
9915
9993
  if (compare(reduxTx, reduxTxs[txid])) continue; // Ensure the transaction has metadata:
@@ -9982,6 +10060,22 @@ function watchCurrencyWallet(input) {
9982
10060
  checkChangesLoop(input.props);
9983
10061
  }
9984
10062
 
10063
+ const validateConfirmations = (tx, blockHeight, requiredConfirmations = 1 // Default confirmation rule is 1 block
10064
+ ) => {
10065
+ // If tx block height is 0, this means it's not yet mined in a block,
10066
+ // so block confirmations is 0.
10067
+ const blockConfirmations = tx.blockHeight === 0 ? 0 : 1 + blockHeight - tx.blockHeight;
10068
+ /*
10069
+ A negative number of block confirmations means the wallet's block
10070
+ height has not caught up with the transaction's block height, or the
10071
+ transaction is mined in a block which is apart of an chain fork.
10072
+ Either way, the transaction is considered unconfirmed.
10073
+ */
10074
+
10075
+ const confirmations = blockConfirmations >= requiredConfirmations ? 'confirmed' : blockConfirmations <= 0 ? 'unconfirmed' : blockConfirmations;
10076
+ return confirmations;
10077
+ };
10078
+
9985
10079
  function dateFilter(tx, opts) {
9986
10080
  const {
9987
10081
  startDate = -Infinity,
@@ -10623,6 +10717,7 @@ function combineTxWithFile(input, tx, file, currencyCode) {
10623
10717
  } = flowHack; // Copy the tx properties to the output:
10624
10718
 
10625
10719
  const out = {
10720
+ confirmations: tx.confirmations,
10626
10721
  blockHeight: tx.blockHeight,
10627
10722
  date: tx.date,
10628
10723
  ourReceiveAddresses: tx.ourReceiveAddresses,
@@ -1408,6 +1408,10 @@ export * from './error.js'
1408
1408
 
1409
1409
 
1410
1410
 
1411
+
1412
+
1413
+
1414
+
1411
1415
 
1412
1416
 
1413
1417
 
@@ -301,7 +301,7 @@ export interface EdgeCurrencyInfo {
301
301
  canReplaceByFee?: boolean // Defaults to false
302
302
  customFeeTemplate?: EdgeObjectTemplate // Indicates custom fee support
303
303
  customTokenTemplate?: EdgeObjectTemplate // Indicates custom token support
304
- requiredConfirmations?: number
304
+ requiredConfirmations?: number // Block confirmations required for a tx
305
305
  memoMaxLength?: number // Max number of text characters, if supported
306
306
  memoMaxValue?: string // Max numerical value, if supported
307
307
  memoType?: 'text' | 'number' | 'other' // undefined means no memo support
@@ -367,6 +367,7 @@ export interface EdgeTransaction {
367
367
  parentNetworkFee?: string
368
368
 
369
369
  // Confirmation status:
370
+ confirmations?: 'confirmed' | 'unconfirmed' | 'dropped' | number
370
371
  blockHeight: number
371
372
  date: number
372
373
 
@@ -551,11 +552,13 @@ export interface EdgeCurrencyEngineCallbacks {
551
552
  currencyCode: string,
552
553
  nativeBalance: string
553
554
  ) => void
554
- readonly onBlockHeightChanged: (blockHeight: number) => void
555
555
  readonly onStakingStatusChanged: (status: EdgeStakingStatus) => void
556
556
  readonly onTransactionsChanged: (transactions: EdgeTransaction[]) => void
557
557
  readonly onTxidsChanged: (txids: EdgeTxidMap) => void
558
558
  readonly onWcNewContractCall: (payload: JsonObject) => void
559
+
560
+ // Deprecated
561
+ readonly onBlockHeightChanged: (blockHeight: number) => void
559
562
  }
560
563
 
561
564
  export interface EdgeCurrencyEngineOptions {
@@ -1156,6 +1159,7 @@ export interface EdgeAccount {
1156
1159
  readonly fetchLobby: (lobbyId: string) => Promise<EdgeLobby>
1157
1160
 
1158
1161
  // Login management:
1162
+ readonly deleteRemoteAccount: () => Promise<void>
1159
1163
  readonly logout: () => Promise<void>
1160
1164
 
1161
1165
  // Master wallet list:
package/lib/types.d.ts CHANGED
@@ -238,6 +238,7 @@ export interface EdgeTransaction {
238
238
  nativeAmount: string;
239
239
  networkFee: string;
240
240
  parentNetworkFee?: string;
241
+ confirmations?: 'confirmed' | 'unconfirmed' | 'dropped' | number;
241
242
  blockHeight: number;
242
243
  date: number;
243
244
  txid: string;
@@ -371,11 +372,11 @@ export interface EdgeCurrencyEngineCallbacks {
371
372
  readonly onAddressChanged: () => void;
372
373
  readonly onAddressesChecked: (progressRatio: number) => void;
373
374
  readonly onBalanceChanged: (currencyCode: string, nativeBalance: string) => void;
374
- readonly onBlockHeightChanged: (blockHeight: number) => void;
375
375
  readonly onStakingStatusChanged: (status: EdgeStakingStatus) => void;
376
376
  readonly onTransactionsChanged: (transactions: EdgeTransaction[]) => void;
377
377
  readonly onTxidsChanged: (txids: EdgeTxidMap) => void;
378
378
  readonly onWcNewContractCall: (payload: JsonObject) => void;
379
+ readonly onBlockHeightChanged: (blockHeight: number) => void;
379
380
  }
380
381
  export interface EdgeCurrencyEngineOptions {
381
382
  callbacks: EdgeCurrencyEngineCallbacks;
@@ -725,6 +726,7 @@ export interface EdgeAccount {
725
726
  readonly approveVoucher: (voucherId: string) => Promise<void>;
726
727
  readonly rejectVoucher: (voucherId: string) => Promise<void>;
727
728
  readonly fetchLobby: (lobbyId: string) => Promise<EdgeLobby>;
729
+ readonly deleteRemoteAccount: () => Promise<void>;
728
730
  readonly logout: () => Promise<void>;
729
731
  readonly allKeys: EdgeWalletInfoFull[];
730
732
  readonly changeWalletStates: (walletStates: EdgeWalletStates) => Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "edge-core-js",
3
- "version": "0.19.18",
3
+ "version": "0.19.21",
4
4
  "description": "Edge account & wallet management library",
5
5
  "keywords": [
6
6
  "bitcoin",
@@ -304,7 +304,7 @@ export type EdgeCurrencyInfo = {
304
304
  canReplaceByFee?: boolean, // Defaults to false
305
305
  customFeeTemplate?: EdgeObjectTemplate, // Indicates custom fee support
306
306
  customTokenTemplate?: EdgeObjectTemplate, // Indicates custom token support
307
- requiredConfirmations?: number,
307
+ requiredConfirmations?: number, // Block confirmations required for a tx
308
308
  memoMaxLength?: number, // Max number of text characters, if supported
309
309
  memoMaxValue?: string, // Max numerical value, if supported
310
310
  memoType?: 'text' | 'number' | 'other', // undefined means no memo support
@@ -370,6 +370,7 @@ export type EdgeTransaction = {
370
370
  parentNetworkFee?: string,
371
371
 
372
372
  // Confirmation status:
373
+ confirmations?: 'confirmed' | 'unconfirmed' | 'dropped' | number,
373
374
  blockHeight: number,
374
375
  date: number,
375
376
 
@@ -549,11 +550,13 @@ export type EdgeCurrencyEngineCallbacks = {
549
550
  +onAddressChanged: () => void,
550
551
  +onAddressesChecked: (progressRatio: number) => void,
551
552
  +onBalanceChanged: (currencyCode: string, nativeBalance: string) => void,
552
- +onBlockHeightChanged: (blockHeight: number) => void,
553
553
  +onStakingStatusChanged: (status: EdgeStakingStatus) => void,
554
554
  +onTransactionsChanged: (transactions: EdgeTransaction[]) => void,
555
555
  +onTxidsChanged: (txids: EdgeTxidMap) => void,
556
- +onWcNewContractCall: (payload: JsonObject) => void
556
+ +onWcNewContractCall: (payload: JsonObject) => void,
557
+
558
+ // Deprecated
559
+ +onBlockHeightChanged: (blockHeight: number) => void
557
560
  }
558
561
 
559
562
  export type EdgeCurrencyEngineOptions = {
@@ -1124,6 +1127,7 @@ export type EdgeAccount = {
1124
1127
  +fetchLobby: (lobbyId: string) => Promise<EdgeLobby>,
1125
1128
 
1126
1129
  // Login management:
1130
+ +deleteRemoteAccount: () => Promise<void>,
1127
1131
  +logout: () => Promise<void>,
1128
1132
 
1129
1133
  // Master wallet list: