Skip to content
This repository has been archived by the owner on Nov 28, 2020. It is now read-only.

Feature for confirm custom transaction #306

Open
wants to merge 22 commits into
base: master
Choose a base branch
from

Conversation

Tarzeron
Copy link

No description provided.

Copy link
Member

@mvines mvines left a comment

Choose a reason for hiding this comment

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

Neat. It would be helpful to add more detail into the README about what the purpose of "confirmTransaction" is. Also it looks like it's really "sendCustomTransaction", as the functionality first sends the transaction and then confirms it.

README.md Outdated
@@ -55,7 +55,7 @@ window.addEventListener('message', (e) => {
}
});
```
4. Send an `'addFunds'` request
4. Send an `'addFunds'` or `'confirmTX'` request
Copy link
Member

Choose a reason for hiding this comment

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

confirmTransaction please.

Copy link
Author

Choose a reason for hiding this comment

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

done

README.md Outdated
walletWindow.postMessage({
method: 'confirmTX',
params: {
description: "Description of tx",
Copy link
Member

Choose a reason for hiding this comment

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

tx -> transaction

Copy link
Author

Choose a reason for hiding this comment

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

done

README.md Outdated
params: {
description: "Description of tx",
format: 'JSON',
transaction: "Your tx in JSON",
Copy link
Member

Choose a reason for hiding this comment

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

Would be nice to describe this more. Is this a JSON array of octets representing the signed wire transaction, or some other kind of JSON representation

Copy link
Author

Choose a reason for hiding this comment

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

done

src/wallet.js Outdated
@@ -151,14 +153,15 @@ class TokenInput extends React.Component {
placeholder="Enter amount to transfer"
onChange={e => this.handleChange(e.target.value)}
/>
<FormControl.Feedback />
<FormControl.Feedback/>
Copy link
Member

Choose a reason for hiding this comment

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

Can you please remove all these whitespace changes? Ie, formatting style changes can be a separate PR, much easier to review the "important" bits of this PR

Copy link
Author

Choose a reason for hiding this comment

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

done

@mvines mvines requested a review from jstarry September 10, 2019 15:57
@mvines
Copy link
Member

mvines commented Sep 10, 2019

@jstarry - hey can you please review this PR?

Copy link
Member

@jstarry jstarry left a comment

Choose a reason for hiding this comment

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

Great! Thanks for adding this functionality, super useful :D

const transaction = new web3.Transaction();
const inputs = JSON.parse(params.transaction);

inputs.map(input => {
Copy link
Member

Choose a reason for hiding this comment

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

I'm not a big fan of this approach because if we change Transaction structure, it would break. I would prefer to rely on the web3 sdk serialization methods instead for passing messages: transaction.serialize(): Buffer and Transaction.from(buffer: Buffer).

I like that you are displaying the json formatted transaction in the confirmation before sending. I think that a toJSON method would be nice to have inside Web3, thoughts?

Copy link
Author

@Tarzeron Tarzeron Sep 11, 2019

Choose a reason for hiding this comment

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

Yes, I also wanted to do this, but SDK does not serialize an unsigned transaction, can you give an example how to do it?

public serialize(): Buffersource
Serialize the Transaction in the wire format.
The Transaction must have a valid signature before invoking this method

I have error
Uncaught Error: Transaction recentBlockhash required

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Author

@Tarzeron Tarzeron Sep 11, 2019

Choose a reason for hiding this comment

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

need to fill out recentBlockhash, what if the user did not immediately confirm the transaction, it needs to be filled again on the wallet side?

Copy link
Member

Choose a reason for hiding this comment

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

Setting a placeholder is fine because the wallet will always set the recentBlockhash when signing. Something like:

transaction.recentBlockhash = new PublicKey(0).toBase58();

src/wallet.js Outdated
onSendCustomTransactionRequest(params, origin) {
if (!params.format || !params.network || !params.transaction) {
if (!params.network) this.addError(`Request did not specify a network`);
if (!params.format) this.addError(`Request did not specify a transaction format`);
Copy link
Member

Choose a reason for hiding this comment

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

Looks like you aren't checking the value of format anywhere. Let's remove it for now, and add if we introduce other formats.

Copy link
Author

Choose a reason for hiding this comment

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

done

README.md Outdated
@@ -55,7 +55,7 @@ window.addEventListener('message', (e) => {
}
});
```
4. Send an `'addFunds'` request
4. Send an `'addFunds'` or `'sendCustomTransaction'` request
Copy link
Member

Choose a reason for hiding this comment

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

We need to re-organize this README section rather than adding more things to the "Funding dApps" section. I recommend

## Wallet Setup
... steps 1 - 3

## Requesting Funds
... steps 4 - 5

## Sending Custom Transactions
... your new steps

Copy link
Author

Choose a reason for hiding this comment

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

done

@@ -321,14 +321,16 @@ export class Wallet extends React.Component {
account: null,
requestMode: false,
requesterOrigin: '*',
requestPending: false,
Copy link
Member

Choose a reason for hiding this comment

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

Why did you remove this?

Copy link
Author

Choose a reason for hiding this comment

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

The user may not close the wallet window after the last request and may simply not respond to it, but may also request a new action in the DAPP therefore. For useful, I allowed DAPP to update the request, and in the future we will need a request queue.

src/wallet.js Outdated
requestedPublicKey: '',
requestedAmount: '',
recipientPublicKey: '',
recipientAmount: '',
recipientIdentity: null,
confirmationSignature: null,
transactionConfirmed: null,
unsignedTransaction: null,
formattedUnsignedTransaction: '',
description: '',
Copy link
Member

Choose a reason for hiding this comment

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

Please namespace this: unsignedTransactionDescription is more wordy but easier to understand what it's used for

Copy link
Author

Choose a reason for hiding this comment

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

done

@@ -321,14 +321,16 @@ export class Wallet extends React.Component {
account: null,
requestMode: false,
Copy link
Member

Choose a reason for hiding this comment

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

Let's change this state flag from a boolean to an enum and rename to displayMode since we have 3 display modes now

Copy link
Author

Choose a reason for hiding this comment

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

done

src/wallet.js Outdated
description: params.description ? params.description : '',
unsignedTransaction: transaction,
formattedUnsignedTransaction: JSON.stringify(JSON.parse(params.transaction), null, 4),
requestedPublicKey: null,
Copy link
Member

Choose a reason for hiding this comment

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

please remove, we can use a different approach to distinguish between "addFunds" and "sendCustomTransaction"

Copy link
Author

Choose a reason for hiding this comment

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

done

src/wallet.js Show resolved Hide resolved
src/wallet.js Outdated
@@ -817,10 +906,46 @@ export class Wallet extends React.Component {
</Col>
</Row>
</Grid>
<div className="container">{this.renderPanels()}</div>
Copy link
Member

Choose a reason for hiding this comment

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

Please revert this change

Copy link
Author

Choose a reason for hiding this comment

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

done

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

Successfully merging this pull request may close these issues.

5 participants