Skip to content

Commit

Permalink
REF: INR rate source
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosrdz authored and Overtorment committed Oct 15, 2021
1 parent 0bca454 commit 821117a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@
ReferencedContainer = "container:BlueWallet.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<EnvironmentVariables>
<EnvironmentVariable
key = "_XCWidgetKind"
value = "PriceWidget"
isEnabled = "YES">
</EnvironmentVariable>
</EnvironmentVariables>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
9 changes: 9 additions & 0 deletions ios/Widgets/Shared/WidgetAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class WidgetAPI {
urlString = "https://bitcoinduliban.org/api.php?key=lbpusd"
case "Exir":
urlString = "https://api.exir.io/v1/ticker?symbol=btc-irt"
case "wazirx":
urlString = "https://api.wazirx.com/api/v2/tickers/btcinr"
default:
urlString = "https://api.coindesk.com/v1/bpi/currentprice/\(endPointKey).json"
}
Expand Down Expand Up @@ -69,6 +71,13 @@ class WidgetAPI {
let rateString = String(rateDouble)
let lastUpdatedString = ISO8601DateFormatter().string(from: Date())
latestRateDataStore = WidgetDataStore(rate: rateString, lastUpdate: lastUpdatedString, rateDouble: rateDouble)
case "wazirx":
guard let tickerDict = json["ticker"] as? [String: Any],
let rateString = tickerDict["buy"] as? String,
let rateDouble = Double(rateString)
else { break }
let lastUpdatedString = ISO8601DateFormatter().string(from: Date())
latestRateDataStore = WidgetDataStore(rate: rateString, lastUpdate: lastUpdatedString, rateDouble: rateDouble)
default:
guard let bpi = json["bpi"] as? Dictionary<String, Any>,
let preferredCurrency = bpi[endPointKey] as? Dictionary<String, Any>,
Expand Down
19 changes: 18 additions & 1 deletion models/fiatUnit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const FiatUnitSource = {
Yadio: 'Yadio',
BitcoinduLiban: 'BitcoinduLiban',
Exir: 'Exir',
wazirx: 'wazirx',
} as const;

const RateExtractors = {
Expand Down Expand Up @@ -71,14 +72,30 @@ const RateExtractors = {
if (!(rate >= 0)) throw new Error(`Could not update rate for ${ticker}: data is wrong`);
return rate;
},

wazirx: async (ticker: string): Promise<number> => {
let json;
try {
const res = await fetch(`https://api.wazirx.com/api/v2/tickers/btcinr`);
json = await res.json();
} catch (e) {
throw new Error(`Could not update rate for ${ticker}: ${e.message}`);
}
let rate = json?.ticker?.buy; // eslint-disable-line
if (!rate) throw new Error(`Could not update rate for ${ticker}: data is wrong`);

rate = Number(rate);
if (!(rate >= 0)) throw new Error(`Could not update rate for ${ticker}: data is wrong`);
return rate;
},
} as const;

type FiatUnit = {
[key: string]: {
endPointKey: string;
symbol: string;
locale: string;
source: 'CoinDesk' | 'Yadio' | 'Exir' | 'BitcoinduLiban';
source: 'CoinDesk' | 'Yadio' | 'Exir' | 'BitcoinduLiban' | 'wazirx';
};
};
export const FiatUnit = untypedFiatUnit as FiatUnit;
Expand Down
2 changes: 1 addition & 1 deletion models/fiatUnits.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
"endPointKey": "INR",
"symbol": "",
"locale": "hi-HN",
"source": "CoinDesk"
"source": "wazirx"
},
"IRT": {
"endPointKey": "IRT",
Expand Down

0 comments on commit 821117a

Please sign in to comment.