This repository has been archived by the owner on Jul 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 465
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1131 from 0xProject/feature/instant/move-features…
…-over-from-zrx-buyer [instant][types][order-utils][asset-buyer] Move over and clean up features from zrx-buyer
- Loading branch information
Showing
39 changed files
with
793 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { AssetProxyId } from '@0xproject/types'; | ||
import { BigNumber } from '@0xproject/utils'; | ||
import * as _ from 'lodash'; | ||
import * as React from 'react'; | ||
|
||
import { assetMetaData } from '../data/asset_meta_data'; | ||
import { ColorOption } from '../style/theme'; | ||
import { util } from '../util/util'; | ||
|
||
import { AmountInput, AmountInputProps } from './amount_input'; | ||
import { Container, Text } from './ui'; | ||
|
||
export interface AssetAmountInputProps extends AmountInputProps { | ||
assetData?: string; | ||
onChange: (value?: BigNumber, assetData?: string) => void; | ||
} | ||
|
||
export class AssetAmountInput extends React.Component<AssetAmountInputProps> { | ||
public static defaultProps = { | ||
onChange: util.boundNoop, | ||
}; | ||
public render(): React.ReactNode { | ||
const { assetData, onChange, ...rest } = this.props; | ||
return ( | ||
<Container> | ||
<AmountInput {...rest} onChange={this._handleChange} /> | ||
<Container display="inline-block" marginLeft="10px"> | ||
<Text fontSize={rest.fontSize} fontColor={ColorOption.white} textTransform="uppercase"> | ||
{this._getAssetSymbolLabel()} | ||
</Text> | ||
</Container> | ||
</Container> | ||
); | ||
} | ||
private readonly _getAssetSymbolLabel = (): string => { | ||
const unknownLabel = '???'; | ||
if (_.isUndefined(this.props.assetData)) { | ||
return unknownLabel; | ||
} | ||
const metaData = assetMetaData[this.props.assetData]; | ||
if (_.isUndefined(metaData)) { | ||
return unknownLabel; | ||
} | ||
if (metaData.assetProxyId === AssetProxyId.ERC20) { | ||
return metaData.symbol; | ||
} | ||
return unknownLabel; | ||
}; | ||
private readonly _handleChange = (value?: BigNumber): void => { | ||
this.props.onChange(value, this.props.assetData); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,53 @@ | ||
import { BuyQuote } from '@0xproject/asset-buyer'; | ||
import * as _ from 'lodash'; | ||
import * as React from 'react'; | ||
|
||
import { ColorOption } from '../style/theme'; | ||
import { assetBuyer } from '../util/asset_buyer'; | ||
import { util } from '../util/util'; | ||
import { web3Wrapper } from '../util/web3_wrapper'; | ||
|
||
import { Button, Container, Text } from './ui'; | ||
|
||
export interface BuyButtonProps {} | ||
export interface BuyButtonProps { | ||
buyQuote?: BuyQuote; | ||
onClick: (buyQuote: BuyQuote) => void; | ||
onBuySuccess: (buyQuote: BuyQuote, txnHash: string) => void; | ||
onBuyFailure: (buyQuote: BuyQuote, tnxHash?: string) => void; | ||
text: string; | ||
} | ||
|
||
export const BuyButton: React.StatelessComponent<BuyButtonProps> = props => ( | ||
<Container padding="20px" width="100%"> | ||
<Button width="100%"> | ||
<Text fontColor={ColorOption.white} fontWeight={600} fontSize="20px"> | ||
Buy | ||
</Text> | ||
</Button> | ||
</Container> | ||
); | ||
|
||
BuyButton.displayName = 'BuyButton'; | ||
export class BuyButton extends React.Component<BuyButtonProps> { | ||
public static defaultProps = { | ||
onClick: util.boundNoop, | ||
onBuySuccess: util.boundNoop, | ||
onBuyFailure: util.boundNoop, | ||
}; | ||
public render(): React.ReactNode { | ||
const shouldDisableButton = _.isUndefined(this.props.buyQuote); | ||
return ( | ||
<Container padding="20px" width="100%"> | ||
<Button width="100%" onClick={this._handleClick} isDisabled={shouldDisableButton}> | ||
<Text fontColor={ColorOption.white} fontWeight={600} fontSize="20px"> | ||
{this.props.text} | ||
</Text> | ||
</Button> | ||
</Container> | ||
); | ||
} | ||
private readonly _handleClick = async () => { | ||
// The button is disabled when there is no buy quote anyway. | ||
if (_.isUndefined(this.props.buyQuote)) { | ||
return; | ||
} | ||
this.props.onClick(this.props.buyQuote); | ||
let txnHash; | ||
try { | ||
txnHash = await assetBuyer.executeBuyQuoteAsync(this.props.buyQuote); | ||
await web3Wrapper.awaitTransactionSuccessAsync(txnHash); | ||
this.props.onBuySuccess(this.props.buyQuote, txnHash); | ||
} catch { | ||
this.props.onBuyFailure(this.props.buyQuote, txnHash); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.