forked from avral/golos-ui
-
Notifications
You must be signed in to change notification settings - Fork 8
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 #430 from golos-blockchain/beta
Beta
- Loading branch information
Showing
70 changed files
with
2,448 additions
and
1,436 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
|
@@ -47,4 +47,9 @@ | |
bottom: 100%; | ||
top: auto; | ||
} | ||
|
||
&.top-most > .VerticalMenu { | ||
position: fixed; | ||
top: auto; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -9,4 +9,8 @@ | |
padding-top: 0.5rem; | ||
padding-bottom: 0.5rem; | ||
width: 50%; | ||
|
||
&.disabled { | ||
cursor: auto; | ||
} | ||
} |
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,75 @@ | ||
import React from 'react' | ||
import tt from 'counterpart' | ||
|
||
import { apidexGetPrices } from 'app/utils/ApidexApiClient' | ||
|
||
class CMCValue extends React.Component { | ||
state = {} | ||
|
||
componentDidMount() { | ||
this.updateCMCPrice(this.props.buyAmount) | ||
} | ||
|
||
componentDidUpdate(prevProps) { | ||
const { buyAmount } = this.props | ||
if (buyAmount && (!prevProps.buyAmount || | ||
buyAmount.ne(prevProps.buyAmount) || | ||
buyAmount.symbol !== prevProps.buyAmount.symbol)) { | ||
this.updateCMCPrice(buyAmount) | ||
} | ||
} | ||
|
||
updateCMCPrice = async (buyAmount) => { | ||
if (!buyAmount) { | ||
return | ||
} | ||
const { price_usd, price_rub, page_url } = await apidexGetPrices(buyAmount.symbol) | ||
const calc = (price) => { | ||
if (price === null || price === undefined) return null | ||
return parseFloat(buyAmount.amountFloat) * price | ||
} | ||
const cmcPrice = { | ||
price_usd: calc(price_usd), | ||
price_rub: calc(price_rub), | ||
page_url | ||
} | ||
this.setState({ | ||
cmcPrice | ||
}) | ||
} | ||
|
||
render() { | ||
const { renderer, compact } = this.props | ||
let cmc = null | ||
const { cmcPrice } = this.state | ||
if (cmcPrice) { | ||
const formatVal = (val, fmt) => { | ||
if (val && val.toFixed) { | ||
if (val > 1000000) return fmt((val / 1000000).toFixed(3) + 'M') | ||
if (compact && val > 100) return fmt(Math.round(val)) | ||
return fmt(val.toFixed(2)) | ||
} | ||
return null | ||
} | ||
let mainVal, altVal | ||
const price_usd = formatVal(cmcPrice.price_usd, v => `$${v}`) | ||
const price_rub = formatVal(cmcPrice.price_rub, v => `${v} RUB`) | ||
if (tt.getLocale() === 'ru') { | ||
mainVal = price_rub || price_usd | ||
altVal = price_usd || price_rub | ||
} else { | ||
mainVal = price_usd || price_rub | ||
altVal = price_rub || price_usd | ||
} | ||
if (mainVal) { | ||
cmc = <b title={'~' + altVal}>{'~' + mainVal}</b> | ||
if (cmcPrice.page_url) { | ||
cmc = <a href={cmcPrice.page_url} target='_blank' rel='noopener noreferrer'>{cmc}</a> | ||
} | ||
} | ||
} | ||
return (cmc && renderer) ? renderer(cmc) : cmc | ||
} | ||
} | ||
|
||
export default CMCValue |
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,87 @@ | ||
import React from 'react' | ||
|
||
import Icon from 'app/components/elements/Icon' | ||
import LoadingIndicator from 'app/components/elements/LoadingIndicator' | ||
|
||
|
||
import { apidexGetPrices } from 'app/utils/ApidexApiClient' | ||
|
||
class CMCWidget extends React.Component { | ||
state = { | ||
loaded: false | ||
} | ||
|
||
getPriceChange = (res) => { | ||
let price_change = null | ||
try { | ||
price_change = res.data.quote.RUB.percent_change_24h | ||
} catch (err) {} | ||
if (price_change) { | ||
price_change = parseFloat(price_change) | ||
if (isNaN(price_change)) { | ||
price_change = null | ||
} | ||
} | ||
return price_change | ||
} | ||
|
||
async componentDidMount() { | ||
let res = await apidexGetPrices('GOLOS') | ||
if (res.price_rub) { | ||
const price_change = this.getPriceChange(res) | ||
this.setState({ | ||
loaded: true, | ||
price_usd: res.price_usd, | ||
price_rub: res.price_rub, | ||
page_url: res.page_url, | ||
price_change, | ||
}) | ||
} else { | ||
this.setState({ | ||
failed: true | ||
}) | ||
} | ||
} | ||
|
||
render() { | ||
const { loaded, failed, price_usd, price_rub, page_url, price_change } = this.state | ||
if (!loaded) { | ||
return (<div class="CMCWidget"> | ||
<div className="CMCWidget__inner"> | ||
<div className='CMCWidget__inner2' style={{ 'justify-content': 'center' }} > | ||
{!failed ? | ||
<LoadingIndicator type='circle' size='25px' /> : | ||
null} | ||
</div> | ||
</div> | ||
</div>) | ||
} | ||
return (<div class="CMCWidget"> | ||
<div className="CMCWidget__inner"> | ||
<div className='CMCWidget__inner2'> | ||
<div className="CMCWidget__icon-parent"> | ||
<Icon name='golos' size='2x' /> | ||
</div> | ||
<div className="CMCWidget__main-parent"> | ||
<span style={{ fontSize: '18px' }}> | ||
<a href={page_url} target="_blank" className="CMCWidget__link">Golos Blockchain </a> | ||
</span><br/> | ||
<span style={{ fontSize: '16px' }}> | ||
<span className="CMCWidget__main-val">{price_rub ? price_rub.toFixed(6) : null}</span> | ||
<span className="CMCWidget__main-cur"> RUB</span> | ||
<span className="CMCWidget__sub-parent"> | ||
{(price_change && price_change.toFixed) ? <span style={{ color: price_change < 0 ? '#d94040' : '#009600' }}> | ||
<br />({price_change.toFixed(2)}%) | ||
</span> : null} | ||
<br /> | ||
<span className="CMCWidget__sub">{price_usd ? price_usd.toFixed(6) + ' USD' : null}</span> | ||
</span> | ||
</span> | ||
</div> | ||
</div> | ||
</div> | ||
</div>) | ||
} | ||
} | ||
|
||
export default CMCWidget |
Oops, something went wrong.