feat(core): wallet provider updates #183
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR makes multiple changes to all wallet providers in the core library. It represents many of the "must-haves" remaining before the 3.0.0 stable release. Several of these improvements/fixes depend on each other, which is why they appear in a single pull request:
returnGroup
, closes Remove thereturnGroup
argument and logic fromsignTransactions
#160signTransactions
, closes re-initialize active wallet client following hot module reload #173transactionSigner
signTransactions
only assert what gets passed to the wallet is correctRemoves
returnGroup
Here is the new
signTransactions
type signature:Now
signTransactions
will ONLY return an array of signed transactions, instead of re-assembling and returning the original group by default.MyAlgo Wallet's original implementation did not support signing with multiple connected accounts. The
returnGroup
logic facilitated a workaround where the group could be re-submitted to MyAlgo for each signer separately. It remained after MyAlgo was sunsetted because its removal is a breaking change.Re-initialize client in
signTransactions
Instead of throwing an error if the client is not initialized, the client is re-initialized. See #173
Removes duplicated logic in
transactionSigner
methodHere's what the entire method now looks like in every wallet (except Custom and Mnemonic):
The
transactionSigner
method now simply callssignTransactions
directly, so processing and signing logic doesn't need to be repeated. A single test has been added to each wallet that verifiessignTransactions
is called with the same arguments passed to it.Refactors transaction processing
Processing for each transaction type (
Transaction[]
orUint8Array[]
) has been refactored into separate private methods:processTxns
andprocessEncodedTxns
, respectively.Transaction
types no longer need to be converted to byte arrays and then back again before being submitted for signatureErrors are always thrown
connect
anddisconnect
methods.All public methods will throw their errors to the consuming application.
connect
method previously logged errors but returned a promise that resolved to an empty array. Now the promise is rejected with the error.disconnect
orresumeSession
methods contained any async function calls, errors would be caught and logged but the promise would resolve. Now errors are always thrown, rejecting the promise.Tests for
signTransactions
only check what gets passed to the walletAll the library is responsible for is processing and normalizing what is passed to the wallet to be signed. The tests were previously mocking responses from the wallet and then verifying those responses were correct. (Hint: of course they are, they're being mocked!)
Now, given particular values for
txnGroup
andindexesToSign
, the tests only assert that the array of formatted transactions sent to the wallet are correct.SVG icons
Several of the wallet icons contained extraneous SVG/XML markup that is auto-generated by tools such as Adobe Illustrator. When they are base64 encoded as strings, the resulting strings are significantly larger than they need to be.
I decoded each icon and made it as small as possible, only containing markup that is required. Then, rather than showing the encoded base64 string, the SVG markup itself is displayed inside a
btoa
function, so you can actually see what's there.Mnemonic provider
These improvements probably could have been made in a separate PR, actually. While making the other changes to the Mnemonic provider, I also addressed some
@todo:
comments I left for myself:persistToStorage
option, so private key mnemonics wouldn't need to be entered into a prompt each timedisconnect
will abort if the active network detected isNetworkId.MAINNET
Other changes
disconnect
method before any async actions (for snappier UX)`[${this.metadata.name}]...`
vs hard-coded'[ProviderName]...'