Skip to content

Commit

Permalink
metamask backend
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmasken committed Jun 5, 2024
1 parent f15c3c5 commit 4ad038c
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .dfx/network/local/ic-https-outcalls-adapter-pid
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1006
3886
1 change: 0 additions & 1 deletion .dfx/network/local/icx-proxy-pid
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
1103
2 changes: 1 addition & 1 deletion .dfx/network/local/replica-configuration/replica-1.port
Original file line number Diff line number Diff line change
@@ -1 +1 @@
42949
46051
2 changes: 1 addition & 1 deletion .dfx/network/local/replica-configuration/replica-pid
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1013
3893
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
43 changes: 43 additions & 0 deletions canisters/backend/main.mo
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ shared (actorContext) actor class Backend(_startBlock : Nat) = this {
// The user data store. The key is the user's principal ID.
private stable var userStore : Trie.Trie<Text, User> = Trie.empty();
stable var transactionsStable : [(Nat, Transaction)] = [];
stable var metamaskUsers :[(Text,Principal)] = [];
stable var departmentsStable : [(Nat, Department)] = [];
stable var organizationsStable : [(Nat, Organization)] = [];
stable var designationsStable : [(Nat, Designation)] = [];
Expand All @@ -86,6 +87,7 @@ shared (actorContext) actor class Backend(_startBlock : Nat) = this {
stable var notificationsCounter : Nat = 0;
stable var invoiceCounter : Nat = 0;
stable var payrollCounter : Nat = 0;
stable var noofmetamaskusers : Nat = 0;
var transactions : HashMap.HashMap<Nat, Transaction> = HashMap.fromIter(Iter.fromArray(transactionsStable), transactionsStable.size(), Nat.equal, Hash.hash);
var contacts : HashMap.HashMap<Nat, Employee> = HashMap.fromIter(Iter.fromArray(contactsStable), contactsStable.size(), Nat.equal, Hash.hash);
var employees : HashMap.HashMap<Nat, Emp> = HashMap.fromIter(Iter.fromArray(stableEmployees), stableEmployees.size(), Nat.equal, Hash.hash);
Expand All @@ -94,6 +96,8 @@ shared (actorContext) actor class Backend(_startBlock : Nat) = this {
var organizations : HashMap.HashMap<Nat, Organization> = HashMap.fromIter(Iter.fromArray(organizationsStable), organizationsStable.size(), Nat.equal, Hash.hash);
var departments : HashMap.HashMap<Nat, Department> = HashMap.fromIter(Iter.fromArray(departmentsStable), departmentsStable.size(), Nat.equal, Hash.hash);
var designations : HashMap.HashMap<Nat, Designation> = HashMap.fromIter(Iter.fromArray(designationsStable), designationsStable.size(), Nat.equal, Hash.hash);
var selfcustodyusers : HashMap.HashMap<Text, Principal> = HashMap.fromIter(Iter.fromArray(metamaskUsers), metamaskUsers.size(), Text.equal, Text.hash);


var MAX_TRANSACTIONS = 30_000;
let invoices : HashMap.HashMap<Nat, Invoice> = HashMap.fromIter(Iter.fromArray(invoicesStable), invoicesStable.size(), Nat.equal, Hash.hash);
Expand Down Expand Up @@ -131,6 +135,45 @@ return Principal.fromText(wallet);
};
};

public shared ({ caller }) func addToMetamaskUsers(address:Text,identity:Principal): async Result.Result<Text, Text> {
selfcustodyusers.put(address,identity);

return #ok("identity" # "address");

};

// public shared ({ caller }) func getMetamaskUsers(): async [(Text, Principal)] {

// let allEntries = Iter.toArray(selfcustodyusers.entries());
// let users = [(Text, Principal)];
// for ((Text, Principal) in allEntries.vals()) {
// //add to users and return

// };
// };
// my_designations.add(designation);
// };
// };

// return Buffer.toArray<Designation>(my_designations);

public shared ({ caller }) func getMetamaskUsers(): async [(Text, Principal)] {
let allEntries = Iter.toArray(selfcustodyusers.entries());
var users : [(Text, Principal)] = [];
let buffer = Buffer.Buffer<(Text, Principal)>(100);
for ((key, value) in allEntries.vals()) {
// Assuming key is of type Text and value is of type Principal
// users := users.append((key, value));
buffer.add(key, value);
};
return Buffer.toArray<(Text,Principal)>(buffer);
};

// public shared ({ caller }) func getSelfCustodyUsers(): async ?HashMap.HashMap<Text, Principal> {
// return selfcustodyusers;
// };


public shared ({ caller }) func getUserPayslip(identity : Text) : async Types.Response<PayslipData> {
let employee = await getEmpByPrincipal(Principal.fromText(identity));
Debug.print("employee is " # debug_show (employee));
Expand Down

0 comments on commit 4ad038c

Please sign in to comment.