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

Allow use plugin array & add plural web3js helpers #98

Conversation

mPaella
Copy link
Contributor

@mPaella mPaella commented Nov 15, 2023

  • allow plugins to be passed as an array
  • add plural web3js-adapter functions

Copy link

changeset-bot bot commented Nov 15, 2023

🦋 Changeset detected

Latest commit: b8dc9bf

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 20 packages
Name Type
@metaplex-foundation/umi-web3js-adapters Patch
@metaplex-foundation/umi Patch
@metaplex-foundation/umi-eddsa-web3js Patch
@metaplex-foundation/umi-rpc-web3js Patch
@metaplex-foundation/umi-signer-wallet-adapters Patch
@metaplex-foundation/umi-transaction-factory-web3js Patch
@metaplex-foundation/umi-uploader-bundlr Patch
@metaplex-foundation/umi-uploader-irys Patch
@metaplex-foundation/umi-bundle-defaults Patch
@metaplex-foundation/umi-bundle-tests Patch
@metaplex-foundation/umi-downloader-http Patch
@metaplex-foundation/umi-http-fetch Patch
@metaplex-foundation/umi-program-repository Patch
@metaplex-foundation/umi-rpc-chunk-get-accounts Patch
@metaplex-foundation/umi-serializer-beet Patch
@metaplex-foundation/umi-serializer-data-view Patch
@metaplex-foundation/umi-signer-derived Patch
@metaplex-foundation/umi-storage-mock Patch
@metaplex-foundation/umi-uploader-aws Patch
@metaplex-foundation/umi-uploader-nft-storage Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Comment on lines +20 to +52
fromWeb3JsPublicKeys([myWeb3JsPublicKey, myOtherWeb3JsPublicKey]);
toWeb3JsPublicKey(myUmiPublicKey);
toWeb3JsPublicKeys([myUmiPublicKey, myOtherUmiPublicKey]);

// For keypairs.
fromWeb3JsKeypair(myWeb3JsKeypair);
fromWeb3JsKeypairs([myWeb3JsKeypair, myOtherWeb3JsKeypair]);
toWeb3JsKeypair(myUmiKeypair);
toWeb3JsKeypairs([myUmiKeypair, myOtherUmiKeypair]);

// For transactions.
fromWeb3JsTransaction(myWeb3JsTransaction);
fromWeb3JsTransactions([myWeb3JsTransaction, myOtherWeb3JsTransaction]);
toWeb3JsTransaction(myUmiTransaction);
toWeb3JsTransactions([myUmiTransaction, myOtherUmiTransaction]);
fromWeb3JsLegacyTransaction(myLegacyWeb3JsTransaction);
fromWeb3JsLegacyTransactions([myLegacyWeb3JsTransaction, myOtherLegacyWeb3JsTransaction]);
toWeb3JsLegacyTransaction(myUmiTransaction);
toWeb3JsLegacyTransactions([myUmiTransaction, myOtherUmiTransaction]);

// For transaction messages.
fromWeb3JsMessage(myWeb3JsTransactionMessage);
fromWeb3JsMessages([myWeb3JsTransactionMessage, myOtherWeb3JsTransactionMessage]);
toWeb3JsMessage(myUmiTransactionMessage);
toWeb3JsMessages([myUmiTransactionMessage, myOtherUmiTransactionMessage]);
toWeb3JsMessageFromInput(myUmiTransactionInput);
toWeb3JsMessagesFromInputs([myUmiTransactionInput, myOtherUmiTransactionInput]);

// For instructions.
fromWeb3JsInstruction(myWeb3JsInstruction);
fromWeb3JsInstructions([myWeb3JsInstruction, myOtherWeb3JsInstruction]);
toWeb3JsInstruction(myUmiInstruction);
toWeb3JsInstructions([myUmiInstruction, myOtherUmiInstruction]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is kinda ugly, so happy to do in a different way if you'd like, for ex just specifying in text that these functions all have plural equivalents

@lorisleiva
Copy link
Collaborator

Hey, thanks for the PR! I'm really not a fan of the plural web3js adapters though. We're only saving the end-user to do array.map(someFunction) which I don't think requires a wrapper.

Regarding accepting an array of plugin do you have a use case for this? Because currently we encourage people to do this by creating bundles of plugins like so:

const myBundle = (): UmiPlugin => {
  install(umi: Umi) {
    umi.use(pluginA())
      .use(pluginB())
      .use(pluginC())
      .use(pluginD());
  }
}

Meaning the end-user can install all these plugins like so:

umi.use(myBundle());

Which I think is more elegant than:

umi.use([pluginA(), pluginB(), pluginC(), pluginD()]);

@mPaella
Copy link
Contributor Author

mPaella commented Nov 17, 2023

Hey, thanks for the PR! I'm really not a fan of the plural web3js adapters though. We're only saving the end-user to do array.map(someFunction) which I don't think requires a wrapper.

i think you could make the same argument in the other way as well, that since its a single line the lib should just have it, but i understand...

stretch, but would you accept this?

export function fromWeb3JsPublicKey(publicKey: Web3JsPublicKey): PublicKey;
export function fromWeb3JsPublicKey(
  ...publicKeys: Web3JsPublicKey[]
): PublicKey[];
export function fromWeb3JsPublicKey(
  ...publicKeys: Web3JsPublicKey[]
): PublicKey | PublicKey[] {
  if (publicKeys.length === 1) {
    return publicKeys[0].toBase58() as PublicKey;
  }
  return publicKeys.map((publicKey) => fromWeb3JsPublicKey(publicKey));
}

// usage
const pk1 = fromWeb3JsPublicKey(new Web3JsPublicKey('pk1'));

const [pk1, pk2] = fromWeb3JsPublicKey(
  new Web3JsPublicKey('pk1'),
  new Web3JsPublicKey('pk1')
);

@lorisleiva
Copy link
Collaborator

I'd rather leave things as-is for now. There's gonna be a few changes in that department when I update Umi to use the new Web3.js and I think this is an unnecessary refactoring at this time.

@lorisleiva lorisleiva closed this Nov 17, 2023
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.

2 participants