Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various improvements #109

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
52b6a15
fix: copy address instead of shortenaddress or group
nicolasbrugneaux Nov 29, 2024
8e3996c
feat: show accurate unlocking period
nicolasbrugneaux Nov 29, 2024
f7cb634
fix: shows the correct proposal status
nicolasbrugneaux Nov 29, 2024
a258e82
fix: use the executedIds earlier in the flow to prioritize metadata<-…
nicolasbrugneaux Dec 3, 2024
d09f55a
refactor: use NEXT_PUBLIC_RPC_URL
nicolasbrugneaux Dec 4, 2024
b8f6816
chore: add anvil to tests
nicolasbrugneaux Dec 4, 2024
3dab9dd
Merge branch 'main' into fix/various
nicolasbrugneaux Dec 5, 2024
06f8e0d
fix: add foundry-toolchain
nicolasbrugneaux Dec 6, 2024
db0e282
fix: anvil on ci
nicolasbrugneaux Dec 6, 2024
e2372f6
fix: prettier
nicolasbrugneaux Dec 6, 2024
b3b1b98
fix: unused json
nicolasbrugneaux Dec 6, 2024
8f7d9b8
fix: quorum calculation
nicolasbrugneaux Dec 9, 2024
3cc68d8
fix: quorum calculation
nicolasbrugneaux Dec 10, 2024
3d0e29e
wip: tests
nicolasbrugneaux Dec 13, 2024
9b5deb9
fix: tests
nicolasbrugneaux Dec 16, 2024
45c3cc9
fake stash
nicolasbrugneaux Dec 16, 2024
209d515
wip: renderhooks
nicolasbrugneaux Dec 17, 2024
5d3c2ea
test: should pass!
nicolasbrugneaux Dec 18, 2024
2459980
Merge branch 'main' into fix/various
nicolasbrugneaux Dec 18, 2024
f237b89
fix: linting
nicolasbrugneaux Dec 18, 2024
55294c1
fix: ci
nicolasbrugneaux Dec 18, 2024
65f7f45
fix: prettier
nicolasbrugneaux Dec 18, 2024
c48b11c
fx: foundry version
nicolasbrugneaux Dec 18, 2024
2dfdab0
fix: anvil setup
nicolasbrugneaux Dec 18, 2024
6df3373
fix: more resilient snapshot
nicolasbrugneaux Dec 18, 2024
61b9025
fix: PR feedback
nicolasbrugneaux Dec 19, 2024
c0152ee
Merge branch 'main' into fix/various
nicolasbrugneaux Dec 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ jobs:
# Check out the lockfile from main, reinstall, and then
# verify the lockfile matches what was committed.
run: |
yarn install --immutable
CHANGES=$(git status -s)
if [[ ! -z $CHANGES ]]; then
echo "Changes found: $CHANGES"
git diff
exit 1
fi
yarn install --immutable
CHANGES=$(git status -s)
if [[ ! -z $CHANGES ]]; then
echo "Changes found: $CHANGES"
git diff
exit 1
fi

build:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -85,7 +85,7 @@ jobs:
.yarn/cache
key: ${{ runner.os }}-yarn-cache-${{ hashFiles('./yarn.lock') }}

- name: lint
- name: lint
run: yarn run lint

test:
Expand All @@ -102,6 +102,9 @@ jobs:
**/node_modules
.yarn/cache
key: ${{ runner.os }}-yarn-cache-${{ hashFiles('./yarn.lock') }}
- uses: foundry-rs/foundry-toolchain@v1

- name: test
run: yarn run test
env:
NEXT_PUBLIC_RPC_URL: https://public-archive-nodes.celo-testnet.org
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ For support, you can [file an issue](https://github.com/celo-org/celo-mondo/issu

## Development

To run Celo Mondo against alfajores network set `NEXT_PUBLIC_IS_ALFAJORES` env variable to `1`.
To run Celo Mondo against alfajores network set `NEXT_PUBLIC_RPC_URL` env variable to `alfajores`.

To run Celo Mondo against any other network (such as your local testnet) set `NEXT_PUBLIC_RPC_URL` env variable to `http://<your-rpc-url>`.

1. Install: `yarn`
2. Setup: `yarn prepare`
3. Run locally: `yarn dev`
4. Test locally: `yarn test`

For more information about the architecture and internals of this app, see [DEVELOPER.md](./DEVELOPER.md).
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,26 @@
"zod": "^3.23.8"
},
"devDependencies": {
"@celo/devchain-anvil": "12.0.0-canary.49",
"@tanstack/eslint-plugin-query": "^5.28.6",
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.1.0",
"@types/dompurify": "^3",
"@types/node": "^20.11.30",
"@types/react": "^18.2.73",
"@types/react-dom": "^18.2.22",
"@typescript-eslint/eslint-plugin": "^7.4.0",
"@typescript-eslint/parser": "^7.4.0",
"@viem/anvil": "^0.0.10",
nicolasbrugneaux marked this conversation as resolved.
Show resolved Hide resolved
"autoprefixer": "^10.4.20",
"critters": "^0.0.25",
"daisyui": "^4.9.0",
"dotenv": "^16.4.5",
"eslint": "^8.57.1",
"eslint-config-next": "^14.1.4",
"eslint-config-prettier": "^9.1.0",
"happy-dom": "^15.11.7",
"husky": "^9.0.11",
"lint-staged": "^15.2.10",
"postcss": "^8.4.38",
Expand Down
2 changes: 1 addition & 1 deletion src/app/bridge/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const BRIDGES: Bridge[] = [
{
name: 'Superbridge',
operator: 'Superbridge',
href: `https://superbridge.app/celo${config.isAlfajores ? '-testnet' : ''}`,
href: `https://superbridge.app/celo${config.chain.testnet ? '-testnet' : ''}`,
logo: '/logos/superbridge.jpg',
cel2Only: true,
},
Expand Down
38 changes: 16 additions & 22 deletions src/app/delegate/api/register/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ const getRequest = (formData: FormData): Request => {
formData: () => formData,
} as any as Request;
};
const imageBuffer = fs.readFileSync(
path.join(__dirname, '../../../../../public/logos/validators/clabs.jpg'),
);

const getValidFormData = async () => {
const request = await getValidRequest();
const data = new FormData();
const imageBuffer = fs.readFileSync(
path.join(__dirname, '../../../../../public/logos/validators/clabs.jpg'),
);

data.append('image', new Blob([imageBuffer], { type: 'image/jpeg' }), 'clabs.jpg');
data.append('name', request.name);
Expand Down Expand Up @@ -52,25 +52,19 @@ it('successfuly calls PR creation', async () => {
`);
expect(isAddressAnAccountMock).toHaveBeenCalledTimes(1);
expect(createDelegationPRMock).toHaveBeenCalledTimes(1);
expect(createDelegationPRMock.mock.lastCall).toMatchInlineSnapshot(`
[
{
"address": "0x6A5DD51Da29914e8659b9CC354B414f30c7692c4",
"description": "Delegatee description",
"image": File {
Symbol(kHandle): Blob {},
Symbol(kLength): 3801,
Symbol(kType): "image/jpeg",
},
"interests": "blockchain, NFTs",
"name": "Delegatee name",
"signature": "0x52a3c23ef6c6817691872b77615ef30927453d641acd8c607de458d39e581bcd5411f723102640897af151644086abf4f3a9baf216d684d784194aef2c6730be1c",
"twitterUrl": "https://example.com/x",
"verificationUrl": "https://example.com/verification",
"websiteUrl": "https://example.com",
},
]
`);
const request = createDelegationPRMock.mock.lastCall![0];
expect(request.address).toBe('0x6A5DD51Da29914e8659b9CC354B414f30c7692c4');
expect(request.description).toBe('Delegatee description');
expect(request.image).toBeInstanceOf(File);
expect((request.image as File).arrayBuffer()).resolves.toEqual(imageBuffer.buffer);
expect(request.interests).toBe('blockchain, NFTs');
expect(request.name).toBe('Delegatee name');
expect(request.signature).toBe(
'0x52a3c23ef6c6817691872b77615ef30927453d641acd8c607de458d39e581bcd5411f723102640897af151644086abf4f3a9baf216d684d784194aef2c6730be1c',
);
expect(request.twitterUrl).toBe('https://example.com/x');
expect(request.verificationUrl).toBe('https://example.com/verification');
expect(request.websiteUrl).toBe('https://example.com');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the reason I'd rather leave the snapshot is that if we add new fields to the form then it has to be added here explicitly

and we're missing checking for the file properties like mime type and size in this case

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the timestamp kept changing that's the reason

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which timestamp?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the file's created at

});

it('handles validation errors', async () => {
Expand Down
2 changes: 2 additions & 0 deletions src/app/governance/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ function useFilteredProposals({
p.proposal?.url.toLowerCase().includes(query) ||
p.metadata?.title.toLowerCase().includes(query) ||
p.metadata?.author.toLowerCase().includes(query) ||
String(p.metadata?.cgp).toLowerCase().includes(query) ||
String(p.id).toLowerCase().includes(query) ||
p.metadata?.url?.toLowerCase().includes(query),
);
}, [proposals, filter, searchQuery]);
Expand Down
4 changes: 3 additions & 1 deletion src/app/staking/[address]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ function HeaderSection({ group }: { group?: ValidatorGroup }) {
<div className="flex items-center space-x-3 sm:space-x-6">
<ValidatorGroupLogo address={address} size={90} />
<div>
<h1 className="font-serif text-4xl">{group?.name || '...'}</h1>
<h1 className="overflow-hidden text-ellipsis font-serif text-4xl">
{group?.name || '...'}
</h1>
<div className="mt-2 flex items-center space-x-1.5 sm:space-x-3">
<OutlineButton
className="all:py-1 all:font-normal"
Expand Down
1 change: 1 addition & 0 deletions src/components/charts/chartData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface ChartDataItem {
label: string;
value: number;
percentage?: number;
address?: `0x${string}`;
}

export function sortAndCombineChartData(
Expand Down
5 changes: 3 additions & 2 deletions src/components/text/CopyInline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { useCopyHandler } from 'src/utils/clipboard';

type Props = ButtonHTMLAttributes<HTMLButtonElement> & {
text: string;
textToCopy?: string;
};

export function CopyInline({ text, ...props }: Props) {
const onClick = useCopyHandler(text);
export function CopyInline({ text, textToCopy = text, ...props }: Props) {
const onClick = useCopyHandler(textToCopy);
return (
<button type="button" onClick={onClick} title="Copy" {...props}>
{text}
Expand Down
11 changes: 9 additions & 2 deletions src/components/text/ShortAddress.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import { ButtonHTMLAttributes } from 'react';
import { CopyInline } from 'src/components/text/CopyInline';
import { shortenAddress } from 'src/utils/addresses';
import { normalizeAddress, shortenAddress } from 'src/utils/addresses';

type Props = ButtonHTMLAttributes<HTMLButtonElement> & {
address: Address;
};

export function ShortAddress({ address, ...props }: Props) {
return <CopyInline text={shortenAddress(address)} title="Copy address" {...props} />;
return (
<CopyInline
text={shortenAddress(address)}
textToCopy={normalizeAddress(address)}
title="Copy address"
{...props}
/>
);
}
43 changes: 37 additions & 6 deletions src/config/config.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { ChainId } from 'src/config/chains';
import { celo, celoAlfajores, Chain } from 'viem/chains';

interface Config {
debug: boolean;
version: string | null;
appName: string;
chainId: number;
walletConnectProjectId: string;
fornoApiKey: string;
celoscanApiKey: string;
infuraApiKey: string;
upstashKey: string;
watchBlockNumber: boolean;
isAlfajores: boolean;
chain: Chain;
}

const isDevMode = process?.env?.NODE_ENV === 'development';
Expand All @@ -21,21 +20,53 @@ const fornoApiKey = process?.env?.NEXT_PUBLIC_FORNO_API_KEY || '';
const celoscanApiKey = process?.env?.NEXT_PUBLIC_CELOSCAN_API_KEY || '';
const infuraApiKey = process?.env?.NEXT_PUBLIC_INFURA_API_KEY || '';
const upstashKey = process?.env?.UPSTASH_KEY || '';
const isAlfajores = process?.env?.NEXT_PUBLIC_IS_ALFAJORES === '1' || false;

export const fornoRpcUrl = `https://forno.celo.org?apikey=${fornoApiKey}`;
export const infuraRpcUrl = `https://celo-mainnet.infura.io/v3/${infuraApiKey}`;

const rpcUrl = process?.env?.NEXT_PUBLIC_RPC_URL || celo.rpcUrls.default.http[0];

const isMainnet = [
'mainnet',
celo.rpcUrls.default.http[0],
nicolasbrugneaux marked this conversation as resolved.
Show resolved Hide resolved
process.env.NEXT_PUBLIC_RPC_URL,
].includes(rpcUrl);
const isKnownNetwork = [
'mainnet',
celo.rpcUrls.default.http[0],
process.env.NEXT_PUBLIC_RPC_URL,
'testnet',
'alfajores',
celoAlfajores.rpcUrls.default.http[0],
].includes(rpcUrl);

const chain = {
...(isMainnet ? celo : celoAlfajores),
...(isKnownNetwork
? {}
: {
rpcUrls: {
default: {
http: [rpcUrl],
},
},
testnet: true,
}),
} as Chain;

// TODO: too complex, refactor this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still valid?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still valid need to do it

chain.rpcUrls.default.http = [rpcUrl];

export const config: Config = Object.freeze({
debug: isDevMode,
version,
appName: 'Celo Mondo',
chainId: isAlfajores ? ChainId.Alfajores : ChainId.Celo,
chain,
walletConnectProjectId,
fornoApiKey,
celoscanApiKey,
infuraApiKey,
upstashKey,
watchBlockNumber: false,
isAlfajores,
});
17 changes: 16 additions & 1 deletion src/config/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ import { registryABI } from '@celo/abis-12';
import { config } from 'src/config/config';
import { ZERO_ADDRESS } from 'src/config/consts';
import { createCeloPublicClient } from 'src/utils/client';
import { celo, celoAlfajores } from 'viem/chains';

const UNKNOWN_TESTNET_ADDRESSES = {
Accounts: ZERO_ADDRESS,
Election: ZERO_ADDRESS,
EpochManager: ZERO_ADDRESS,
Governance: ZERO_ADDRESS,
LockedGold: ZERO_ADDRESS,
Validators: ZERO_ADDRESS,
} as const;

const ALFAJORES_ADDRESSES = {
Accounts: '0xed7f51A34B4e71fbE69B3091FcF879cD14bD73A9',
Expand All @@ -23,7 +33,12 @@ const MAINNET_ADDRESSES = {
Validators: '0xaEb865bCa93DdC8F47b8e29F40C5399cE34d0C58',
} as const;

export const Addresses = config.isAlfajores ? ALFAJORES_ADDRESSES : MAINNET_ADDRESSES;
export const Addresses =
config.chain.rpcUrls.default.http[0] === celo.rpcUrls.default.http[0]
? MAINNET_ADDRESSES
: config.chain.rpcUrls.default.http[0] === celoAlfajores.rpcUrls.default.http[0]
? ALFAJORES_ADDRESSES
: UNKNOWN_TESTNET_ADDRESSES;
shazarre marked this conversation as resolved.
Show resolved Hide resolved

export const REGISTRY_ADDRESS = '0x000000000000000000000000000000000000ce10';

Expand Down
Loading
Loading