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

feat: walletconnect #529

Closed
wants to merge 39 commits into from

Conversation

GMSteuart
Copy link

Adds a package for integrating WalletConnect

Closes #499

@vercel
Copy link

vercel bot commented May 10, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
hdwallet ❌ Failed (Inspect) Jun 21, 2022 at 9:12PM (UTC)

packages/hdwallet-core/tsconfig.build.json Outdated Show resolved Hide resolved
data: msg.data,
chainId: msg.chainId,
nonce: msg.nonce,
// MetaMask, like other Web3 libraries, derives its transaction schema from Ethereum's official JSON-RPC API specification
Copy link
Collaborator

Choose a reason for hiding this comment

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

If this comment is relevant to WalletConnect as well, update the text to match:

Suggested change
// MetaMask, like other Web3 libraries, derives its transaction schema from Ethereum's official JSON-RPC API specification
// WalletConnect, like other Web3 libraries, derives its transaction schema from Ethereum's official JSON-RPC API specification

Copy link
Author

Choose a reason for hiding this comment

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

Pretty sure my entire ethereum.ts can be removed

packages/hdwallet-walletconnect/src/walletconnect.ts Outdated Show resolved Hide resolved
packages/hdwallet-walletconnect/src/walletconnect.ts Outdated Show resolved Hide resolved
connected = false;
chainId: number = -1;
accounts: string[] = [];
// TODO: confirm empty string doesn't break
Copy link
Collaborator

Choose a reason for hiding this comment

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

Test this and remove comment

packages/hdwallet-walletconnect/src/walletconnect.ts Outdated Show resolved Hide resolved
packages/hdwallet-walletconnect/src/walletconnect.ts Outdated Show resolved Hide resolved
packages/hdwallet-walletconnect/src/walletconnect.ts Outdated Show resolved Hide resolved
packages/hdwallet-walletconnect/src/walletconnect.ts Outdated Show resolved Hide resolved
packages/hdwallet-walletconnect/src/walletconnect.ts Outdated Show resolved Hide resolved
}

public async ethGetAddress(): Promise<string | null> {
return this.ethAddress;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return this.ethAddress;
if (!this.ethAddress) {
if (!this.connected) {
console.error("WalletConnect provider not connected.");
return null;
}
const { accounts } = this.provider.connector;
const [address] = accounts;
this.ethAddress = address;
}
return this.ethAddress;

Copy link
Author

Choose a reason for hiding this comment

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

Is the setting of ethAddress inside of it's "getter" an anti-pattern?

Comment on lines 107 to 111
provider: WalletConnectProvider;
connected = false;
chainId: number = -1;
accounts: string[] = [];
ethAddress: string = "";
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm thinking maybe it might be an improvement to make these fields private. Is there any reason not to?

Copy link
Author

@GMSteuart GMSteuart May 19, 2022

Choose a reason for hiding this comment

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

If you're only talking about the three (chainId, accounts, connected) that I added, then yes, I could see it as an improvement.

* @see https://docs.walletconnect.com/client-api#sign-transaction-eth_signtransaction
*/
public async ethSignTx(msg: core.ETHSignTx & { from: string }): Promise<core.ETHSignedTx | null> {
msg.from = this.ethAddress;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This works but sort of breaks the pattern established in the other wallet adapters. Only for consistency, I think we should keep these functions as wrappers and move the logic down into ethereum.ts, passing whatever state is necessary into those functions. The same goes for ethSendTx(), ethSignMessage() and ethVerifyMessage().

packages/hdwallet-walletconnect/src/walletconnect.test.ts Outdated Show resolved Hide resolved
@0xdef1cafe
Copy link
Collaborator

closing in favor of #544

@0xdef1cafe 0xdef1cafe closed this Jun 27, 2022
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.

implement WalletConnect (v1) as a dapp option into hdwallet
3 participants