Skip to content
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

Offline support #195

Merged
merged 33 commits into from Feb 4, 2019
Merged

Offline support #195

merged 33 commits into from Feb 4, 2019

Conversation

TobiaszCudnik
Copy link
Contributor

This PR adds:

  • offline support (account, recent transactions)
  • connections status (top bar icon / text, responsive)

Fixes following issues:

Does not cover the following:

To demo the feature one needs to have a non-localhost server with HTTPS.

TobiaszCudnik and others added 18 commits January 22, 2019 17:59
- listen to the browser's offline event
- refactored service worker to async/await
- persist the account data
- refresh the data after going online
- persist recent transactions
- persist recent transactions
- persist recent transactions
- refresh when connecting
During one of the Ledger code refactors the feature of pinging the
Ledger device only when the UI needs the information was lost. This
commit reimplements that feature.

This is also needed for users of Yubikeys (for which the U2F protocol
was created for), to not bombard their non-Ledger devices with U2F
requests when it's not needed. See #174.
The LedgerChannel wasn't being closed properly in the
ConfirmTransactionDialog logic, thus the background pinging of the
device continued indefinitely. This has been fixed.

In addition the LedgerChannel was opened for non-Ledger transactions.
Now the channel is only openend for accounts of type LEDGER.

See #174 for motivations behind these improvements.
- persist recent transactions
Copy link
Contributor

@roosmaa roosmaa left a comment

Choose a reason for hiding this comment

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

Would've been better if this had been broken in to multiple PRs as currently this branch contains various other changes that aren't directly related to offline support feature (file formatting changes, bug fixes, my changes from another PR). Makes reviewing and catching things harder.

src/index.tsx Outdated Show resolved Hide resolved
src/stores/account.ts Outdated Show resolved Hide resolved
src/stores/account.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@roosmaa roosmaa left a comment

Choose a reason for hiding this comment

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

screenshot 2019-01-29 11 16 21

The font on the connected indicator is wrong.

src/containers/wallet/ConnectionStatus.tsx Outdated Show resolved Hide resolved
src/containers/wallet/ConnectionStatus.tsx Outdated Show resolved Hide resolved
src/containers/wallet/ConnectionStatus.tsx Outdated Show resolved Hide resolved
@roosmaa
Copy link
Contributor

roosmaa commented Jan 29, 2019

Found a bug somewhere with the dirty state probably:

  1. Make sure that the cache local storage key is unset
  2. Refresh wallet with 3 accounts, account 1 open
  3. Open dev tools and toggle offline mode
  4. Open account 2, see errors in console, the loading indicator doesn't go away
  5. Go back to account 1 & disable offline mode
  6. Open account 2, the loading indicator still running, but no actual request to load the transaction data is made
  7. Open account 3, the account history is loaded successfully

@roosmaa
Copy link
Contributor

roosmaa commented Jan 29, 2019

Another bug - the account balance isn't persisted after an offline reload.

  1. Setup a domain with the production service worker installed
  2. Open wallet and let it load data for accounts
  3. Enable offline mode in developer tools
  4. Reload the page
  5. Old transactions appear, but the balance is shown as zero.

Sub-bug 2 of this is that at step 5 the connection indicator claims "Connecting" even-though the browser is offline.

@TobiaszCudnik
Copy link
Contributor Author

Would've been better if this had been broken in to multiple PRs as currently this branch contains various other changes that aren't directly related to offline support feature (file formatting changes, bug fixes, my changes from another PR). Makes reviewing and catching things harder.

Somethings wrong with the github's diff, as it doesnt compare with current master. Eg this change isnt a part of the PR, along with others. Local diff shows the real situation.

Formatting is a part of precommit which seems to have been skipped for some files in recent commits. We should keep master formatted to avoid those.

account balance isn't persisted after an offline reload.

Fixed.

connection indicator claims "Connecting" even-though the browser is offline.

Browser limitation. Online/offline status is event based. Events fire only when it changes, thus doesnt fire when page is load from a service worker when offline.

@TobiaszCudnik
Copy link
Contributor Author

To test the recent changes you need to clean the cache (at least localStorage.cache).

@TobiaszCudnik
Copy link
Contributor Author

Browser limitation. Online/offline status is event based. Events fire only when it changes, thus doesnt fire when page is load from a service worker when offline.

This actually turns out not to be true and we can rely on navigator.onLine. Fixed.

@roosmaa
Copy link
Contributor

roosmaa commented Jan 29, 2019

Will do another review-pass & test run tomorrow morning to see if I spot anything else.

Copy link
Contributor

@roosmaa roosmaa left a comment

Choose a reason for hiding this comment

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

Looking good. Didn't find any obvious bugs during my testing either. Just one suggestion about importData() function signature changes (see comments). Up to you if you want to change this or merge straight away.

account.importData(parseAccountReponse(res, local));
account.loaded = true;
const res = await this.fetchAccountData(id);
account.importData(parseAccountReponse(res, local), true, true);
Copy link
Contributor

Choose a reason for hiding this comment

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

I know that intelliJ shows the argument names, but for the sake of non-intelliJ users it would be nice if the importData() function took an options object with named fields as the final parameter, instead of regular boolean arguments. E.g:

account.importData(parseAccountReponse(res, local), {
    saveCache: true,
    markAsLoaded: true
});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, but an options object for 2 params seems like an overkill.

@@ -152,9 +212,11 @@ export class Transaction {
amount: RawAmount;
amountFee: RawAmount;
fee: RawAmount;
/** TODO may be a problem when keeping the same transaction for 2 users */
Copy link
Contributor

Choose a reason for hiding this comment

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

You mean when both the sender account and recipient account are in the same wallet? That worked as expected while I was testing things.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note for the future, related to #191.

@TobiaszCudnik
Copy link
Contributor Author

TobiaszCudnik commented Jan 30, 2019

I've reformatted the whole master and rebased this branch properly, so only the involved changes are visible in the diff.

@TobiaszCudnik TobiaszCudnik merged commit 57c0e6b into master Feb 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants