-
Notifications
You must be signed in to change notification settings - Fork 155
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
fix: Handle transactions after NAJ update to v4.0.x for WalletConnect #1205
Conversation
…er after NAJ update to v4.
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.
What do you think about this approach?
@@ -354,7 +354,10 @@ const WalletConnect: WalletBehaviourFactory< | |||
}, | |||
}); | |||
|
|||
return nearAPI.transactions.SignedTransaction.decode(Buffer.from(result)); | |||
// @ts-ignore |
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.
let signatureData: Uint8Array;
if (result instanceof Uint8Array) {
// This will handle both Buffer and Uint8Array since Buffer is a subclass of Uint8Array
signatureData = result;
} else if (Array.isArray(result)) {
signatureData = new Uint8Array(result);
} else if (typeof result === "object" && result !== null) {
signatureData = new Uint8Array(Object.values(result));
} else {
throw new Error("Unexpected result type from near_signTransaction");
}
return nearAPI.transactions.SignedTransaction.decode(
Buffer.from(signatureData)
);
We can make the helper method to handle the transaction and use it in the results.map
below.
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.
@pivanov Thanks for the review. I added a new helper function using the suggested code above.
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.
r+
Description
After the update of wallet selector to use NAJ
v4.0.x
the wallet-connectsignAndSendTransaction(s)
has stopped working because the type of the value oftx.encode()
has changed fromBuffer
toUint8Array
since NAJ v3 the[email protected]
update.WalletConnect uses formats and encodes the payload and this handles the
Buffer
andUint8Array
differently.This PR adds support to handle the result returned from a wallet that uses latest version of NAJ (Uint8Array) and still keeps support for the old versions (Buffer).
I have also updated the web-examples of WalletConnect to add support for the latest version(s) of NAJ:
reown-com/web-examples#702
Checklist:
Type of change.