mirror of
https://github.com/lil-org/wallet.git
synced 2025-01-04 02:24:39 +03:00
Get eth price
This commit is contained in:
parent
a3d929e087
commit
1e9368cc17
@ -45,6 +45,7 @@
|
||||
2C901C4A2689F01700D0926A /* Strings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C901C492689F01700D0926A /* Strings.swift */; };
|
||||
2C901C4D268A033100D0926A /* GasService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C901C4C268A033100D0926A /* GasService.swift */; };
|
||||
2C917429267D2A6E00049075 /* Keychain.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C917428267D2A6E00049075 /* Keychain.swift */; };
|
||||
2CC0CDBE2692027E0072922A /* PriceService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CC0CDBD2692027E0072922A /* PriceService.swift */; };
|
||||
2CDAB3722675B3F0009F8B97 /* PasswordViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CDAB3712675B3F0009F8B97 /* PasswordViewController.swift */; };
|
||||
2CE3D012267F73C00032A62E /* Transaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CE3D011267F73C00032A62E /* Transaction.swift */; };
|
||||
2CE3D015267F73E80032A62E /* Account.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CE3D014267F73E80032A62E /* Account.swift */; };
|
||||
@ -92,6 +93,7 @@
|
||||
2C901C492689F01700D0926A /* Strings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Strings.swift; sourceTree = "<group>"; };
|
||||
2C901C4C268A033100D0926A /* GasService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GasService.swift; sourceTree = "<group>"; };
|
||||
2C917428267D2A6E00049075 /* Keychain.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Keychain.swift; sourceTree = "<group>"; };
|
||||
2CC0CDBD2692027E0072922A /* PriceService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PriceService.swift; sourceTree = "<group>"; };
|
||||
2CDAB3712675B3F0009F8B97 /* PasswordViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PasswordViewController.swift; sourceTree = "<group>"; };
|
||||
2CE3D011267F73C00032A62E /* Transaction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Transaction.swift; sourceTree = "<group>"; };
|
||||
2CE3D014267F73E80032A62E /* Account.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Account.swift; sourceTree = "<group>"; };
|
||||
@ -237,6 +239,7 @@
|
||||
children = (
|
||||
2C8A09B42675101300993638 /* AccountsService.swift */,
|
||||
2C901C4C268A033100D0926A /* GasService.swift */,
|
||||
2CC0CDBD2692027E0072922A /* PriceService.swift */,
|
||||
2C917428267D2A6E00049075 /* Keychain.swift */,
|
||||
);
|
||||
path = Services;
|
||||
@ -393,6 +396,7 @@
|
||||
2C901C4A2689F01700D0926A /* Strings.swift in Sources */,
|
||||
0DB729152674E2DB0011F7A1 /* EIP712Error.swift in Sources */,
|
||||
2C6706A5267A6BFE006AAEF2 /* Bundle.swift in Sources */,
|
||||
2CC0CDBE2692027E0072922A /* PriceService.swift in Sources */,
|
||||
2C8A09C6267513FC00993638 /* Agent.swift in Sources */,
|
||||
2C8A09D42675184700993638 /* Window.swift in Sources */,
|
||||
0DB7291A2674E2DB0011F7A1 /* EIP712Type.swift in Sources */,
|
||||
|
@ -7,6 +7,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
|
||||
private let agent = Agent.shared
|
||||
private let gasService = GasService.shared
|
||||
private let priceService = PriceService.shared
|
||||
|
||||
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
|
||||
return false
|
||||
@ -15,6 +16,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
||||
agent.start()
|
||||
gasService.start()
|
||||
priceService.start()
|
||||
}
|
||||
|
||||
func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
|
||||
|
@ -22,6 +22,7 @@ class ApproveTransactionViewController: NSViewController {
|
||||
}
|
||||
|
||||
private let gasService = GasService.shared
|
||||
private let priceService = PriceService.shared
|
||||
private var currentGasInfo: GasService.Info?
|
||||
private var transaction: Transaction!
|
||||
private var completion: ((Transaction?) -> Void)!
|
||||
|
36
Encrypted Ink/Services/PriceService.swift
Normal file
36
Encrypted Ink/Services/PriceService.swift
Normal file
@ -0,0 +1,36 @@
|
||||
// Copyright © 2021 Encrypted Ink. All rights reserved.
|
||||
|
||||
import Foundation
|
||||
|
||||
class PriceService {
|
||||
|
||||
private struct PriceResponse: Codable {
|
||||
let ethereum: Price
|
||||
}
|
||||
|
||||
private struct Price: Codable {
|
||||
let usd: Double
|
||||
}
|
||||
|
||||
static let shared = PriceService()
|
||||
private let jsonDecoder = JSONDecoder()
|
||||
private let urlSession = URLSession(configuration: .ephemeral)
|
||||
|
||||
private init() {}
|
||||
|
||||
var currentPrice: Double?
|
||||
|
||||
func start() {
|
||||
let url = URL(string: "https://api.coingecko.com/api/v3/simple/price?ids=ethereum&vs_currencies=usd")!
|
||||
let dataTask = urlSession.dataTask(with: url) { [weak self] (data, _, _) in
|
||||
if let data = data,
|
||||
let priceResponse = try? self?.jsonDecoder.decode(PriceResponse.self, from: data) {
|
||||
DispatchQueue.main.async {
|
||||
self?.currentPrice = priceResponse.ethereum.usd
|
||||
}
|
||||
}
|
||||
}
|
||||
dataTask.resume()
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user