Skip to content

DO NOT MERGE! Experiment stop files loading #627

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"require": "sucrase/register",
"spec": "test/**/*.test.ts"
}
22 changes: 11 additions & 11 deletions src/core/currency/wallet/currency-wallet-callbacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import {
loadFiatFile,
loadNameFile,
loadTokensFile,
loadTxFileNames,
setupNewTxMetadata
loadTxFileNames
// setupNewTxMetadata
} from './currency-wallet-files'
import {
CurrencyWalletInput,
Expand Down Expand Up @@ -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[] = []
Expand All @@ -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
Expand All @@ -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)
Comment on lines +351 to +352
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably want to do changed.push(combinedTx) for every transaction, so the GUI still gets updates.

The idea here is to switch between onTxChanged / onNewTx, but since we don't have files, we just want everything to go in the "existing" bucket. The if (files[txidHash] != null) check was there to prevent crashes, but that's no longer needed thanks to your other changes.

txidHashes[txidHash] = { date: combinedTx.date, txid }
}

Expand Down
51 changes: 26 additions & 25 deletions src/core/currency/wallet/currency-wallet-files.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -353,37 +354,37 @@ async function getLegacyFileNames(
export async function loadTxFileNames(
input: CurrencyWalletInput
): Promise<void> {
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 }
})
}

Expand Down
12 changes: 6 additions & 6 deletions test/core/currency/wallet/currency-wallet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = {
Expand Down
Loading