fix: handle invalid transaction ids correctly

This commit is contained in:
Rene Vergara 2024-10-10 12:52:14 -05:00
parent 32c136c167
commit a3139033b6
Signed by: pitmutt
GPG key ID: 65122AD495A7F5B2
5 changed files with 113 additions and 73 deletions

View file

@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [0.2.0.1]
### Fixed
- When the input to the transaction search is invalid, the error is handled properly.
## [0.2.0.0]
- Implemented routing

View file

@ -10929,7 +10929,7 @@
return new Search(ev);
})])([p_([input([css("input"), value14(state3.term), placeholder("Search TX ID..."), onValueInput(function(str) {
return new SetTerm(str);
})]), button([css("btn-primary raised"), type_19(ButtonSubmit.value)])([i([css("ri-search-line ri-xl")])([])])])]), table([css("footer")])([tr_([td([css("footer")])([p_([text("Made with "), a([href("https://www.purescript.org/")])([text("PureScript")])])]), td([css("footer")])([p_([i([css("ri-copyright-line")])([]), text("2024 Vergara Technologies LLC")])]), td([css("footer")])([p([])([text("Network: "), text(show13(state3.network)), br_, text("Version: "), text(state3.version), br_, text("Zebra Node: "), text(state3.zebra)])])])])]);
})]), button([css("btn-primary raised"), type_19(ButtonSubmit.value)])([i([css("ri-search-line ri-xl")])([])])])]), table([css("footer")])([tr_([td([css("footer")])([p_([text("Made with "), a([href("https://www.purescript.org/")])([text("PureScript")])])]), td([css("footer")])([p_([i([css("ri-copyright-line")])([]), text("2024 Vergara Technologies LLC")])]), td([css("footer")])([p([])([text("Network: "), text(show13(state3.network)), br_, text("Server: "), text(state3.version), br_, text("UI: 0.1.0.1"), br_, text("Zebra Node: "), text(state3.zebra)])])])])]);
};
var handleAction = function(dictMonadAff) {
var monadAffHalogenM2 = monadAffHalogenM(dictMonadAff);
@ -11018,10 +11018,10 @@
});
}
;
throw new Error("Failed pattern match at Exblo.Home (line 146, column 9 - line 154, column 61): " + [v1.constructor.name]);
throw new Error("Failed pattern match at Exblo.Home (line 148, column 9 - line 156, column 61): " + [v1.constructor.name]);
}
;
throw new Error("Failed pattern match at Exblo.Home (line 142, column 5 - line 154, column 61): " + [res.constructor.name]);
throw new Error("Failed pattern match at Exblo.Home (line 144, column 5 - line 156, column 61): " + [res.constructor.name]);
});
});
}
@ -11068,7 +11068,7 @@
});
}
;
throw new Error("Failed pattern match at Exblo.Home (line 133, column 16 - line 162, column 23): " + [v.constructor.name]);
throw new Error("Failed pattern match at Exblo.Home (line 135, column 16 - line 164, column 23): " + [v.constructor.name]);
};
};
};
@ -11292,7 +11292,9 @@
}
;
if (state3.tx instanceof Failure) {
return p_([text(state3.tx.value0)]);
return div2([css("card")])([p_([text(state3.tx.value0)]), button([css("btn-primary raised"), onClick(function(ev) {
return new Close(ev);
})])([i([css("ri-arrow-go-back-fill ri-lg")])([]), text("Back")])]);
}
;
if (state3.tx instanceof Success2) {
@ -11306,7 +11308,7 @@
return tr_([th_([text("orchard")]), table_([tr_([th_([text("actions")]), td_([text(show5(length(v.value0.actions)))])]), tr_([th_([text("value")]), td_([text(show5(v.value0.value))])])])]);
}
;
throw new Error("Failed pattern match at Exblo.Tx (line 78, column 19 - line 93, column 26): " + [v.constructor.name]);
throw new Error("Failed pattern match at Exblo.Tx (line 90, column 19 - line 105, column 26): " + [v.constructor.name]);
}(), function() {
var v = toMaybe(state3.tx.value0.sapling);
if (v instanceof Nothing) {
@ -11317,7 +11319,7 @@
return tr_([th_([text("sapling")]), table_([tr_([th_([text("spends")]), td_([text(show5(length(v.value0.spends)))])]), tr_([th_([text("outputs")]), td_([text(show5(length(v.value0.outputs)))])]), tr_([th_([text("value")]), td_([text(show5(v.value0.value))])])])]);
}
;
throw new Error("Failed pattern match at Exblo.Tx (line 94, column 19 - line 113, column 26): " + [v.constructor.name]);
throw new Error("Failed pattern match at Exblo.Tx (line 106, column 19 - line 125, column 26): " + [v.constructor.name]);
}(), function() {
var v = toMaybe(state3.tx.value0.transparent);
if (v instanceof Nothing) {
@ -11338,13 +11340,13 @@
})(0)(v.value0.vout)))])])])]);
}
;
throw new Error("Failed pattern match at Exblo.Tx (line 114, column 19 - line 137, column 26): " + [v.constructor.name]);
throw new Error("Failed pattern match at Exblo.Tx (line 126, column 19 - line 149, column 26): " + [v.constructor.name]);
}()]), button([css("btn-primary raised"), onClick(function(ev) {
return new Close(ev);
})])([i([css("ri-arrow-go-back-fill ri-lg")])([]), text("Back")])]);
}
;
throw new Error("Failed pattern match at Exblo.Tx (line 65, column 7 - line 146, column 14): " + [state3.tx.constructor.name]);
throw new Error("Failed pattern match at Exblo.Tx (line 66, column 7 - line 158, column 14): " + [state3.tx.constructor.name]);
}(), p_([i([css("ri-copyright-line")])([]), text("2024 Vergara Technologies LLC")])]);
};
var handleAction2 = function(dictMonadAff) {
@ -11354,16 +11356,16 @@
return function(v) {
if (v instanceof Initialize4) {
return discard4(modify_5(function(v1) {
var $297 = {};
for (var $298 in v1) {
if ({}.hasOwnProperty.call(v1, $298)) {
$297[$298] = v1[$298];
var $298 = {};
for (var $299 in v1) {
if ({}.hasOwnProperty.call(v1, $299)) {
$298[$299] = v1[$299];
}
;
}
;
$297.tx = Loading2.value;
return $297;
$298.tx = Loading2.value;
return $298;
}))(function() {
return bind9(gets4(function(v1) {
return v1.hex;
@ -11371,55 +11373,70 @@
return bind9(liftAff2(get4(string)("https://api.exblo.app/gettransaction/" + term)))(function(res) {
if (res instanceof Left) {
return modify_5(function(v12) {
var $301 = {};
for (var $302 in v12) {
if ({}.hasOwnProperty.call(v12, $302)) {
$301[$302] = v12[$302];
var $302 = {};
for (var $303 in v12) {
if ({}.hasOwnProperty.call(v12, $303)) {
$302[$303] = v12[$303];
}
;
}
;
$301.tx = new Failure(printError(res.value0));
return $301;
$302.tx = new Failure(printError(res.value0));
return $302;
});
}
;
if (res instanceof Right) {
var v1 = readJSON3(res.value0.body);
if (v1 instanceof Right) {
return modify_5(function(v2) {
var $306 = {};
for (var $307 in v2) {
if ({}.hasOwnProperty.call(v2, $307)) {
$306[$307] = v2[$307];
if (res.value0.status === 200) {
var v1 = readJSON3(res.value0.body);
if (v1 instanceof Right) {
return modify_5(function(v2) {
var $308 = {};
for (var $309 in v2) {
if ({}.hasOwnProperty.call(v2, $309)) {
$308[$309] = v2[$309];
}
;
}
;
}
;
$306.tx = new Success2(v1.value0);
return $306;
});
}
;
if (v1 instanceof Left) {
return modify_5(function(v2) {
var $310 = {};
for (var $311 in v2) {
if ({}.hasOwnProperty.call(v2, $311)) {
$310[$311] = v2[$311];
$308.tx = new Success2(v1.value0);
return $308;
});
}
;
if (v1 instanceof Left) {
return modify_5(function(v2) {
var $312 = {};
for (var $313 in v2) {
if ({}.hasOwnProperty.call(v2, $313)) {
$312[$313] = v2[$313];
}
;
}
;
}
;
$310.tx = new Failure(show14(v1.value0));
return $310;
});
$312.tx = new Failure(show14(v1.value0));
return $312;
});
}
;
throw new Error("Failed pattern match at Exblo.Tx (line 178, column 18 - line 181, column 69): " + [v1.constructor.name]);
}
;
throw new Error("Failed pattern match at Exblo.Tx (line 164, column 12 - line 167, column 63): " + [v1.constructor.name]);
return modify_5(function(v12) {
var $316 = {};
for (var $317 in v12) {
if ({}.hasOwnProperty.call(v12, $317)) {
$316[$317] = v12[$317];
}
;
}
;
$316.tx = new Failure("Invalid transaction identifier");
return $316;
});
}
;
throw new Error("Failed pattern match at Exblo.Tx (line 160, column 5 - line 167, column 63): " + [res.constructor.name]);
throw new Error("Failed pattern match at Exblo.Tx (line 172, column 5 - line 182, column 85): " + [res.constructor.name]);
});
});
});
@ -11427,36 +11444,36 @@
;
if (v instanceof Receive4) {
return bind9(get5)(function(st) {
var $315 = st.hex !== v.value0.input;
if ($315) {
var $320 = st.hex !== v.value0.input;
if ($320) {
return discard4(modify_5(function(v1) {
var $316 = {};
for (var $317 in v1) {
if ({}.hasOwnProperty.call(v1, $317)) {
$316[$317] = v1[$317];
var $321 = {};
for (var $322 in v1) {
if ({}.hasOwnProperty.call(v1, $322)) {
$321[$322] = v1[$322];
}
;
}
;
$316.hex = v.value0.input;
$316.network = v.value0.context;
return $316;
$321.hex = v.value0.input;
$321.network = v.value0.context;
return $321;
}))(function() {
return handleAction2(dictMonadAff)(dictNavigate)(Initialize4.value);
});
}
;
return modify_5(function(v1) {
var $319 = {};
for (var $320 in v1) {
if ({}.hasOwnProperty.call(v1, $320)) {
$319[$320] = v1[$320];
var $324 = {};
for (var $325 in v1) {
if ({}.hasOwnProperty.call(v1, $325)) {
$324[$325] = v1[$325];
}
;
}
;
$319.network = v.value0.context;
return $319;
$324.network = v.value0.context;
return $324;
});
});
}
@ -11465,7 +11482,7 @@
return navigate2(Home.value);
}
;
throw new Error("Failed pattern match at Exblo.Tx (line 155, column 16 - line 175, column 27): " + [v.constructor.name]);
throw new Error("Failed pattern match at Exblo.Tx (line 167, column 16 - line 190, column 27): " + [v.constructor.name]);
};
};
};
@ -11491,8 +11508,8 @@
handleQuery: defaultEval.handleQuery,
finalize: defaultEval.finalize,
handleAction: handleAction1(dictNavigate),
receive: function($329) {
return Just.create(Receive4.create($329));
receive: function($334) {
return Just.create(Receive4.create($334));
},
initialize: new Just(Initialize4.value)
})

View file

@ -11,6 +11,6 @@
"bundle": "spago bundle-app --to dev/app.js",
"test": "spago test",
"serve": "spago build && parcel serve --open --no-cache --dist-dir dist/ dev/index.html",
"build-prod": "rm -rf dist && mkdir -p dist && cp dev/index.html dist/ && spago bundle-app --to dist/app.js && parcel build dist/index.html"
"build-prod": "rm -rf dist && mkdir -p dist && cp dev/index.html dist/ && cp dev/*.css dist/ && cp -r dev/fonts dist/ && spago bundle-app --to dist/app.js && parcel build dist/index.html"
}
}

View file

@ -118,9 +118,11 @@ render state =
[ HH.text "Network: "
, HH.text $ show state.network
, HH.br_
, HH.text "Version: "
, HH.text "Server: "
, HH.text state.version
, HH.br_
, HH.text "UI: 0.2.0.1"
, HH.br_
, HH.text "Zebra Node: "
, HH.text state.zebra
]

View file

@ -3,6 +3,7 @@ module Exblo.Tx where
import Prelude
import Simple.JSON (readJSON)
import Affjax.StatusCode (StatusCode(..))
import Affjax.Web as AX
import Affjax.ResponseFormat as AXRF
import Data.Array (length, foldl)
@ -65,7 +66,18 @@ render state =
, case state.tx of
NotAsked -> HH.p_ [ HH.text "Explore the Zcash blockchain" ]
Loading -> HH.p_ [ HH.text "Processing Zebra response..." ]
Failure e -> HH.p_ [ HH.text e ]
Failure e ->
HH.div
[ css "card" ]
[ HH.p_ [ HH.text e ]
, HH.button
[ css "btn-primary raised"
, HE.onClick \ev -> Close ev
]
[ HH.i [ css "ri-arrow-go-back-fill ri-lg" ] []
, HH.text "Back"
]
]
Success t ->
HH.div
[ css "card" ]
@ -161,10 +173,13 @@ handleAction = case _ of
Left err -> do
H.modify_ _ { tx = Failure $ AX.printError err }
Right response -> do
case readJSON response.body of
Right (t :: Transaction) ->
H.modify_ _ { tx = Success t}
Left e -> H.modify_ _ { tx = Failure $ show e }
case response.status of
StatusCode 200 -> do
case readJSON response.body of
Right (t :: Transaction) ->
H.modify_ _ { tx = Success t}
Left e -> H.modify_ _ { tx = Failure $ show e }
_any -> H.modify_ _ { tx = Failure "Invalid transaction identifier" }
Receive {context: network, input: hex } -> do
st <- H.get
if (st.hex /= hex) then do