Skip to content

Commit

Permalink
fix: update token if token already exsit (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
shenao78 authored Jul 10, 2024
1 parent 78de753 commit b57be78
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions route/icp/icp_route.did
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type GenerateTicketError = variant {
TemporarilyUnavailable : text;
InsufficientAllowance : record { allowance : nat64 };
TransferFailure : text;
UnsupportedAction : text;
RedeemFeeNotSet;
UnsupportedChainId : text;
UnsupportedToken : text;
Expand Down
5 changes: 4 additions & 1 deletion route/icp/src/updates/add_new_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ pub enum AddNewTokenError {

pub async fn add_new_token(token: Token) -> Result<(), AddNewTokenError> {
if read_state(|s| s.tokens.contains_key(&token.token_id)) {
return Err(AddNewTokenError::AlreadyAdded(token.token_id));
mutate_state(|s| {
s.tokens.insert(token.token_id.clone(), token);
});
return Ok(())
}

let record = install_icrc2_ledger(
Expand Down

0 comments on commit b57be78

Please sign in to comment.