Skip to content

Commit

Permalink
chore: return error from method if not supported
Browse files Browse the repository at this point in the history
  • Loading branch information
chungquantin committed Jul 30, 2024
1 parent d5034bc commit 773dd4e
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pallets/api/src/fungibles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ pub mod pallet {
TokenDecimals(T::AssetKind),
}

#[pallet::error]
pub enum Error<T> {
// The method is not supported for the asset class
UnsupportedMethod,
}

/// Configure the pallet by specifying the parameters and types on which it depends.
#[pallet::config]
pub trait Config: frame_system::Config + pallet_assets::Config<Self::AssetsInstance> {
Expand Down Expand Up @@ -148,8 +154,8 @@ pub mod pallet {
value: BalanceOf<T>,
) -> DispatchResultWithPostInfo {
match T::AssetCriteria::convert(asset) {
Either::Left(_) => todo!(),
Either::Right(id) => Self::do_approve_asset(origin, id, spender, value),
Either::Left(_) => Err(Error::<T>::UnsupportedMethod.into()),
}
}

Expand All @@ -168,11 +174,11 @@ pub mod pallet {
value: BalanceOf<T>,
) -> DispatchResult {
match T::AssetCriteria::convert(asset) {
Either::Left(_) => todo!(),
Either::Right(id) => {
let spender = T::Lookup::unlookup(spender);
AssetsOf::<T>::approve_transfer(origin, id.into(), spender, value)
},
Either::Left(_) => Err(Error::<T>::UnsupportedMethod.into()),
}
}
}
Expand Down

0 comments on commit 773dd4e

Please sign in to comment.