Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
poocart committed Mar 16, 2024
2 parents a81fe5e + 0a404bc commit 180bb54
Show file tree
Hide file tree
Showing 13 changed files with 170 additions and 70 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/firebase-hosting-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ jobs:
npm i
npm run build
env:
REACT_APP_API_HOSTNAME: https://api-dy5ynjdjtq-uc.a.run.app
REACT_APP_API_HOSTNAME: https://api-dy5ynjdjtq-uc.a.run.app/
REACT_APP_WORLDCOIN_APP_ID: app_staging_73bcd9155d492ed847a45a92360ed9c7
REACT_APP_ETHERSPOT_KEY: "${{ secrets.ETHERSPOT_KEY }}"
REACT_APP_CHAIN_ID: 8453
REACT_APP_ASSET_SYMBOL: BASE
REACT_APP_NATIVE_ASSET_PRICE_CHAIN_ID: 8453
- uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: "${{ secrets.GITHUB_TOKEN }}"
Expand Down
2 changes: 1 addition & 1 deletion firebase/functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ api.post("/jars", verifyAuth, add);

api.post("/worldcoin/verify", worldcoinVerify);

exports.api = onRequest(api);
exports.api = onRequest({ cors: true }, api);
37 changes: 18 additions & 19 deletions frontend/src/components/LoginContainer/LoginContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@ export default function LoginContainer() {

const startGetPasskeyDataSequence = async () => {
await getPasskeyData()
.then(async (response) => {
console.log(response);
if (response) {
navigate("/app/check");
} else {
await createPasskey();
navigate("/app/check");
}
})
.catch(async (e) => {
console.warn(
"Could not get existing passkey, trying to create a new one:",
e.message
);
const r = await createPasskey();
return r;
});
.then(async (response) => {
console.log(response);
if (response) {
navigate("/app/check");
} else {
await createPasskey();
navigate("/app/check");
}
})
.catch(async (e) => {
console.warn(
"Could not get existing passkey, trying to create a new one:",
e.message
);
const r = await createPasskey();
return r;
});
};

const startDeletePasskeySequence = async () => {
Expand All @@ -59,9 +59,8 @@ export default function LoginContainer() {
};

const handleVerify = async (proof) => {
console.log(proof);
const res = await fetch(
`${process.env.REACT_APP_API_HOSTNAME}/token-tip-me/us-central1/api/worldcoin/verify?appId=${process.env.REACT_APP_WORLDCOIN_APP_ID}&actionId=sign-in`,
`${process.env.REACT_APP_API_HOSTNAME}worldcoin/verify?appId=${process.env.REACT_APP_WORLDCOIN_APP_ID}&actionId=sign-in`,
{
// route to your backend will depend on implementation
method: "POST",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/services/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react";
export const tokenTipApi = createApi({
reducerPath: "tokenTipApi",
baseQuery: fetchBaseQuery({
baseUrl: `${process.env.REACT_APP_API_HOSTNAME}/token-tip-me/us-central1/api/`,
baseUrl: process.env.REACT_APP_API_HOSTNAME,
prepareHeaders: async (headers) => {
const uid = localStorage.getItem("uid");

Expand Down
Binary file added images/TokenTipLogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions username_registry/lib/solady
Submodule solady added at ec85d4
12 changes: 0 additions & 12 deletions username_registry/script/Counter.s.sol

This file was deleted.

17 changes: 17 additions & 0 deletions username_registry/script/UsernameRegistry.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {Script, console2} from "forge-std/Script.sol";
import {UsernameRegistry} from "../src/contracts/UsernameRegistry.sol";

contract UsernameRegistryScript is Script {
function setUp() public {}

function run() public {
uint256 deployerPrivateKey = vm.envUint("DEPLOYER_PRIVATE_KEY");
vm.startBroadcast(deployerPrivateKey);
UsernameRegistry unreg = new UsernameRegistry(msg.sender);
console2.log("UsernameRegistry deployed at address", address(unreg));
vm.stopBroadcast();
}
}
12 changes: 0 additions & 12 deletions username_registry/src/UsernameRegistry.sol

This file was deleted.

46 changes: 46 additions & 0 deletions username_registry/src/contracts/UsernameRegistry.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.20;

import "solady/auth/Ownable.sol";
import "../interfaces/IUsernameRegistry.sol";

contract UsernameRegistry is Ownable, IUsernameRegistry {
mapping(address => string) public addressToUsername;
mapping(string => address) public usernameToAddress;

constructor(address _owner) {
_setOwner(_owner);
}

// External functions

function registerUserData(
address _scw,
string memory _un
) external onlyOwner {
_setSCW(_scw, _un);
_setUsername(_scw, _un);
emit UserRegistered(_scw, _un);
}

function getUsernameForWallet(
address _scw
) external view returns (string memory un) {
return addressToUsername[_scw];
}

function getWalletForUsername(
string memory _un
) external view returns (address scw) {
return usernameToAddress[_un];
}

// Internal functions

function _setSCW(address _scw, string memory _un) internal {
usernameToAddress[_un] = _scw;
}
function _setUsername(address _scw, string memory _un) internal {
addressToUsername[_scw] = _un;
}
}
16 changes: 16 additions & 0 deletions username_registry/src/interfaces/IUsernameRegistry.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.20;

interface IUsernameRegistry {
event UserRegistered(address indexed scw, string un);

function registerUserData(address _scw, string memory _un) external;

function getUsernameForWallet(
address _scw
) external view returns (string memory un);

function getWalletForUsername(
string memory _un
) external view returns (address scw);
}
24 changes: 0 additions & 24 deletions username_registry/test/Counter.t.sol

This file was deleted.

68 changes: 68 additions & 0 deletions username_registry/test/UsernameRegistry.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.20;

import "forge-std/Test.sol";
import {UsernameRegistry} from "../src/contracts/UsernameRegistry.sol";

contract UsernameRegistryTest is Test {
UsernameRegistry registry;
Account internal owner;
Account internal user;

event UserRegistered(address indexed scw, string un);

function setUp() public {
owner = makeAccount("owner");
user = makeAccount("user");
registry = new UsernameRegistry(owner.addr);
}

function test_registerUserData() public {
string memory username = "john";
vm.prank(owner.addr);

registry.registerUserData(user.addr, username);

assertEq(registry.getUsernameForWallet(user.addr), username);
assertEq(registry.getWalletForUsername(username), user.addr);
}

function test_revertOnlyOwnerCanRegister() public {
string memory username = "john";
vm.prank(user.addr);
vm.expectRevert();
registry.registerUserData(user.addr, username);
}

// Test getUsernameForWallet
function test_getUsernameForWallet() public {
string memory username = "john";
vm.prank(owner.addr);

registry.registerUserData(user.addr, username);

string memory result = registry.getUsernameForWallet(user.addr);
assertEq(result, username);
}

// Test getWalletForUsername
function test_getWalletForUsername() public {
string memory username = "john";
vm.prank(owner.addr);

registry.registerUserData(user.addr, username);

address result = registry.getWalletForUsername(username);
assertEq(result, user.addr);
}

// Test UserRegistered event
function test_emitUserRegisteredEvent() public {
string memory username = "john";
vm.expectEmit(true, true, false, true);
emit UserRegistered(user.addr, username);
vm.prank(owner.addr);

registry.registerUserData(user.addr, username);
}
}

0 comments on commit 180bb54

Please sign in to comment.