Skip to content

Commit

Permalink
Reduce Shapeshift Requests (#1463)
Browse files Browse the repository at this point in the history
* Use market info instead of fetching each and every pair.

* Make loaders the size of the content.
  • Loading branch information
wbobeirne authored and dternyak committed Apr 6, 2018
1 parent 8fb0e03 commit ad838f6
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 22 deletions.
18 changes: 3 additions & 15 deletions common/api/shapeshift.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,26 +118,20 @@ class ShapeshiftService {

public getAllRates = async () => {
const marketInfo = await this.getMarketInfo();
const pairRates = await this.getPairRates(marketInfo);
const pairRates = await this.filterPairs(marketInfo);
const checkAvl = await this.checkAvl(pairRates);
const mappedRates = this.mapMarketInfo(checkAvl);
return mappedRates;
};

private getPairRates(marketInfo: ShapeshiftMarketInfo[]) {
const filteredMarketInfo = marketInfo.filter(obj => {
private filterPairs(marketInfo: ShapeshiftMarketInfo[]) {
return marketInfo.filter(obj => {
const { pair } = obj;
const pairArr = pair.split('_');
return this.whitelist.includes(pairArr[0]) && this.whitelist.includes(pairArr[1])
? true
: false;
});
const pairRates = filteredMarketInfo.map(p => {
const { pair } = p;
const singlePair = Promise.resolve(this.getSinglePairRate(pair));
return { ...p, ...singlePair };
});
return pairRates;
}

private async checkAvl(pairRates: IPairData[]) {
Expand Down Expand Up @@ -174,12 +168,6 @@ class ShapeshiftService {
.then(parseJSON);
}

private getSinglePairRate(pair: string) {
return fetch(`${this.url}/rate/${pair}`)
.then(checkHttpStatus)
.then(parseJSON);
}

private getMarketInfo() {
return fetch(`${this.url}/marketinfo`)
.then(checkHttpStatus)
Expand Down
7 changes: 7 additions & 0 deletions common/containers/Tabs/Swap/components/CurrencySwap.scss
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,11 @@
&-submit {
margin-top: 0.5rem;
}

&-loader {
display: flex;
align-items: center;
justify-content: center;
height: 175px;
}
}
4 changes: 3 additions & 1 deletion common/containers/Tabs/Swap/components/CurrencySwap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,9 @@ export default class CurrencySwap extends PureComponent<Props, State> {
</div>
</React.Fragment>
) : (
<Spinner />
<div className="CurrencySwap-loader">
<Spinner size="x3" />
</div>
)}
</article>
);
Expand Down
8 changes: 8 additions & 0 deletions common/containers/Tabs/Swap/components/CurrentRates.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
&-rate {
color: #fff;

&.is-loading {
display: flex;
align-items: center;
align-self: center;
justify-content: center;
height: 50px;
}

&-input {
display: inline-block;
width: 16%;
Expand Down
12 changes: 6 additions & 6 deletions common/containers/Tabs/Swap/components/CurrentRates.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,25 +152,25 @@ class CurrentRates extends PureComponent<Props> {
} else {
// TODO - de-dup
children = (
<>
<React.Fragment>
<div className="SwapRates-panel-side col-sm-6">
<div className="SwapRates-panel-rate">
<div className="SwapRates-panel-rate is-loading">
<Spinner size="x1" light={true} />
</div>
<div className="SwapRates-panel-rate">
<div className="SwapRates-panel-rate is-loading">
<Spinner size="x1" light={true} />
</div>
</div>

<div className="SwapRates-panel-side col-sm-6">
<div className="SwapRates-panel-rate">
<div className="SwapRates-panel-rate is-loading">
<Spinner size="x1" light={true} />
</div>
<div className="SwapRates-panel-rate">
<div className="SwapRates-panel-rate is-loading">
<Spinner size="x1" light={true} />
</div>
</div>
</>
</React.Fragment>
);
}

Expand Down

0 comments on commit ad838f6

Please sign in to comment.