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

PE-6052 -- feat(web): implement walletAdapter for SOL and ETH web signing support #188

Merged
merged 7 commits into from
Oct 2, 2024

Conversation

fedellen
Copy link
Collaborator

@fedellen fedellen commented Sep 30, 2024

this PR implements ETH and SOL web signing for upload and crypto fund flows

@fedellen fedellen self-assigned this Sep 30, 2024
Copy link

codecov bot commented Sep 30, 2024

Codecov Report

Attention: Patch coverage is 95.22059% with 13 lines in your changes missing coverage. Please review.

Project coverage is 93.34%. Comparing base (df8a629) to head (d8b51bb).
Report is 12 commits behind head on alpha.

Files with missing lines Patch % Lines
src/common/signer.ts 60.00% 10 Missing ⚠️
src/web/signer.ts 50.00% 2 Missing ⚠️
src/common/factory.ts 99.27% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            alpha     #188      +/-   ##
==========================================
+ Coverage   93.31%   93.34%   +0.02%     
==========================================
  Files          25       25              
  Lines        3097     3245     +148     
  Branches      144      147       +3     
==========================================
+ Hits         2890     3029     +139     
- Misses        207      216       +9     

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

Comment on lines +104 to +118
protected getAuthenticatedTurbo({
privateKey,
signer: providedSigner,
paymentServiceConfig = {},
uploadServiceConfig = {},
token,
gatewayUrl,
tokenMap,
tokenTools,
logger,
walletAdapter,
}: TurboAuthenticatedConfiguration & { logger: TurboWinstonLogger }) {
token = token === 'pol' ? 'matic' : token;

if (!token) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this common level factory de-duplicates the code from the node and web factories. we defer to the child classes for importing node and web specific uploaders and signers via abstract methods to keep the imports clean

Comment on lines +133 to +151
if (this.walletAdapter) {
if (!isEthereumWalletAdapter(this.walletAdapter)) {
throw new Error(
'Unsupported wallet adapter -- must implement getSigner',
);
}
const signer = this.walletAdapter.getSigner();
if (signer.sendTransaction === undefined) {
throw new Error(
'Unsupported wallet adapter -- getSigner must return a signer with sendTransaction API for crypto funds transfer',
);
}

const { hash } = await signer.sendTransaction({
to: target,
value: parseEther(amount.toFixed(18)),
});
return hash;
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

here we defer to ethereum wallet adapter when available which allows web wallets to use the crypto-fund flow

@fedellen fedellen marked this pull request as ready for review September 30, 2024 16:45
@fedellen fedellen requested a review from a team as a code owner September 30, 2024 16:45
Comment on lines 65 to +67
token = token === 'pol' ? 'matic' : token;

token ??= 'arweave'; // default to arweave if token is not provided
Copy link
Collaborator

Choose a reason for hiding this comment

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

could this be:

Suggested change
token = token === 'pol' ? 'matic' : token;
token ??= 'arweave'; // default to arweave if token is not provided
token = token === 'pol' ? 'matic' : token ??= 'arweave'; // default to arweave if token is not provided

more so curious, not necessary to change

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it works with parenthesis around (token ??= 'arweave'), but doesn't appear to provide type safety on token being defined

Copy link
Collaborator Author

@fedellen fedellen Oct 2, 2024

Choose a reason for hiding this comment

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

the pol=>matic convenience part I think could be expanded to include an "acceptableTokenStringMap" that converts the tickers as well like

sol => solana
eth => ethereum
ar => arweave

it would be a littel easier to use the token input parameter on the sdk, but no need for yet

@fedellen fedellen merged commit bb280ac into alpha Oct 2, 2024
9 checks passed
@fedellen fedellen deleted the PE-6052-SOL-ETH-web-signing branch October 2, 2024 15:53
@dtfiedler
Copy link
Collaborator

🎉 This PR is included in version 1.19.0-alpha.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@dtfiedler
Copy link
Collaborator

🎉 This PR is included in version 1.19.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

3 participants