@@ -9,6 +9,7 @@ use torus_client::{
99use crate :: {
1010 cli:: CliCtx ,
1111 store:: { get_account, get_key} ,
12+ util:: torus,
1213} ;
1314
1415#[ derive( clap:: Parser ) ]
@@ -65,12 +66,14 @@ pub enum StakeCliSubCommand {
6566#[ derive( tabled:: Tabled ) ]
6667struct StakingEntry {
6768 target : String ,
68- amount : u128 ,
69+ amount : String ,
6970}
7071
7172pub async fn given ( ctx : & CliCtx , key : String ) -> anyhow:: Result < ( ) > {
7273 let account = get_account ( & key) ?;
7374
75+ println ! ( "Fetching given stake..." ) ;
76+
7477 let staking = if ctx. is_testnet ( ) {
7578 let client = TorusClient :: for_testnet ( ) . await ?;
7679 client
@@ -91,15 +94,22 @@ pub async fn given(ctx: &CliCtx, key: String) -> anyhow::Result<()> {
9194 . await ?
9295 } ;
9396
94- let staking = staking
95- . into_iter ( )
97+ let mut entries = staking
98+ . iter ( )
9699 . map ( |( ( _, target) , amount) | StakingEntry {
97100 target : target. to_string ( ) ,
98- amount,
99- } ) ;
101+ amount : torus ( * amount) ,
102+ } )
103+ . collect :: < Vec < _ > > ( ) ;
100104
101- let table = Table :: new ( staking ) ;
105+ let sum = staking . iter ( ) . map ( | ( _ , amount ) | * amount ) . sum :: < u128 > ( ) ;
102106
107+ entries. push ( StakingEntry {
108+ target : "" . to_string ( ) ,
109+ amount : torus ( sum) ,
110+ } ) ;
111+
112+ let table = Table :: new ( entries) ;
103113 println ! ( "{table}" ) ;
104114
105115 Ok ( ( ) )
@@ -108,12 +118,14 @@ pub async fn given(ctx: &CliCtx, key: String) -> anyhow::Result<()> {
108118#[ derive( tabled:: Tabled ) ]
109119struct StakedEntry {
110120 source : String ,
111- amount : u128 ,
121+ amount : String ,
112122}
113123
114124pub async fn received ( ctx : & CliCtx , key : String ) -> anyhow:: Result < ( ) > {
115125 let account = get_account ( & key) ?;
116126
127+ println ! ( "Fetching received stake..." ) ;
128+
117129 let staked = if ctx. is_testnet ( ) {
118130 let client = TorusClient :: for_testnet ( ) . await ?;
119131 client
@@ -134,13 +146,22 @@ pub async fn received(ctx: &CliCtx, key: String) -> anyhow::Result<()> {
134146 . await ?
135147 } ;
136148
137- let staked = staked. into_iter ( ) . map ( |( ( _, source) , amount) | StakedEntry {
138- source : source. to_string ( ) ,
139- amount,
140- } ) ;
149+ let mut entries = staked
150+ . iter ( )
151+ . map ( |( ( _, target) , amount) | StakedEntry {
152+ source : target. to_string ( ) ,
153+ amount : torus ( * amount) ,
154+ } )
155+ . collect :: < Vec < _ > > ( ) ;
141156
142- let table = Table :: new ( staked) ;
157+ let sum = staked. iter ( ) . map ( |( _, amount) | * amount) . sum :: < u128 > ( ) ;
158+
159+ entries. push ( StakedEntry {
160+ source : "" . to_string ( ) ,
161+ amount : torus ( sum) ,
162+ } ) ;
143163
164+ let table = Table :: new ( entries) ;
144165 println ! ( "{table}" ) ;
145166
146167 Ok ( ( ) )
@@ -152,7 +173,7 @@ pub async fn add(ctx: &CliCtx, key: String, target: String, amount: u128) -> any
152173
153174 let target = AccountId32 :: from_str ( & target) ?;
154175
155- ctx. confirm ( & format ! ( "add {amount } stake to {target}" ) ) ?;
176+ ctx. confirm ( & format ! ( "add {} stake to {target}" , torus ( amount ) ) ) ?;
156177
157178 println ! ( "Staking..." ) ;
158179
@@ -183,7 +204,7 @@ pub async fn remove(ctx: &CliCtx, key: String, target: String, amount: u128) ->
183204
184205 let target = AccountId32 :: from_str ( & target) ?;
185206
186- ctx. confirm ( & format ! ( "remove {amount } stake from {target}" ) ) ?;
207+ ctx. confirm ( & format ! ( "remove {} stake from {target}" , torus ( amount ) ) ) ?;
187208
188209 println ! ( "Unstaking..." ) ;
189210
@@ -222,7 +243,8 @@ pub async fn transfer(
222243 let target = AccountId32 :: from_str ( & target) ?;
223244
224245 ctx. confirm ( & format ! (
225- "transfer {amount} stake from {source} to {target}"
246+ "transfer {} stake from {source} to {target}" ,
247+ torus( amount)
226248 ) ) ?;
227249
228250 println ! ( "Transfering stake..." ) ;
0 commit comments