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

[WALL-25371] Remove RxJS from WalletLinkConnection #1018

Merged
merged 32 commits into from
Oct 11, 2023

Conversation

bangtoven
Copy link
Contributor

@bangtoven bangtoven commented Sep 29, 2023

Summary

  • removed RxJS and transitioned to TS promises while preserving the original data flow as closely as possible.
  • please note that we prioritized maintaining consistency with the previous rxjs-based implementation.
  • we will revisit for a cleaner implementation with simpler logic.

Previous RxJS removal changes
#779
#969
#988
#992

How did you test your changes?

manual + unit tests

test.mov


import { ConnectionState, RxWebSocket } from './RxWebSocket';
import { ConnectionState, WalletLinkWebSocket } from './RxWebSocket';
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we rename this file name to WalletLinkWebSocket?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes indeed.
didn't make the change yet due to github diff issues. will address in a later pr.

@cb-jake
Copy link
Contributor

cb-jake commented Sep 29, 2023

🙌 Looks great! Will need to pull it down and test. I'll check it out on Monday!

@bangtoven bangtoven marked this pull request as ready for review October 6, 2023 23:28
@bangtoven bangtoven requested a review from cb-jake October 6, 2023 23:28
@@ -43,7 +43,6 @@
"eventemitter3": "^5.0.1",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

dear reviewers,
recommend to turn on Hide whitespace
https://github.com/coinbase/coinbase-wallet-sdk/pull/1018/files?diff=split&w=1
ty!

@bangtoven bangtoven force-pushed the jungho/wlconnection-rxjs-removal branch from a50f5cf to 7ce57a7 Compare October 6, 2023 23:48
@bangtoven bangtoven force-pushed the jungho/wlconnection-rxjs-removal branch from 5a5c823 to d438aed Compare October 6, 2023 23:52
@@ -1,27 +1,29 @@
// Copyright (c) 2018-2023 Coinbase, Inc. <https://www.coinbase.com/>
// Licensed under the Apache License, version 2.0

import { BehaviorSubject, empty, Observable, of, Subject, throwError } from 'rxjs';
import { flatMap, take } from 'rxjs/operators';
import { ServerMessage } from './ServerMessage';
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: should we rename this file to be WebSocket since we're no longer using RX?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#1018 (comment)
@cb-jake yup. but then github considered it as a new file and made it hard to compare from the previous implementation. will rename the file as followup.

Copy link
Contributor

Choose a reason for hiding this comment

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

that makes sense

Copy link
Contributor

@cb-jake cb-jake left a comment

Choose a reason for hiding this comment

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

This looks good and testing seems to work. I think we should have someone with more rxjs experience should look at the PR before merging

@bangtoven bangtoven merged commit a757aa5 into master Oct 11, 2023
14 checks passed
@bangtoven bangtoven deleted the jungho/wlconnection-rxjs-removal branch October 11, 2023 20:01

let connected = false;
switch (state) {
case ConnectionState.DISCONNECTED:
// if DISCONNECTED and not destroyed
Copy link
Contributor

@hieronymus777 hieronymus777 Oct 27, 2023

Choose a reason for hiding this comment

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

Checking if it's intentional we don't skip the initial disconnect event. Potential risk of calling ws.connect() too many times?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

for the record:
with rxjs subject, it used to emit a default value DISCONNECTED whenever the observable was subscribed
by replacing it with callback listener, we expect connectionStateListener only gets invoked when there’s actual state changes. so we don’t need skip(1) for DISCONNECTED

await this.authenticate();
this.sendIsLinked();
this.sendGetSessionConfig();
connected = true;
Copy link
Contributor

@hieronymus777 hieronymus777 Oct 27, 2023

Choose a reason for hiding this comment

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

Previously we would do 'distinctUntilChanged' - meaning we would only emit connected if it changes. So we wouldn't emit two true events in a row. Just making sure this doesn't have a side effect? Nevermind, I see this.connected = connected is below and correctly checks for distinct until changed.

}
break;

case ConnectionState.CONNECTED:
Copy link
Contributor

Choose a reason for hiding this comment

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

We were skipping 2 events before authenticating. Not sure why this was here before but something to verify -are we sure we're not calling authenticate twice?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

for ConnectionState.CONNECTED check which used to have skip(2) , i believe it was to ignore initial DISCONNECTED and CONNECTING states as the comment said. we don’t need this skipping anymore for this code block as we moved to simple switch syntax instead of individual rx subscription.

@@ -246,15 +219,14 @@ export class WalletLinkConnection {
this.diagnostic?.log(EVENTS.STARTED_CONNECTING, {
sessionIdHash: Session.hash(this.sessionId),
});
this.ws.connect().subscribe();
this.ws.connect();
}

/**
* Terminate connection, and mark as destroyed. To reconnect, create a new
* instance of WalletSDKConnection
*/
public destroy(): void {
Copy link
Contributor

Choose a reason for hiding this comment

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

We were calling unsubscribe before which would clear the previous listeners. I don't see that happening anymore. Is there a possibility that the listeners will now get called after the connection is destroyed, for example through a race condition?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

bangtoven added a commit that referenced this pull request Feb 29, 2024
* [WALL-25371] Remove RxJS WalletLinkConnection

* authenticate

* onceConnected onceLinked

* remove connectionStateSubject

* adding delay function to replace rxjs delay

* applying ws.connectionState$ changes

* remove delay func

* comment

* this.connected

* replace this.onceConnected$

* replace linkedSubject

* cleanup

* refactor RxWebSocket class

* fix tests

* remove rxjs from test files

* cleanup

* ws.setIncomingDataListener

* keep markUnseenEventsAsSeen as it used to be

* implement request resolve mapping

* fix tests

* rename RxWebSocket -> WalletLinkWebSocket

* Revert "rename RxWebSocket -> WalletLinkWebSocket"

This reverts commit c3ae669.

* rename only the class

* remove rxjs package

* duh

* cleanup

* reimplement this.linked update pipeline

* separate out once***ed logic

* cleanup

* this.shouldFetchUnseenEventsOnConnect

* cleanup
bangtoven added a commit that referenced this pull request Aug 16, 2024
* [WALL-25371] Remove RxJS WalletLinkConnection

* authenticate

* onceConnected onceLinked

* remove connectionStateSubject

* adding delay function to replace rxjs delay

* applying ws.connectionState$ changes

* remove delay func

* comment

* this.connected

* replace this.onceConnected$

* replace linkedSubject

* cleanup

* refactor RxWebSocket class

* fix tests

* remove rxjs from test files

* cleanup

* ws.setIncomingDataListener

* keep markUnseenEventsAsSeen as it used to be

* implement request resolve mapping

* fix tests

* rename RxWebSocket -> WalletLinkWebSocket

* Revert "rename RxWebSocket -> WalletLinkWebSocket"

This reverts commit c3ae669.

* rename only the class

* remove rxjs package

* duh

* cleanup

* reimplement this.linked update pipeline

* separate out once***ed logic

* cleanup

* this.shouldFetchUnseenEventsOnConnect

* cleanup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants