Validate NEAR transactions request

This commit is contained in:
Ivan Grachev 2022-06-09 15:07:33 +03:00
parent e2b88012c4
commit e34ab74de7

View File

@ -73,14 +73,13 @@ struct DappRequestProcessor {
} }
return .selectAccount(action) return .selectAccount(action)
case .signAndSendTransactions: case .signAndSendTransactions:
guard let account = account else { guard let account = account, let transactions = body.transactions, !transactions.isEmpty else {
respond(to: request, error: Strings.somethingWentWrong, completion: completion) respond(to: request, error: Strings.somethingWentWrong, completion: completion)
return .none return .none
} }
let meta: String let meta: String
if let transactions = body.transactions, if let jsonObject: Any = transactions.count == 1 ? transactions.first : transactions,
let jsonObject: Any = transactions.count == 1 ? transactions.first : transactions,
let data = try? JSONSerialization.data(withJSONObject: jsonObject, options: .prettyPrinted), let data = try? JSONSerialization.data(withJSONObject: jsonObject, options: .prettyPrinted),
let string = String(data: data, encoding: .utf8) { let string = String(data: data, encoding: .utf8) {
meta = string meta = string
@ -90,7 +89,7 @@ struct DappRequestProcessor {
let action = SignMessageAction(provider: request.provider, subject: .approveTransaction, account: account, meta: meta, peerMeta: peerMeta) { approved in let action = SignMessageAction(provider: request.provider, subject: .approveTransaction, account: account, meta: meta, peerMeta: peerMeta) { approved in
if approved, let privateKey = privateKey { if approved, let privateKey = privateKey {
near.signAndSendTransactions(body.transactions, account: account, privateKey: privateKey) { result in near.signAndSendTransactions(transactions, account: account, privateKey: privateKey) { result in
switch result { switch result {
case let .success(response): case let .success(response):
let body = ResponseToExtension.Near(response: response) let body = ResponseToExtension.Near(response: response)