Add chain info to response to extension

This commit is contained in:
Ivan Grachyov 2021-11-25 13:40:56 +03:00
parent 2496941709
commit dd3a552969
2 changed files with 15 additions and 14 deletions

View File

@ -328,9 +328,9 @@ class Agent: NSObject {
let accountsList = instantiate(AccountsListViewController.self)
accountsList.onSelectedWallet = { chainId, wallet in
// TODO: pass results
ExtensionBridge.respond(id: safariRequest.id, response: ResponseToExtension(name: safariRequest.name, results: [wallet.ethereumAddress ?? "weird address"]))
// TODO: pass chain info
let response = ResponseToExtension(name: safariRequest.name, results: [wallet.ethereumAddress ?? "weird address"], chainId: "", rpcURL: "")
ExtensionBridge.respond(id: safariRequest.id, response: response)
Window.closeAllAndActivateBrowser()
}

View File

@ -8,36 +8,37 @@ struct ResponseToExtension: Codable {
let result: String?
let results: [String]?
let error: String?
let chainId: String?
let rpcURL: String?
var json: [String: AnyHashable] {
if let result = result {
return ["name": name, "result": result]
} else if let results = results {
return ["name": name, "results": results]
} else if let error = error {
return ["name": name, "error": error]
if let data = try? JSONEncoder().encode(self),
let dict = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: AnyHashable] {
return dict
} else {
return [:]
}
}
init(name: String, result: String) {
self.init(name: name, result: result, results: nil, error: nil)
self.init(name: name, result: result, results: nil, error: nil, chainId: nil, rpcURL: nil)
}
init(name: String, results: [String]) {
self.init(name: name, result: nil, results: results, error: nil)
init(name: String, results: [String], chainId: String, rpcURL: String) {
self.init(name: name, result: nil, results: results, error: nil, chainId: chainId, rpcURL: rpcURL)
}
init(name: String, error: String) {
self.init(name: name, result: nil, results: nil, error: error)
self.init(name: name, result: nil, results: nil, error: error, chainId: nil, rpcURL: nil)
}
private init(name: String, result: String?, results: [String]?, error: String?) {
private init(name: String, result: String?, results: [String]?, error: String?, chainId: String?, rpcURL: String?) {
self.name = name
self.result = result
self.results = results
self.error = error
self.chainId = chainId
self.rpcURL = rpcURL
}
}