From b41b3cf2c71e23c4f621fbdd4f4a68b12db37b01 Mon Sep 17 00:00:00 2001 From: Sam Holmes Date: Wed, 20 Nov 2024 15:40:03 -0800 Subject: [PATCH] Experiment stop files loading --- .mocharc.json | 4 ++ .../wallet/currency-wallet-callbacks.ts | 22 ++++---- .../currency/wallet/currency-wallet-files.ts | 51 ++++++++++--------- .../currency/wallet/currency-wallet.test.ts | 12 ++--- 4 files changed, 47 insertions(+), 42 deletions(-) create mode 100644 .mocharc.json diff --git a/.mocharc.json b/.mocharc.json new file mode 100644 index 000000000..40ab01bf0 --- /dev/null +++ b/.mocharc.json @@ -0,0 +1,4 @@ +{ + "require": "sucrase/register", + "spec": "test/**/*.test.ts" +} diff --git a/src/core/currency/wallet/currency-wallet-callbacks.ts b/src/core/currency/wallet/currency-wallet-callbacks.ts index 1131c6eff..1f3fe19e3 100644 --- a/src/core/currency/wallet/currency-wallet-callbacks.ts +++ b/src/core/currency/wallet/currency-wallet-callbacks.ts @@ -24,8 +24,8 @@ import { loadFiatFile, loadNameFile, loadTokensFile, - loadTxFileNames, - setupNewTxMetadata + loadTxFileNames + // setupNewTxMetadata } from './currency-wallet-files' import { CurrencyWalletInput, @@ -307,7 +307,7 @@ export function makeCurrencyWalletCallbacks( // Grab stuff from redux: const { state } = input.props - const { fileNames, txs: reduxTxs } = input.props.walletState + const { /* fileNames, */ txs: reduxTxs } = input.props.walletState const txidHashes: TxidHashes = {} const changed: EdgeTransaction[] = [] @@ -333,12 +333,12 @@ export function makeCurrencyWalletCallbacks( // Ensure the transaction has metadata: const txidHash = hashStorageWalletFilename(state, walletId, txid) - const isNew = tx.isSend ? false : fileNames[txidHash] == null - if (isNew) { - setupNewTxMetadata(input, tx).catch(error => - input.props.onError(error) - ) - } + // const isNew = tx.isSend ? false : fileNames[txidHash] == null + // if (isNew) { + // setupNewTxMetadata(input, tx).catch(error => + // input.props.onError(error) + // ) + // } // Build the final transaction to show the user: const { files } = input.props.walletState @@ -348,8 +348,8 @@ export function makeCurrencyWalletCallbacks( files[txidHash], tx.tokenId ) - if (isNew) created.push(combinedTx) - else if (files[txidHash] != null) changed.push(combinedTx) + // if (isNew) created.push(combinedTx) + // else if (files[txidHash] != null) changed.push(combinedTx) txidHashes[txidHash] = { date: combinedTx.date, txid } } diff --git a/src/core/currency/wallet/currency-wallet-files.ts b/src/core/currency/wallet/currency-wallet-files.ts index afdec00e7..a3a752ac7 100644 --- a/src/core/currency/wallet/currency-wallet-files.ts +++ b/src/core/currency/wallet/currency-wallet-files.ts @@ -1,5 +1,5 @@ import { number as currencyFromNumber } from 'currency-codes' -import { Disklet, justFiles, navigateDisklet } from 'disklet' +import { Disklet, justFiles /* navigateDisklet */ } from 'disklet' import { EdgeAssetAction, @@ -301,6 +301,7 @@ export async function loadTxFiles( * If they in the legacy format, convert them to the new format * and cache them on disk */ +// eslint-disable-next-line @typescript-eslint/no-unused-vars async function getLegacyFileNames( state: RootState, walletId: string, @@ -353,37 +354,37 @@ async function getLegacyFileNames( export async function loadTxFileNames( input: CurrencyWalletInput ): Promise { - const { dispatch, state, walletId } = input.props - const disklet = getStorageWalletDisklet(state, walletId) + const { dispatch, /* state, */ walletId } = input.props + // const disklet = getStorageWalletDisklet(state, walletId) // Legacy transactions files: - const txFileNames: TxFileNames = await getLegacyFileNames( - state, - walletId, - navigateDisklet(disklet, 'Transactions') - ) + // const txFileNames: TxFileNames = await getLegacyFileNames( + // state, + // walletId, + // navigateDisklet(disklet, 'Transactions') + // ) // New transactions files: - const listing = await navigateDisklet(disklet, 'transaction').list() - for (const fileName of justFiles(listing)) { - const prefix = fileName.split('.json')[0] - const split: string[] = prefix.split('-') - const [creationDatePart, txidHash] = split - const creationDate = parseInt(creationDatePart) - - // Create entry in the txFileNames for the txidHash if it doesn't exist - // or the creation date is older than the existing one - if ( - txFileNames[txidHash] == null || - creationDate < txFileNames[txidHash].creationDate - ) { - txFileNames[txidHash] = { creationDate, fileName } - } - } + // const listing = await navigateDisklet(disklet, 'transaction').list() + // for (const fileName of justFiles(listing)) { + // const prefix = fileName.split('.json')[0] + // const split: string[] = prefix.split('-') + // const [creationDatePart, txidHash] = split + // const creationDate = parseInt(creationDatePart) + + // // Create entry in the txFileNames for the txidHash if it doesn't exist + // // or the creation date is older than the existing one + // if ( + // txFileNames[txidHash] == null || + // creationDate < txFileNames[txidHash].creationDate + // ) { + // txFileNames[txidHash] = { creationDate, fileName } + // } + // } dispatch({ type: 'CURRENCY_WALLET_FILE_NAMES_LOADED', - payload: { txFileNames, walletId } + payload: { txFileNames: {}, walletId } }) } diff --git a/test/core/currency/wallet/currency-wallet.test.ts b/test/core/currency/wallet/currency-wallet.test.ts index a7b995b9a..be90ac38a 100644 --- a/test/core/currency/wallet/currency-wallet.test.ts +++ b/test/core/currency/wallet/currency-wallet.test.ts @@ -83,7 +83,7 @@ describe('currency wallets', function () { expect(account.currencyConfig.fakecoin).equals(wallet.currencyConfig) }) - it('triggers callbacks', async function () { + it.skip('triggers callbacks', async function () { const log = makeAssertLog() const { wallet, config } = await makeFakeCurrencyWallet() @@ -183,7 +183,7 @@ describe('currency wallets', function () { await log.waitFor(1).assert('new e f g') }) - it('handles token balances', async function () { + it.skip('handles token balances', async function () { const fixture: Fixture = await makeFakeCurrencyWallet() const { wallet, config } = fixture await config.changeUserSettings({ @@ -304,7 +304,7 @@ describe('currency wallets', function () { ) }) - it('streams transactions', async function () { + it.skip('streams transactions', async function () { const { wallet, config } = await makeFakeCurrencyWallet() const tokenId = await addDemoTransactions(config) @@ -333,7 +333,7 @@ describe('currency wallets', function () { checkIteratorResult(await search.next()) }) - it('search transactions', async function () { + it.skip('search transactions', async function () { const { wallet, config } = await makeFakeCurrencyWallet() await addDemoTransactions(config) @@ -423,7 +423,7 @@ describe('currency wallets', function () { expect(await wallet.nativeToDenomination('10', 'TOKEN')).equals('0.01') }) - it('can save metadata at spend time', async function () { + it.skip('can save metadata at spend time', async function () { const log = makeAssertLog() const { wallet, config } = await makeFakeCurrencyWallet() await config.changeUserSettings({ balance: 100 }) // Spending balance @@ -594,7 +594,7 @@ describe('currency wallets', function () { expect(txs[0].savedAction).deep.equals(savedAction) }) - it('can delete metadata', async function () { + it.skip('can delete metadata', async function () { const { wallet, config } = await makeFakeCurrencyWallet() const metadata: EdgeMetadata = {