pub fn mint_nft(&mut self, amount: NearToken) -> Promise {
let user = env::predecessor_account_id();
Promise::new(self.nft.clone())
.function_call(
"mint".to_string(),
{
"token_id": "1",
"receiver_id": user.clone()
},
Gas(5_000_000_000_000),
amount.as_yoctonear()
)
.then(
Self::ext(env::current_account_id())
.mint_callback(user, amount),
)
}
#[private]
pub fn mint_callback(
&mut self,
user: AccountId,
amount: NearToken,
#[callback_result] result: Result<(), PromiseError>,
) {
if result.is_err() {
// we got the tokens back, refund the user
// do not use panic, that will stop the callback execution
Promise::new(user).transfer(amount);
} else {
// mint succeeded, do something else
}
}