-
Notifications
You must be signed in to change notification settings - Fork 50
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
Allow use plugin array & add plural web3js helpers #98
Conversation
mPaella
commented
Nov 15, 2023
- allow plugins to be passed as an array
- add plural web3js-adapter functions
🦋 Changeset detectedLatest commit: b8dc9bf The changes in this PR will be included in the next version bump. This PR includes changesets to release 20 packages
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 |
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]); |
There was a problem hiding this comment.
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
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 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()]); |
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')
); |
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. |