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

v1.3.6 Improved Session Handling and Logging #318

Closed
wants to merge 20 commits into from

Conversation

kantorcodes
Copy link
Contributor

@kantorcodes kantorcodes commented Oct 29, 2024

Description:

This PR suggests a number of fixes to improve the dApp experience:

  1. Enables dApps to specify a log level for better control of console logs.
  2. Ensures that there is only one Signer per AccountId + ExtensionId combination. Having multiple signers with different ids created issues in pulling the correct record.
  3. Explores better state management and automatic removal of stale sessions.

Related issue(s):

Fixes CON-494

Notes for reviewer:

  • We need to merge v1.3.5 Improved Documentation and Test Runner #317 first and then update this branch before merging this in.
  • These updates are substantial and should be a net positive on the experience, but require careful review from the dApp experience. Wallet experiences should remain mostly the same.

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

@kantorcodes kantorcodes requested review from a team as code owners October 29, 2024 20:33
@kantorcodes kantorcodes force-pushed the CON-494 branch 7 times, most recently from aed5926 to fe12330 Compare October 31, 2024 19:27
Signed-off-by: Michael Kantor <[email protected]>
Signed-off-by: Michael Kantor <[email protected]>
Signed-off-by: Michael Kantor <[email protected]>
Signed-off-by: Michael Kantor <[email protected]>
Comment on lines +139 to +152
const signClient = await SignClient.init({
logger,
relayUrl: 'wss://relay.walletconnect.com',
projectId: this.projectId,
metadata: this.dAppMetadata,
})
this.walletConnectClient = signClient
const existingSessions = this.walletConnectClient.session.getAll()

if (existingSessions.length > 0)
if (existingSessions.length > 0) {
this.signers = existingSessions.flatMap((session) => this.createSigners(session))
else this.checkIframeConnect()
} else {
await this.checkIframeConnect()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with improving code style and formatting, but these changes should be in a separate commit to avoid any confusion with the purpose of this one.

Comment on lines +1 to +42
export interface ILogger {
error(message: string, ...args: any[]): void
warn(message: string, ...args: any[]): void
info(message: string, ...args: any[]): void
debug(message: string, ...args: any[]): void
}

export class DefaultLogger implements ILogger {
private logLevel: 'error' | 'warn' | 'info' | 'debug' = 'info'

constructor(logLevel: 'error' | 'warn' | 'info' | 'debug' = 'info') {
this.logLevel = logLevel
}

setLogLevel(level: 'error' | 'warn' | 'info' | 'debug'): void {
this.logLevel = level
}

error(message: string, ...args: any[]): void {
if (['error', 'warn', 'info', 'debug'].includes(this.logLevel)) {
console.error(`[ERROR] ${message}`, ...args)
}
}

warn(message: string, ...args: any[]): void {
if (['warn', 'info', 'debug'].includes(this.logLevel)) {
console.warn(`[WARN] ${message}`, ...args)
}
}

info(message: string, ...args: any[]): void {
if (['info', 'debug'].includes(this.logLevel)) {
console.info(`[INFO] ${message}`, ...args)
}
}

debug(message: string, ...args: any[]): void {
if (this.logLevel === 'debug') {
console.debug(`[DEBUG] ${message}`, ...args)
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a great idea! However, I'd suggest keeping the logging feature separate from the wallet connect functionality. Putting it in its own commit will keep things clear.

Comment on lines +107 to 112
return transaction._makeTransactionBody(nodeAccountId)
}

export function transactionBodyToBase64String(transactionBody: Uint8Array) {
return Uint8ArrayToBase64String(transactionBody)
export function transactionBodyToBase64String(transactionBody: proto.ITransactionBody) {
return Uint8ArrayToBase64String(proto.TransactionBody.encode(transactionBody).finish())
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, this fixes a reported issue, so it should be committed separately and liked to it.

@franfernandez20
Copy link
Contributor

franfernandez20 commented Nov 5, 2024

Great work, @kantorcodes ! This is a fantastic improvement. The only thing I’d suggest is splitting these changes into four parts:

  • Logging System Implementation
  • Session Update Enhancements
  • Issue with transactionBodyToBase64String Resolution. (PR125)
  • Code Style Improvements

@kantorcodes
Copy link
Contributor Author

kantorcodes commented Nov 5, 2024

Thank you for your feedback.

While I generally agree that breaking this out into multiple commits would make this easier in case we must revert something, at the same time the work here provides essential fixes to make HWC more usable for important dApps in the ecosystem.

Perhaps prioritizing canary releases would be a good interim solution, as I fear the time to review four separate pull requests would slow things down immensely.

Additionally, while logging is not a required dependency here, it did make developing and debugging these improvements easier.

My proposed options in order:

A) prioritize canary NPM tags so we can allow immediate usage of these improvements to dApps

B) Push this one over in light of urgency

C) Counter recommendations for two PRs instead of four

  • remove style improvements
  • combine session improvements + logging
  • issue a revert PR on transaction bytes separately

@itsbrandondev
Copy link

@kantorcodes i really like the idea of utilizing canary releases (option A). we have to find a balance between urgent response for dApps and plenty of time for reviews and testing. option C is reasonable as well.

interested to hear thoughts from @teacoat @valeraOlexienko @jwtong

Signed-off-by: Michael Kantor <[email protected]>
Signed-off-by: Michael Kantor <[email protected]>
Signed-off-by: Michael Kantor <[email protected]>
Signed-off-by: Michael Kantor <[email protected]>
Signed-off-by: Michael Kantor <[email protected]>
Copy link

codecov bot commented Nov 5, 2024

Codecov Report

Attention: Patch coverage is 6.97674% with 40 lines in your changes missing coverage. Please review.

Please upload report for BASE (main@b3600fd). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/lib/dapp/index.ts 8.33% 33 Missing ⚠️
src/lib/dapp/DAppSigner.ts 0.00% 4 Missing ⚠️
src/lib/shared/utils.ts 0.00% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #318   +/-   ##
=======================================
  Coverage        ?   36.05%           
=======================================
  Files           ?       14           
  Lines           ?      613           
  Branches        ?       79           
=======================================
  Hits            ?      221           
  Misses          ?      392           
  Partials        ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Michael Kantor <[email protected]>
@kantorcodes
Copy link
Contributor Author

@kantorcodes i really like the idea of utilizing canary releases (option A). we have to find a balance between urgent response for dApps and plenty of time for reviews and testing. option C is reasonable as well.

interested to hear thoughts from @teacoat @valeraOlexienko @jwtong

After some discovery, we've figured out we can create canary releases now. Per the feedback, I'll be breaking off this PR into separate merges.

Signed-off-by: Michael Kantor <[email protected]>
@kantorcodes
Copy link
Contributor Author

kantorcodes commented Nov 5, 2024

We've broken this PR into three new reviews, and will be closing this one out in favor of those.

#327
#326
#325

Copy link
Contributor

@andrewb1269hg andrewb1269hg left a comment

Choose a reason for hiding this comment

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

@rbarkerSL I think these 3 files look good, but please review as well:
.github/workflows/publish-canary.yml - new file, definitely review.
package-lock.json (doesn't really need to be reviewed)
package.json

@kantorcodes kantorcodes closed this Nov 6, 2024
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.

5 participants