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: skip EVM signature message #443

Merged
merged 9 commits into from
Dec 15, 2024
7 changes: 7 additions & 0 deletions .changeset/swift-knives-thank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@fuel-connectors/walletconnect-connector": minor
"@e2e-tests/runner": minor
"@fuels/react": minor
---

Skip EVM signature step for previously signed accounts.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test.describe('SolanaConnector', () => {
const connectButton = getButtonByText(page, 'Connect Wallet', true);
await connectButton.click();
await getByAriaLabel(page, 'Connect to Solana Wallets', true).click();
await page.getByText('Proceed anyway').click();
await page.getByText('Proceed').click();
await getButtonByText(page, 'Phantom').click();
try {
await phantomExtended.acceptAccess();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ test.describe('WalletConnectConnector', () => {
const connectButton = getButtonByText(page, 'Connect Wallet', true);
await connectButton.click();
await getByAriaLabel(page, 'Connect to Ethereum Wallets', true).click();
await page.getByText('Proceed anyway').click();
await page.getByText('Proceed').click();
await getButtonByText(page, 'MetaMask', true).click();
await metamask.connectToDapp();
await page.waitForTimeout(4000);
Expand Down
7 changes: 1 addition & 6 deletions e2e-tests/runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,5 @@
"dotenv": "16.4.5",
"@phantom/synpress": "4.0.0-alpha.53",
"fuels": "0.96.1"
},
"engines": {
"node": ">=20.11.0",
"pnpm": "9.x"
},
"packageManager": "[email protected]"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"vitest": "2.0.2"
},
"engines": {
"node": ">=20.11.0",
"node": "20.x",
"pnpm": "9.x"
},
"pnpm": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export function ExternalDisclaimer() {
</DisclaimerList>
</DisclaimerContainer>
<ConnectorButtonPrimary onClick={() => _startConnection(connector)}>
Proceed anyway
Proceed
</ConnectorButtonPrimary>
<ConnectorButton onClick={() => back()}>
Select a Native Wallet
Expand Down
12 changes: 8 additions & 4 deletions packages/walletconnect-connector/src/WalletConnectConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
} from '@fuel-connectors/common';
import { PREDICATE_VERSIONS } from '@fuel-connectors/evm-predicates';
import { ApiController } from '@web3modal/core';
import { stringToHex } from 'viem';
import {
ETHEREUM_ICON,
HAS_WINDOW,
Expand Down Expand Up @@ -330,7 +331,10 @@ export class WalletConnectConnector extends PredicateConnector {

async requestValidation(address?: string) {
return new Promise(async (resolve, reject) => {
// Disconnect if user dosen't provide signature in time
const hasSignature = await this.accountHasValidation(address);
if (hasSignature) return resolve(true);

// Disconnect if user doesn't provide signature in time
const validationTimeout = setTimeout(() => {
reject(
new Error("User didn't provide signature in less than 1 minute"),
Expand Down Expand Up @@ -358,11 +362,11 @@ export class WalletConnectConnector extends PredicateConnector {
const wagmiConfig = this.getWagmiConfig();
if (!wagmiConfig) throw new Error('Wagmi config not found');

const { addresses, connector, isConnected } = getAccount(wagmiConfig);
const { connector, isConnected } = getAccount(wagmiConfig);
await disconnect(wagmiConfig, {
connector,
});
addresses?.map((a) => this.storage.removeItem(`SIGNATURE_VALIDATION_${a}`));

return isConnected || false;
}

Expand Down Expand Up @@ -440,7 +444,7 @@ export class WalletConnectConnector extends PredicateConnector {
const message = `Sign this message to verify the connected account: ${currentAccount}`;
const signature = (await ethProvider.request({
method: 'personal_sign',
params: [message, currentAccount],
params: [stringToHex(message), currentAccount],
})) as string;

if (!this.validateSignature(currentAccount, message, signature)) {
Expand Down
Loading