@@ -8,22 +8,18 @@ pub struct AmountFt {
88 #[ interactive_clap( skip_default_input_arg) ]
99 /// Enter an amount FT to transfer:
1010 ft_transfer_amount : crate :: types:: ft_properties:: FungibleTokenTransferAmount ,
11- #[ interactive_clap( skip_default_input_arg) ]
12- /// Enter a memo for transfer (optional):
13- memo : Option < String > ,
1411 #[ interactive_clap( named_arg) ]
15- /// Enter gas for function call
16- prepaid_gas : super :: preparation_ft_transfer :: PrepaidGas ,
12+ /// Enter a memo for transfer (optional):
13+ memo : FtTransferParams ,
1714}
1815
1916#[ derive( Debug , Clone ) ]
2017pub struct AmountFtContext {
21- pub global_context : crate :: GlobalContext ,
22- pub signer_account_id : near_primitives:: types:: AccountId ,
23- pub ft_contract_account_id : near_primitives:: types:: AccountId ,
24- pub receiver_account_id : near_primitives:: types:: AccountId ,
25- pub ft_transfer_amount : crate :: types:: ft_properties:: FungibleTokenTransferAmount ,
26- pub memo : Option < String > ,
18+ global_context : crate :: GlobalContext ,
19+ signer_account_id : near_primitives:: types:: AccountId ,
20+ ft_contract_account_id : near_primitives:: types:: AccountId ,
21+ receiver_account_id : near_primitives:: types:: AccountId ,
22+ ft_transfer_amount : crate :: types:: ft_properties:: FungibleTokenTransferAmount ,
2723}
2824
2925impl AmountFtContext {
@@ -61,14 +57,6 @@ impl AmountFtContext {
6157 ft_contract_account_id : previous_context. ft_contract_account_id ,
6258 receiver_account_id : previous_context. receiver_account_id ,
6359 ft_transfer_amount,
64- memo : scope. memo . as_ref ( ) . and_then ( |s| {
65- let trimmed = s. trim ( ) ;
66- if trimmed. is_empty ( ) {
67- None
68- } else {
69- Some ( trimmed. to_string ( ) )
70- }
71- } ) ,
7260 } )
7361 }
7462}
@@ -113,10 +101,115 @@ impl AmountFt {
113101 . prompt ( ) ?,
114102 ) )
115103 }
104+ }
105+
106+ #[ derive( Debug , Clone , interactive_clap:: InteractiveClap ) ]
107+ #[ interactive_clap( input_context = AmountFtContext ) ]
108+ #[ interactive_clap( output_context = FtTransferParamsContext ) ]
109+ pub struct FtTransferParams {
110+ #[ interactive_clap( skip_default_input_arg) ]
111+ /// Enter a memo for transfer (optional):
112+ memo : Option < String > ,
113+ #[ interactive_clap( long = "prepaid-gas" ) ]
114+ #[ interactive_clap( skip_interactive_input) ]
115+ gas : Option < crate :: common:: NearGas > ,
116+ #[ interactive_clap( long = "attached-deposit" ) ]
117+ #[ interactive_clap( skip_interactive_input) ]
118+ deposit : Option < crate :: types:: near_token:: NearToken > ,
119+ #[ interactive_clap( named_arg) ]
120+ /// Select network
121+ network_config : crate :: network_for_transaction:: NetworkForTransactionArgs ,
122+ }
123+
124+ #[ derive( Clone ) ]
125+ pub struct FtTransferParamsContext ( crate :: commands:: ActionContext ) ;
126+
127+ impl FtTransferParamsContext {
128+ pub fn from_previous_context (
129+ previous_context : AmountFtContext ,
130+ scope : & <FtTransferParams as interactive_clap:: ToInteractiveClapContextScope >:: InteractiveClapContextScope ,
131+ ) -> color_eyre:: eyre:: Result < Self > {
132+ let get_prepopulated_transaction_after_getting_network_callback: crate :: commands:: GetPrepopulatedTransactionAfterGettingNetworkCallback =
133+ std:: sync:: Arc :: new ( {
134+ let signer_account_id = previous_context. signer_account_id . clone ( ) ;
135+ let ft_contract_account_id = previous_context. ft_contract_account_id . clone ( ) ;
136+ let receiver_account_id = previous_context. receiver_account_id . clone ( ) ;
137+ let ft_transfer_amount = previous_context. ft_transfer_amount . clone ( ) ;
138+ let memo = scope. memo . clone ( ) ;
139+ let gas = scope. gas . unwrap_or ( near_gas:: NearGas :: from_tgas ( 100 ) ) ;
140+ let deposit = scope. deposit . unwrap_or ( crate :: types:: near_token:: NearToken :: from_yoctonear ( 1 ) ) ;
141+
142+ move |network_config| {
143+ let amount_ft = super :: get_amount_ft (
144+ & ft_transfer_amount,
145+ network_config,
146+ & signer_account_id,
147+ & ft_contract_account_id
148+ ) ?;
149+
150+ super :: get_prepopulated_transaction (
151+ network_config,
152+ & ft_contract_account_id,
153+ & receiver_account_id,
154+ & signer_account_id,
155+ & amount_ft,
156+ & memo,
157+ & deposit,
158+ & gas
159+ )
160+ }
161+ } ) ;
162+
163+ let on_after_sending_transaction_callback: crate :: transaction_signature_options:: OnAfterSendingTransactionCallback = std:: sync:: Arc :: new ( {
164+ let signer_account_id = previous_context. signer_account_id . clone ( ) ;
165+ let ft_contract_account_id = previous_context. ft_contract_account_id . clone ( ) ;
166+ let receiver_account_id = previous_context. receiver_account_id . clone ( ) ;
167+ let ft_transfer_amount = previous_context. ft_transfer_amount . clone ( ) ;
168+
169+ move |outcome_view, network_config| {
170+ let amount_ft = super :: get_amount_ft (
171+ & ft_transfer_amount,
172+ network_config,
173+ & signer_account_id,
174+ & ft_contract_account_id
175+ ) ?;
176+
177+ if let near_primitives:: views:: FinalExecutionStatus :: SuccessValue ( _) = outcome_view. status {
178+ eprintln ! (
179+ "<{signer_account_id}> has successfully transferred {amount_ft} (FT-contract: {ft_contract_account_id}) to <{receiver_account_id}>." ,
180+ ) ;
181+ }
182+ Ok ( ( ) )
183+ }
184+ } ) ;
185+
186+ Ok ( Self ( crate :: commands:: ActionContext {
187+ global_context : previous_context. global_context ,
188+ interacting_with_account_ids : vec ! [
189+ previous_context. ft_contract_account_id,
190+ previous_context. signer_account_id,
191+ previous_context. receiver_account_id,
192+ ] ,
193+ get_prepopulated_transaction_after_getting_network_callback,
194+ on_before_signing_callback : std:: sync:: Arc :: new (
195+ |_prepolulated_unsinged_transaction, _network_config| Ok ( ( ) ) ,
196+ ) ,
197+ on_before_sending_transaction_callback : std:: sync:: Arc :: new (
198+ |_signed_transaction, _network_config| Ok ( String :: new ( ) ) ,
199+ ) ,
200+ on_after_sending_transaction_callback,
201+ } ) )
202+ }
203+ }
204+
205+ impl From < FtTransferParamsContext > for crate :: commands:: ActionContext {
206+ fn from ( item : FtTransferParamsContext ) -> Self {
207+ item. 0
208+ }
209+ }
116210
117- fn input_memo (
118- _context : & super :: SendFtCommandContext ,
119- ) -> color_eyre:: eyre:: Result < Option < String > > {
211+ impl FtTransferParams {
212+ fn input_memo ( _context : & AmountFtContext ) -> color_eyre:: eyre:: Result < Option < String > > {
120213 let input = Text :: new ( "Enter a memo for transfer (optional):" ) . prompt ( ) ?;
121214 Ok ( if input. trim ( ) . is_empty ( ) {
122215 None
0 commit comments