Skip to content

Commit

Permalink
Merge pull request #9 from ggreif/simplifications
Browse files Browse the repository at this point in the history
chore: simplify code
  • Loading branch information
sideffect0 authored May 10, 2024
2 parents 8189ae7 + ae836a0 commit 0424bf5
Showing 1 changed file with 8 additions and 27 deletions.
35 changes: 8 additions & 27 deletions src/token/main.mo
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

import Prim "mo:⛔";
import Trie "mo:base/Trie";
import Principal "mo:base/Principal";
import Array "mo:base/Array";
Expand Down Expand Up @@ -95,7 +94,7 @@ shared(msg) actor class ICRC1Canister(args : {tokenOwner : Principal}) = this {
private var drc202 = DRC202.DRC202({EN_DEBUG = false; MAX_CACHE_TIME = 3 * 30 * 24 * 3600 * 1000000000; MAX_CACHE_NUMBER_PER = 100; MAX_STORAGE_TRIES = 2; }, standard_);
private stable var drc202_lastStorageTime : Time.Time = 0;

let motoko_nft : MotokoNft.Self = actor("oeee4-qaaaa-aaaak-qaaeq-cai"); // official motok nft snapshot
let motoko_nft : MotokoNft.Self = actor("oeee4-qaaaa-aaaak-qaaeq-cai"); // official Motoko NFT snapshot

/*
* Local Functions
Expand Down Expand Up @@ -210,7 +209,6 @@ shared(msg) actor class ICRC1Canister(args : {tokenOwner : Principal}) = this {
case(_){};
};
};
case(_){};
};
let nonce = index;
let txid = drc202.generateTxid(Principal.fromActor(this), caller, nonce);
Expand Down Expand Up @@ -653,10 +651,9 @@ shared(msg) actor class ICRC1Canister(args : {tokenOwner : Principal}) = this {
private func findEligibleTokens(user: Principal) : Nat {
var totalTokens : Nat = 0;
let accountIdx : [Nat] = Iter.toArray(Iter.range(0, 50));
var address : Text = "";
for(i in accountIdx.vals()) {
for (i in accountIdx.vals()) {
let subaccount_array : [Nat8] = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,Nat8.fromNat(i)];
address := EAID.fromPrincipal(user, ?subaccount_array);
let address = EAID.fromPrincipal(user, ?subaccount_array);
totalTokens += Option.get(eligibleTokens.get(address), 0);
};
return totalTokens;
Expand All @@ -665,32 +662,22 @@ shared(msg) actor class ICRC1Canister(args : {tokenOwner : Principal}) = this {
private func _getEligibleTokenOfUser(user: Principal) : TokenClaimStatus {
switch(airdropedTokens.get(user)) {
case(?tokens) {
return #Airdroped({
tx = "";
tokens = tokens;
});
return #Airdroped { tx = ""; tokens };
};
case(_){};
};
switch(claimedTokens.get(user)){
case(?tokens){

return #Claimed({
tx = "";
tokens = tokens;
});
return #Claimed { tx = ""; tokens };
};
case(_){};
};
return #Unclaimed(findEligibleTokens(user));
};

public shared query(msg) func getEligibleTokenOfUser(user : Principal) : async TokenClaimStatus {
switch(_getEligibleTokenOfUser(user)) {
case(#Unclaimed(tokens)){ return #Unclaimed(tokens); };
case(#Airdroped(status)){ return #Airdroped(status); };
case(#Claimed(status)){ return #Claimed(status); };
};
_getEligibleTokenOfUser(user)
};

// updates
Expand Down Expand Up @@ -731,10 +718,7 @@ shared(msg) actor class ICRC1Canister(args : {tokenOwner : Principal}) = this {
]
);

return #Claimed({
tx = tx;
tokens = tokens;
});
return #Claimed { tx; tokens };
};
case(_){
throw Error.reject("unexpected error");
Expand Down Expand Up @@ -773,10 +757,7 @@ shared(msg) actor class ICRC1Canister(args : {tokenOwner : Principal}) = this {
("fee", #U64(u64(fee_)))
]
);
return #Airdroped({
tx = tx;
tokens = tokens;
});
return #Airdroped { tx; tokens };
};
case(_){
throw Error.reject("unexpected error");
Expand Down

0 comments on commit 0424bf5

Please sign in to comment.