diff --git a/Safari Shared/Models/Requests/NearSafariRequest.swift b/Safari Shared/Models/Requests/NearSafariRequest.swift index c0cdce07..6ee16110 100644 --- a/Safari Shared/Models/Requests/NearSafariRequest.swift +++ b/Safari Shared/Models/Requests/NearSafariRequest.swift @@ -18,8 +18,7 @@ extension SafariRequest { let method: Method let account: String let signInRequest: SignInRequest? - - let params: [String: Any]? + let transactions: [[String: Any]]? init?(name: String, json: [String: Any]) { guard let method = Method(rawValue: name), @@ -28,7 +27,7 @@ extension SafariRequest { self.account = account let parameters = (json["object"] as? [String: Any])?["params"] as? [String: Any] - self.params = parameters + self.transactions = parameters?["transactions"] as? [[String: Any]] if let contractId = parameters?["contractId"] as? String { self.signInRequest = SignInRequest(contractId: contractId, methodNames: parameters?["methodNames"] as? [String]) diff --git a/Shared/Services/DappRequestProcessor.swift b/Shared/Services/DappRequestProcessor.swift index f7f0a09f..88443162 100644 --- a/Shared/Services/DappRequestProcessor.swift +++ b/Shared/Services/DappRequestProcessor.swift @@ -78,11 +78,19 @@ struct DappRequestProcessor { return .none } - let params = body.params - let meta = params?.description ?? "" // TODO: prettify transaction description + let meta: String + if let transactions = body.transactions, + let jsonObject: Any = transactions.count == 1 ? transactions.first : transactions, + let data = try? JSONSerialization.data(withJSONObject: jsonObject, options: .prettyPrinted), + let string = String(data: data, encoding: .utf8) { + meta = string + } else { + meta = Strings.somethingWentWrong + } + let action = SignMessageAction(provider: request.provider, subject: .approveTransaction, account: account, meta: meta, peerMeta: peerMeta) { approved in if approved, let privateKey = privateKey { - near.signAndSendTransactions(params, account: account, privateKey: privateKey) { result in + near.signAndSendTransactions(body.transactions, account: account, privateKey: privateKey) { result in switch result { case let .success(response): let body = ResponseToExtension.Near(response: response)