mirror of
https://github.com/lil-org/tokenary.git
synced 2024-11-30 13:02:49 +03:00
Prettify NEAR transactions description
This commit is contained in:
parent
61c498856e
commit
e2b88012c4
@ -18,8 +18,7 @@ extension SafariRequest {
|
|||||||
let method: Method
|
let method: Method
|
||||||
let account: String
|
let account: String
|
||||||
let signInRequest: SignInRequest?
|
let signInRequest: SignInRequest?
|
||||||
|
let transactions: [[String: Any]]?
|
||||||
let params: [String: Any]?
|
|
||||||
|
|
||||||
init?(name: String, json: [String: Any]) {
|
init?(name: String, json: [String: Any]) {
|
||||||
guard let method = Method(rawValue: name),
|
guard let method = Method(rawValue: name),
|
||||||
@ -28,7 +27,7 @@ extension SafariRequest {
|
|||||||
self.account = account
|
self.account = account
|
||||||
|
|
||||||
let parameters = (json["object"] as? [String: Any])?["params"] as? [String: Any]
|
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 {
|
if let contractId = parameters?["contractId"] as? String {
|
||||||
self.signInRequest = SignInRequest(contractId: contractId, methodNames: parameters?["methodNames"] as? [String])
|
self.signInRequest = SignInRequest(contractId: contractId, methodNames: parameters?["methodNames"] as? [String])
|
||||||
|
@ -78,11 +78,19 @@ struct DappRequestProcessor {
|
|||||||
return .none
|
return .none
|
||||||
}
|
}
|
||||||
|
|
||||||
let params = body.params
|
let meta: String
|
||||||
let meta = params?.description ?? "" // TODO: prettify transaction description
|
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
|
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(params, account: account, privateKey: privateKey) { result in
|
near.signAndSendTransactions(body.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)
|
||||||
|
Loading…
Reference in New Issue
Block a user