Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fc1943s committed Dec 5, 2023
1 parent a9db1f9 commit 880f136
Show file tree
Hide file tree
Showing 14 changed files with 7,498 additions and 7,304 deletions.
3 changes: 2 additions & 1 deletion apps/dice/ui/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ Copy-Item $targetDir/rs/lib/fsharp/Common.rs ../../../lib/fsharp/CommonWasm.rs -
-replace "../../../../lib/fsharp", "../../../lib/fsharp" `
-replace "pub use crate::module_", "// pub use crate::module_" `
-replace "pub struct Heap0 {", "#[derive(serde::Serialize)] pub struct Heap0 {" `
-replace "pub struct Heap1 {", "#[derive(serde::Serialize, serde::Deserialize, borsh::BorshSerialize, borsh::BorshDeserialize)] pub struct Heap1 {" `
-replace "pub struct Heap1 {", "#[derive(serde::Serialize, serde::Deserialize)] pub struct Heap1 {" `
-replace "pub struct Heap2 {", "#[derive(serde::Serialize)] pub struct Heap2 {" `
-replace "pub struct Heap3 {", "#[derive(serde::Serialize, serde::Deserialize, borsh::BorshSerialize, borsh::BorshDeserialize)] pub struct Heap3 {" `
-replace "pub struct Heap4 {", "#[derive(serde::Serialize, serde::Deserialize, borsh::BorshSerialize, borsh::BorshDeserialize)] pub struct Heap4 {" `
-replace "/Common.rs", "/CommonWasm.rs" `
| Set-Content src/dice_ui_wasm.rs

Expand Down
3 changes: 2 additions & 1 deletion apps/dice/ui/package.spiproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ modules:
nearblocks
state
components/
history
transaction
transactions
settings
menu_tabs
content
Expand Down
1 change: 1 addition & 0 deletions apps/dice/ui/src/components/app.spi
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ inl render () =
state =
leptos.create_rw_signal <|
heap {
cache = mapm.new_hash_map () |> leptos.create_rw_signal
}
loading = mapm.new_hash_map () |> leptos.create_rw_signal
}
Expand Down
6 changes: 3 additions & 3 deletions apps/dice/ui/src/components/content.spi
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ inl render () : _ leptos.div =
inl tab =
if hash_url |> leptos.url_pathname |> sm'.starts_with ("/settings" |> sm'.to_std_string)
then menu_tabs.Settings
else menu_tabs.History
else menu_tabs.Transactions

inl tab_log = tab |> sm'.format_pretty'
leptos.log $'"content.render () / effect 2 / new_tab: " + string !tab_log + ""'
Expand All @@ -69,11 +69,11 @@ inl render () : _ leptos.div =
] fun () =>
open menu_tabs
match tab |> leptos.signal_get with
| History =>
| Transactions =>
leptos.div [
$'"class=\\\"flex flex-1 flex-col [overflow-y:auto]\\\""'
] fun () =>
history.render ()
transactions.render ()
|> leptos.views_to_fragment
|> leptos.element_to_view
| Settings =>
Expand Down
341 changes: 0 additions & 341 deletions apps/dice/ui/src/components/history.spi

This file was deleted.

14 changes: 7 additions & 7 deletions apps/dice/ui/src/components/menu_tabs.spi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
union menu_tab =
| Blank
| History
| Transactions
| Settings

inl render tab =
Expand All @@ -26,8 +26,8 @@ inl render tab =
] fun () =>
:>(;[
leptos.option'
(fun () => (tab |> leptos.signal_get) = History)
"History"
(fun () => (tab |> leptos.signal_get) = Transactions)
"Transactions"

leptos.option'
(fun () => (tab |> leptos.signal_get) = Settings)
Expand All @@ -48,10 +48,10 @@ inl render tab =
] fun () =>
:>(;[
leptos.tab_link
$'!url + "#/history"'
(leptos.history_svg ())
"History"
(fun () => (tab |> leptos.signal_get) = History)
$'!url + "#/transactions"'
(leptos.inbox_svg ())
"Transactions"
(fun () => (tab |> leptos.signal_get) = Transactions)

leptos.tab_link
$'!url + "#/settings"'
Expand Down
4 changes: 2 additions & 2 deletions apps/dice/ui/src/components/settings.spi
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ inl global_state_log_render () : _ leptos.pre =
leptos.log $'"settings.global_state_log_render () / global_state_json memo"'

inl global_state = join global_state
inl json : resultm.result' rust.std_string rust.std_string = !\($'"serde_json::to_string_pretty(&!global_state).map_err(|x| x.to_string())"')
inl json : resultm.result' rust.std_string rust.std_string =
!\($'"serde_json::to_string_pretty(&!global_state).map_err(|x| x.to_string())"')
match json |> resultm.unbox with
| Ok json => json |> sm'.from_std_string
| Error error => $'"Error: " + string !error + ""'
Expand All @@ -27,7 +28,6 @@ inl render () =

;[
leptos.accordion "View" true fun () =>
inl grid_pair_padding_class = leptos.grid_pair_padding_class ()
:>(;[
leptos.grid_pair
{ padding = None; cols = None; class = $'"items-center"' }
Expand Down
171 changes: 171 additions & 0 deletions apps/dice/ui/src/components/transaction.spi
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
open rust_operators
open model.near.nearblocks

inl render (index : i64) (transaction : txn) : _ leptos.div =
print_static "<transaction.render>"

inl global_state : state.global_state = leptos.use_context () |> optionm'.unwrap

leptos.div [
$'"class=\\\"flex flex-1 flex-col\\\""'
] fun () => :>(;[
leptos.divider fun () =>
$'"Transaction " + string (!index + 1L) + ""' |> leptos.text_fragment
|> leptos.element_to_view

leptos.div [
$'"class=\\\"grid flex-1 divide-y-[1px] divide-gray-500/[.10]\\\""'
] fun () => :>(;[
leptos.grid_pair
{ padding = Some ""; cols = None; class = "items-center py-[4px]" }
fun () => "Block Timestamp" |> leptos.text_fragment
fun () =>
transaction.block_timestamp
|> fun x => !\($'"!x.parse().unwrap()"') : i64
|> date_time.from_timestamp'
|> optionm.map fun x =>
x
|> date_time.to_local
|> date_time.format'' "%Y-%m-%d %H:%M:%S"
|> sm'.from_std_string
|> resultm.from_option
|> to_string
|> leptos.text_fragment
|> leptos.element_to_view

leptos.grid_pair
{ padding = Some ""; cols = None; class = "items-center py-[4px]" }
fun () => "Predecessor" |> leptos.text_fragment
fun () =>
transaction.predecessor_account_id
|> to_string
|> leptos.text_fragment
|> leptos.element_to_view

leptos.grid_pair
{ padding = Some ""; cols = None; class = "items-center py-[4px]" }
fun () => "Receiver" |> leptos.text_fragment
fun () =>
transaction.receiver_account_id
|> to_string
|> leptos.text_fragment
|> leptos.element_to_view

leptos.grid_pair
{ padding = Some "sm:pr-[10px]"; cols = None; class = "items-center py-[4px]" }
fun () => "Actions" |> leptos.text_fragment
fun () =>
a transaction.actions
|> am'.map_vec fun { action method } =>
leptos.grid_pair
{ padding = Some "items-center"; cols = Some ""; class = "" }
fun () =>
match action |> sm'.from_std_string with
| "FUNCTION_CALL" => "Function Call:"
| "DEPLOY_CONTRACT" => "Contract Deploy:"
| "TRANSFER" => "Transfer:"
| action => action
|> leptos.text_fragment
fun () =>
leptos.div [
$'"class=\\\"flex flex-1 flex-col\\\""'
] fun () => :>(;[
leptos.grid_pair
{ padding = Some ""; cols = None; class = "" }
fun () => "Method" |> leptos.text_fragment
fun () =>
match method with
| Some method =>
method
|> to_string
|> leptos.text_fragment
| None =>
"None" |> leptos.text_fragment
|> leptos.element_to_view
])
|> leptos.element_to_fragment
|> fun (a x : _ i32 _) => :>x
|> leptos.element_to_view

leptos.grid_pair
{ padding = Some ""; cols = None; class = "items-center py-[4px]" }
fun () => "Deposit" |> leptos.text_fragment
fun () =>
transaction.actions_agg.deposit
|> sm'.obj_to_string
|> leptos.text_fragment
|> leptos.element_to_view

leptos.grid_pair
{ padding = Some ""; cols = None; class = "items-center py-[4px]" }
fun () => "Outcome Status" |> leptos.text_fragment
fun () =>
transaction.outcomes.status
|> sm'.obj_to_string
|> leptos.text_fragment
|> leptos.element_to_view

leptos.grid_pair
{ padding = Some ""; cols = None; class = "items-center py-[4px]" }
fun () => "Fee" |> leptos.text_fragment
fun () =>
transaction.outcomes_agg.transaction_fee
|> sm'.obj_to_string
|> leptos.text_fragment
|> leptos.element_to_view

leptos.grid_pair
{ padding = Some ""; cols = None; class = "items-center py-[4px]" }
fun () => "Block Height" |> leptos.text_fragment
fun () =>
transaction.block.block_height
|> sm'.obj_to_string
|> leptos.text_fragment
|> leptos.element_to_view

leptos.grid_pair
{ padding = Some ""; cols = None; class = "items-center py-[4px]" }
fun () => "Hash" |> leptos.text_fragment
fun () =>
transaction.transaction_hash
|> to_string
|> leptos.text_fragment
|> leptos.element_to_view

leptos.grid_pair
{ padding = Some ""; cols = None; class = "items-center py-[4px]" }
fun () => "Block Hash" |> leptos.text_fragment
fun () =>
transaction.included_in_block_hash
|> to_string
|> leptos.text_fragment
|> leptos.element_to_view

leptos.grid_pair
{ padding = Some ""; cols = None; class = "items-center py-[4px]" }
fun () => "Receipt ID" |> leptos.text_fragment
fun () =>
transaction.receipt_id
|> to_string
|> leptos.text_fragment
|> leptos.element_to_view

if leptos.rw_signal_get_untracked global_state.core_state .debug |> leptos.rw_signal_get then
match transaction.logs with
| ;[] => ;[] |> leptos.views_to_view
| _ =>
leptos.grid_pair
{ padding = Some ""; cols = None; class = "items-center py-[4px]" }
fun () => "Logs" |> leptos.text_fragment
fun () =>
(a transaction.logs : _ i32 _)
|> am'.map_vec sm'.from_std_string
|> sm'.concat "\n"
|> sm'.replace "\\n" "\n"
|> leptos.text_block_pre "[max-height:20vh]"
|> leptos.element_to_fragment
|> leptos.element_to_view
else ;[] |> leptos.views_to_view
])
|> leptos.element_to_view
])
93 changes: 93 additions & 0 deletions apps/dice/ui/src/components/transactions.spi
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
open rust_operators


inl render () =
print_static "<transactions.render>"
leptos.log $'"transactions.render ()"'

inl global_state : state.global_state = leptos.use_context () |> optionm'.unwrap

inl url = leptos.create_memo fun () =>
inl account = "i574n.near"

$'"https://api2.nearblocks.io/v1/account/" + !account + "/txns?&order=desc&page=1&per_page=25"'
|> Some
|> optionm'.box
|> fun x =>
inl x_log = x |> sm'.format_debug
leptos.log $'"transactions.render () / url create_memo / result: " + string !x_log + ""'
x

inl root : rust.func0 (option (result model.near.nearblocks.root string)) =
leptos.use_request (fun () => url |> leptos.memo_get) model.near.nearblocks.root_unbox

inl txns : rust.func0 (option (result (array_base (unativeint * heap model.near.nearblocks.txn)) string)) =
rust.move fun () =>
root
|> rust.func0_get
|> optionm.map fun result =>
result
|> resultm.map fun result =>
(a result.txns : _ i32 _)
|> am'.enumerate
|> am'.map_vec fun i, x => i, heap x
|> fun (a x : _ i32 _) => x
|> Some
|> resultm.flatten_option
|> fun x =>
inl x_log = x |> sm'.format_debug
leptos.log $'"transactions.render () / txns move / result length: " + (!x_log |> string |> String.length |> string) + ""'
x

;[
leptos.accordion "Transactions" true fun () =>
match txns |> rust.func0_get with
| Some (Ok transactions) =>
leptos.div [
$'"class=\\\"grid flex-1 py-[10px] px-[12px] [gap:15px] sm:[grid-template-columns:repeat(auto-fill,minmax(500px,1fr))]\\\""'
] fun () =>
leptos.for
transactions
fun _, transaction => transaction.transaction_hash
fun index, transaction' =>
!transaction'
|> transaction.render (index |> i64)
|> leptos.element_to_fragment
|> leptos.view_to_fragment
|> leptos.element_to_fragment
| Some (Error error) =>
:>(;[
leptos.x_red_svg () |> leptos.element_to_view
error |> leptos.text_view
])
| _ =>
leptos.div [
$'"class=\\\"grid place-content-center py-[10vh]\\\""'
] fun () =>
leptos.div [
$'"class=\\\"flex flex-1 [gap:4px] items-center\\\""'
] fun () => :>(;[
leptos.loading_svg () |> leptos.element_to_view
$'"Loading..."' |> leptos.text_view
])
|> leptos.element_to_fragment
|> leptos.element_to_fragment
|> leptos.element_to_view

if leptos.rw_signal_get_untracked global_state.core_state .debug |> leptos.rw_signal_get then
leptos.accordion "Debug" true fun () =>
:>(;[
leptos.grid_pair
{ padding = None; cols = None; class = "" }
fun () => "Transactions" |> leptos.text_fragment
fun () =>
txns
|> rust.func0_get
|> sm'.format_pretty'
|> sm'.from_std_string
|> leptos.text_block_pre "[max-height:70vh]"
|> leptos.element_to_fragment
])
|> leptos.element_to_view
else ;[] |> leptos.views_to_view
]
Loading

0 comments on commit 880f136

Please sign in to comment.