Skip to content

Commit

Permalink
Merge pull request #144 from bandprotocol/hotfix/decode-grant-allowan…
Browse files Browse the repository at this point in the history
…ce-msg

fix grantAllowance decoder
  • Loading branch information
xxibcill authored Mar 8, 2024
2 parents 256841c + bc3e41e commit dc8b443
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
5 changes: 2 additions & 3 deletions src/components/msg/tx-index/RenderMsgDetails.res
Original file line number Diff line number Diff line change
Expand Up @@ -429,9 +429,7 @@ module Grant = {
},
{
title: "Authorization URL",
content: PlainText(
msg.url->Belt.Option.getWithDefault("-")
),
content: PlainText(msg.url->Belt.Option.getWithDefault("-")),
order: 4,
},
{
Expand Down Expand Up @@ -462,6 +460,7 @@ module Revoke = {
]
}

// TODO: add more details eg. spend_limit, expiration
module GrantAllowance = {
let factory = (msg: Msg.FeeGrant.GrantAllowance.t) => [
{
Expand Down
13 changes: 13 additions & 0 deletions src/utils/JsonUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ module Decode = {

let mustDecode = (json, decoder) => json->decode(decoder)->Belt.Result.getExn

// for debug decode msg
// let mustDecode = (json, decoder) =>
// json->(
// x => {
// Js.log(x)
// switch x->decode(decoder) {
// | Ok(decoded) => Js.log("Ok")
// | Error(err) => Js.log(err)
// }
// x->decode(decoder)->Belt.Result.getExn
// }
// )

type fd_type = {
required: 'a. (list<string>, t<'a>) => 'a,
optional: 'a. (list<string>, t<'a>) => option<'a>,
Expand Down
9 changes: 5 additions & 4 deletions src/utils/Msg.res
Original file line number Diff line number Diff line change
Expand Up @@ -368,21 +368,22 @@ module FeeGrant = {
}
}

// TODO: remove decode allowance missing in transaction
module GrantAllowance = {
type t = {
grantee: Address.t,
granter: Address.t,
allowance: Allowance.t,
allowedMessages: list<string>,
// allowance: Allowance.t,
// allowedMessages: list<string>,
}

let decode = {
open JsonUtils.Decode
buildObject(json => {
granter: json.required(list{"msg", "granter"}, address),
grantee: json.required(list{"msg", "grantee"}, address),
allowance: json.required(list{"msg", "allowance"}, Allowance.decoder),
allowedMessages: json.required(list{"msg", "allowance", "allowed_messages"}, list(string)),
// allowance: json.required(list{"msg", "allowance"}, Allowance.decoder),
// allowedMessages: json.required(list{"msg", "allowance", "allowed_messages"}, list(string)),
})
}
}
Expand Down

0 comments on commit dc8b443

Please sign in to comment.