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

Enhance abstraction: Reassign roles of Connection and WebSocket classes #1061

Closed
wants to merge 42 commits into from

Conversation

bangtoven
Copy link
Contributor

@bangtoven bangtoven commented Nov 14, 2023

Summary

How did you test your changes?

@bangtoven bangtoven changed the title connection state WalletLinkWebSocketUpdateListener Nov 14, 2023
@bangtoven bangtoven force-pushed the jungho/connection-state branch from 45c9214 to fda6484 Compare November 14, 2023 01:40
Comment on lines -146 to -128
case ConnectionState.CONNECTING:
break;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

no-op


this.http = new WalletLinkHTTP(linkAPIUrl, session.id, session.key);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

@@ -17,7 +16,7 @@ export type LogProperties = {
onlineGuests?: number; // number of online guests (should be 0 or 1)
sessionIdHash?: string; // anonymous session id for debugging specific sessions
sessionMetadataChange?: string; // change in session metadata
state?: ConnectionState;
state?: boolean;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

btw, in case you're wondering,
the change maintains functional integrity for logging purposes, because
ConnectionState was an enum with DISCONNECTED as its first value => having a raw value of 0

@@ -17,7 +16,7 @@ export type LogProperties = {
onlineGuests?: number; // number of online guests (should be 0 or 1)
sessionIdHash?: string; // anonymous session id for debugging specific sessions
sessionMetadataChange?: string; // change in session metadata
state?: ConnectionState;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Logger should not depend on ConnectionState

fix tests

fix tests
@bangtoven bangtoven force-pushed the jungho/connection-state branch from 2dd3ebc to ad5d71c Compare November 14, 2023 02:42
@bangtoven bangtoven closed this Nov 14, 2023
@bangtoven bangtoven reopened this Nov 14, 2023
Comment on lines 6 to 9
export enum ConnectionState {
DISCONNECTED,
CONNECTING,
CONNECTED,
Copy link
Contributor Author

@bangtoven bangtoven Nov 14, 2023

Choose a reason for hiding this comment

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

it was arbitrary client-side-only concept
we can manage connection state without this enum

@bangtoven bangtoven force-pushed the jungho/connection-state branch from 582c917 to b5987fd Compare November 14, 2023 18:36
@bangtoven bangtoven force-pushed the jungho/connection-state branch from b5987fd to a6bd0a3 Compare November 14, 2023 18:37
Comment on lines 87 to 93
/**
* This section of code implements a reconnect behavior that was ported from a legacy system.
* Preserving original comments to maintain the rationale and context provided by the original author.
* https://github.com/coinbase/coinbase-wallet-sdk/commit/2087ee4a7d40936cd965011bfacdb76ce3462894#diff-dd71e86752e2c20c0620eb0ba4c4b21674e55ae8afeb005b82906a3821e5023cR84
* TOOD: revisit this logic to assess its validity in the current system context.
*/

Copy link
Contributor Author

@bangtoven bangtoven Nov 14, 2023

Choose a reason for hiding this comment

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

it's ~4 year old logic. will revisit later to see if we can improve this

2087ee4#diff-dd71e86752e2c20c0620eb0ba4c4b21674e55ae8afeb005b82906a3821e5023cR84

setIncomingDataListener(listener: (_: ServerMessage) => void): void {
this.incomingDataListener = listener;
}
private pendingData: ClientMessage[] = [];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

pendingData now stores ClientMessages instead of raw request value

@bangtoven bangtoven force-pushed the jungho/connection-state branch from 0eafafd to 74f368f Compare November 14, 2023 19:05
Comment on lines -120 to -119
// perform authentication upon connection
try {
// if CONNECTED, authenticate, and then check link status
await this.authenticate();
this.sendIsLinked();
this.sendGetSessionConfig();
connected = true;
} catch {
/* empty */
}

// send heartbeat every n seconds while connected
// if CONNECTED, start the heartbeat timer
// first timer event updates lastHeartbeat timestamp
// subsequent calls send heartbeat message
this.updateLastHeartbeat();
setInterval(() => {
this.heartbeat();
}, HEARTBEAT_INTERVAL);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

auth, heartbeat management stuff has been migrated to WalletLinkWebSocket class

session,
WebSocketClass,
listener: this,
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

linkAPIUrl => ws url conversion has been migrated to WalletLinkWebSocket class

image

@bangtoven bangtoven force-pushed the jungho/connection-state branch from b037004 to 4c02a75 Compare November 14, 2023 22:39
@bangtoven bangtoven force-pushed the jungho/connection-state branch from 4c02a75 to ed795fe Compare November 14, 2023 22:41
commit 467fafe
Author: Jungho Bang <[email protected]>
Date:   Wed Nov 15 12:40:57 2023 -0800

    apply to HTTP API

commit 883715a
Author: Jungho Bang <[email protected]>
Date:   Wed Nov 15 12:40:47 2023 -0800

    cleanup

commit d01912a
Author: Jungho Bang <[email protected]>
Date:   Wed Nov 15 12:25:30 2023 -0800

    fi xWalletUI

commit 0228706
Author: Jungho Bang <[email protected]>
Date:   Wed Nov 15 12:22:27 2023 -0800

    cleanup

commit 620216f
Author: Jungho Bang <[email protected]>
Date:   Wed Nov 15 12:16:15 2023 -0800

    WalletLinkEventType

commit ea54a0c
Author: Jungho Bang <[email protected]>
Date:   Wed Nov 15 12:07:40 2023 -0800

    apply change to selectProvider

commit 577e596
Author: Jungho Bang <[email protected]>
Date:   Wed Nov 15 12:00:47 2023 -0800

    clarify param

commit 66cbeb8
Author: Jungho Bang <[email protected]>
Date:   Wed Nov 15 11:45:37 2023 -0800

    revert rename

commit 6f3b4bd
Author: Jungho Bang <[email protected]>
Date:   Wed Nov 15 11:36:45 2023 -0800

    fix tests

commit b709f69
Author: Jungho Bang <[email protected]>
Date:   Wed Nov 15 10:26:08 2023 -0800

    rename relay message to be `WalletLinkEventData`

commit cf0ad57
Author: Jungho Bang <[email protected]>
Date:   Wed Nov 15 00:25:21 2023 -0800

    cleaner

commit bfafff9
Author: Jungho Bang <[email protected]>
Date:   Wed Nov 15 00:14:57 2023 -0800

    fix provider

commit 90feb0e
Author: Jungho Bang <[email protected]>
Date:   Tue Nov 14 23:48:07 2023 -0800

    no error on relay

commit cb90fd1
Author: Jungho Bang <[email protected]>
Date:   Tue Nov 14 23:17:51 2023 -0800

    wtf

commit 17c67b5
Author: Jungho Bang <[email protected]>
Date:   Tue Nov 14 23:06:32 2023 -0800

    consolidate RelayMessage

commit f636d5f
Author: Jungho Bang <[email protected]>
Date:   Tue Nov 14 22:12:25 2023 -0800

    support case of request and response having different method

commit a95e96e
Author: Jungho Bang <[email protected]>
Date:   Tue Nov 14 22:04:19 2023 -0800

    comment

commit 8f07056
Author: Jungho Bang <[email protected]>
Date:   Tue Nov 14 22:00:18 2023 -0800

    sync

commit c478f1e
Author: Jungho Bang <[email protected]>
Date:   Tue Nov 14 21:57:26 2023 -0800

    no need to be exported RelayMessageType

commit 7c9cb7b
Author: Jungho Bang <[email protected]>
Date:   Tue Nov 14 21:57:08 2023 -0800

    apply Web3Response changes

commit e2232a8
Author: Jungho Bang <[email protected]>
Date:   Tue Nov 14 21:49:44 2023 -0800

    cleanup RelayMessage

commit c5a93d6
Author: Jungho Bang <[email protected]>
Date:   Tue Nov 14 19:54:54 2023 -0800

    introducing SupportedWeb3Methods

commit 99176c8
Author: Jungho Bang <[email protected]>
Date:   Tue Nov 14 19:26:24 2023 -0800

    improvements

commit 9ceab2a
Author: Jungho Bang <[email protected]>
Date:   Tue Nov 14 19:10:11 2023 -0800

    help git

commit 6c86f5a
Author: Jungho Bang <[email protected]>
Date:   Tue Nov 14 19:04:53 2023 -0800

    Web3Response

commit 93edb63
Author: Jungho Bang <[email protected]>
Date:   Tue Nov 14 18:16:33 2023 -0800

    refactoring Web3Request

commit 154ba57
Author: Jungho Bang <[email protected]>
Date:   Tue Nov 14 17:51:49 2023 -0800

    lfg

commit 2bcc7a7
Author: Jungho Bang <[email protected]>
Date:   Tue Nov 14 17:12:40 2023 -0800

    apply changes

commit 911c669
Author: Jungho Bang <[email protected]>
Date:   Tue Nov 14 16:51:58 2023 -0800

    apply it to ClientMessage

commit 20f7612
Author: Jungho Bang <[email protected]>
Date:   Tue Nov 14 15:48:09 2023 -0800

    refactor ServerMessage type
# Conflicts:
#	packages/wallet-sdk/src/connection/DiagnosticLogger.ts
#	packages/wallet-sdk/src/connection/WalletLinkConnection.ts
@bangtoven bangtoven changed the title WalletLinkWebSocketUpdateListener Enhance abstraction: Reassign roles of Connection and WebSocket classes Nov 16, 2023
@bangtoven bangtoven closed this Feb 29, 2024
@bangtoven bangtoven deleted the jungho/connection-state branch February 29, 2024 05:10
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.

1 participant