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

fund account via ShapeShift #2099

Merged
merged 37 commits into from
Sep 15, 2016
Merged

fund account via ShapeShift #2099

merged 37 commits into from
Sep 15, 2016

Conversation

jacogr
Copy link
Contributor

@jacogr jacogr commented Sep 15, 2016

implements the outstanding Fund Account functionality. Demo of the functionality -

https://youtu.be/1i37yMa3NCc (EDIT: Updated the UI slightly so we don't need to come back to it immediately - https://youtu.be/BIS47mYRxlk)

Requires/includes https://github.com/ethcore/parity/pull/2088 which have been extended slightly to have event subscribe functionality as we have in the other APIs. (Contract, Core)

Future work: (EDIT: addressed in the last commit, updated video added above)

UI could be prettier & much more graphical and snazzy :(
there is an initial delay on clicking shift which is not a perfect UX (some initial busy feedback would be good)

@jacogr jacogr added A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. M-UI labels Sep 15, 2016
@parity-cla-bot
Copy link

It looks like @jacogr signed our Contributor License Agreement. 👍

Many thanks,

Ethcore CLA Bot

@jacogr jacogr added A0-pleasereview 🤓 Pull request needs code review. and removed A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. labels Sep 15, 2016
Copy link
Contributor

@derhuerst derhuerst left a comment

Choose a reason for hiding this comment

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

Tiny remarks:

  • the modal window is not scrollable on small screens
  • at the 2. step, the code should ideally be easily copied to clipboard
  • for the "fund account" button that opens the modal, i'd like to have a different icon, e.g. https://design.google.com/icons/#ic_attach_money

return (
<div className={ styles.center }>
<div className={ styles.info }>
<a href='https://shapeshift.io' target='_blank'>ShapeShift.io</a> is awaiting a { typeSymbol } deposit. Send the funds from you { typeSymbol } network client to -
Copy link
Contributor

Choose a reason for hiding this comment

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

typo. it should be "fund from your … network".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ty, will address.

@jacogr
Copy link
Contributor Author

jacogr commented Sep 15, 2016

Valid, not going to be fixed in this PR, but logging them:

  • Yeap, none of the modals are currently scrollable. Should be fixed in ui/Modal.
  • We have a react-copy-to-clipboard in there, I guess it is actually wider than that - we also have the account phrase we should be copy-able. Should actually go through all do all of them in the same place.

Valid, will fix:

think a different icon is in order, in this case though it is not real money and we should rather use a money symbol for when we have real $ -> ETH integration (Mist added something like that in the last release via Coinbase). Any other ideas of icons in this case? @derhuerst @ngotchac ?

[EDIT: just going to use their btn icon & name, self-explanatory]

<Value amount={ incomingCoin } symbol={ incomingType } /> => <Value amount={ outgoingCoin } symbol={ outgoingType } />
</div>
<div className={ styles.info }>
The funds will reflect in your Parity account shortly.
Copy link
Contributor

Choose a reason for hiding this comment

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

typo? Should be "The change in funds will be reflected ..."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will do.

function call (method, options) {
return fetch(`${ENDPOINT}/${method}`, options)
.then((response) => {
if (response.status !== 200) {
Copy link
Contributor

@derhuerst derhuerst Sep 15, 2016

Choose a reason for hiding this comment

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

I think checking for 200 <= status && status < 300 is safer, as the HTTP RFC defines 2xx as "client's request was successfully received, understood, and accepted.".

Edit: Check for response.ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

response.ok :)

return fetch(`${ENDPOINT}/${method}`, options)
.then((response) => {
if (response.status !== 200) {
throw { code: response.status, message: response.statusText }; // eslint-disable-line
Copy link
Contributor

Choose a reason for hiding this comment

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

As people often check for err instanceof Error, i'd consider using new Error(…) here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. Actually needs to be done to align with the other APIs as well.

return;

case 'failed':
subscription.callback({
Copy link
Contributor

Choose a reason for hiding this comment

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

As above – using new Error(…) might be useful, because people tend to do err instanceof Error or err.toString().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only issue here is that there are 2 types of errors - recoverable and non-recoverable. The fatal flag indicates that. So not 100% sure how to handle that.

}

function _pollStatus () {
subscriptions.map(_getSubscriptionStatus);
Copy link
Contributor

Choose a reason for hiding this comment

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

should be .forEach.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, fixed.

</div>
);
}
return (
Copy link
Contributor

Choose a reason for hiding this comment

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

In AwaitingDepositStep, AwaitingExchangeStep, CompletedStep, ErrorStep and OptionsStep, there's a lot of duplicate/boilerplatisch code. It's a lot of stuff to read through for not soo much complexity being handled; Maybe we can rduce that a little. :)

Also, but this is a matter of taste, having separate directories for these steps is bloat.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Each component in their own directory. We've been following that through the whole codebase.


return (
<div className={ styles.body }>
<span>{ value }</span><small>{ symbol || 'ΞTH' }</small>
Copy link
Contributor

Choose a reason for hiding this comment

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

<span> is an inline element. As of HTML5, <small> has a semantical meaning and should not be used for stylistic purposes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should fix it in a fixes PR - I actually think I started adopting that after seeing it in the Signer. Agreed in principle though, but needs to be done properly. (May be worth it to pull in this component there then and whereever we do this type of thing)

}

state = {
stage: 0,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think strings as values of stage would be both more robust & easier to reason about.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think in this case yes, since there is not a lot of jumping. Just keeping it consistent though.

return {};
}

function mapDispatchToProps (dispatch) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think using Redux just for this isn't worth it, given that Redux adds complexity and makes it harder to follow the flow of data. I'd either go all in and move this component's state to Redux, or remove it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Bringing this whole Shapeshift logic to Redux totally makes sense to me, as it is easily testable, (in doubt) more robust and modelled independently from the UI.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Redux state is just there for the newError action. There is no internal state in the Redux store.

Copy link
Contributor

Choose a reason for hiding this comment

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

Exactly, I consider this as "not worth" the Redux complexity. I propose to pull the stuff that is in state right now into Redux.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If this was a component like a dapp, self-contained, yes. I honestly don't want to be coding for the next 2 days just to do that complexity and conversion where the state is only applicable to the single component.

So no, I'd rather get features out than coding for the sake of coding where in the end I won't be able to follow the actual code. I think Redux is great where I need global state, don't need it here. (newError is global)

Copy link
Contributor

Choose a reason for hiding this comment

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

If this was a component like a dapp, self-contained, yes. I honestly don't want to be coding for the next 2 days just to do that complexity and conversion where the state is only applicable to the single component.

So no, I'd rather get features out than coding for the sake of coding where in the end I won't be able to follow the actual code. I think Redux is great where I need global state, don't need it here. (newError is global)

Fair enough.

Often state is more global than one immeadiatly thinks. There's more parts of the app that should pay attention to each other than we lazy developers like to think of.

const { iconsrc } = this.state;
const size = inline ? '32px' : '56px';
const classes = `${styles.icon} ${center ? styles.center : styles.left} ${padded ? styles.padded : ''} ${inline ? styles.inline : ''} ${className}`;
const classes = `${styles.icon} ${center ? styles.center : styles.left} ${padded ? styles.padded : ''} ${inline ? styles.inline : ''} ${button ? styles.button : ''} ${className}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Use an array? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Like that, should have done it from the start - but kept adding more and more cruft. Will fix.

@@ -23,3 +23,7 @@
margin: 0;
text-transform: uppercase;
}

.waiting {
margin: 0 -1em 0 -1em;
Copy link
Contributor

Choose a reason for hiding this comment

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

That is not very modular (;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not 100% with you here.

@derhuerst
Copy link
Contributor

Sry for the requested & approved changes spam, i'm still figuring out how to use this. 😄

@derhuerst derhuerst added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Sep 15, 2016
@ngotchac ngotchac merged commit 7921fa8 into js Sep 15, 2016
@ngotchac ngotchac deleted the jg-fund-account branch September 15, 2016 18:13
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A8-looksgood 🦄 Pull request is reviewed well.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants