Skip to content

Commit

Permalink
chore(examples): switch browser wallets to mumbai testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-roslaniec committed Sep 25, 2023
1 parent 40b846d commit 51f2439
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 56 deletions.
46 changes: 4 additions & 42 deletions examples/nextjs/README.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,10 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with
[`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
# `nextjs` integration example

## Getting Started
Shows how to use `@nucypher/pre` in Next.js.

First, run the development server:
## Usage

```bash
npm run dev
# or
yarn dev
# or
pnpm install
pnpm dev
# or
bun dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the
result.

You can start editing the page by modifying `app/page.tsx`. The page
auto-updates as you edit the file.

This project uses
[`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to
automatically optimize and load Inter, a custom Google Font.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js
features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out
[the Next.js GitHub repository](https://github.com/vercel/next.js/) - your
feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the
[Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme)
from the creators of Next.js.

Check out our
[Next.js deployment documentation](https://nextjs.org/docs/deployment) for more
details.
22 changes: 13 additions & 9 deletions examples/nextjs/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
SecretKey,
toHexString,
} from '@nucypher/shared';
import { ethers } from 'ethers';
import { useEffect, useState } from 'react';
import {ethers} from 'ethers';
import {useEffect, useState} from 'react';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
declare const window: any;
Expand All @@ -34,9 +34,13 @@ function App() {
}
const provider = new ethers.providers.Web3Provider(window.ethereum, 'any');

const { chainId } = await provider.getNetwork();
if (![137, 80001].includes(chainId)) {
console.error('You need to connect to the Mumbai or Polygon network');
const {chainId} = await provider.getNetwork();
if (chainId !== 80001) {
// Switch to Matic Mumbai testnet
await window.ethereum.request({
method: 'wallet_switchEthereumChain',
params: [{chainId: '0x13881'}],
});
}

await provider.send('eth_requestAccounts', []);
Expand All @@ -52,7 +56,7 @@ function App() {
return <div>Loading...</div>;
}

console.log({ Alice, Bob, getPorterUri, SecretKey, toHexString });
console.log({Alice, Bob, getPorterUri, SecretKey, toHexString});

const makeAlice = () => {
const alice = Alice.fromSecretKey(SecretKey.random());
Expand All @@ -65,8 +69,8 @@ function App() {
};

const makeRemoteBob = (bob: Bob) => {
const { decryptingKey, verifyingKey } = bob;
return { decryptingKey, verifyingKey };
const {decryptingKey, verifyingKey} = bob;
return {decryptingKey, verifyingKey};
};

const makeCharacters = () => {
Expand All @@ -78,7 +82,7 @@ function App() {

const runExample = async () => {
if (!provider) {
console.error('You need to connect to the MetaMask extension');
console.error('You need to connect to your wallet first');
return;
}

Expand Down
10 changes: 7 additions & 3 deletions examples/react/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ function App() {
}
const provider = new ethers.providers.Web3Provider(window.ethereum, 'any');

const { chainId } = await provider.getNetwork();
if (![137, 80001].includes(chainId)) {
console.error('You need to connect to the Mumbai or Polygon network');
const {chainId} = await provider.getNetwork();
if (chainId !== 80001) {
// Switch to Matic Mumbai testnet
await window.ethereum.request({
method: 'wallet_switchEthereumChain',
params: [{chainId: '0x13881'}],
});
}

await provider.send('eth_requestAccounts', []);
Expand Down
9 changes: 9 additions & 0 deletions examples/webpack-5/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ const runExample = async () => {
const provider = new ethers.providers.Web3Provider(window.ethereum!, 'any');
await provider.send('eth_requestAccounts', []);

const { chainId } = await provider.getNetwork();
if (chainId !== 80001) {
// Switch to Matic Mumbai testnet
await window.ethereum!.request!({
method: 'wallet_switchEthereumChain',
params: [{ chainId: '0x13881' }],
});
}

const remoteBob = makeRemoteBob();
const threshold = 2;
const shares = 3;
Expand Down
7 changes: 6 additions & 1 deletion packages/shared/test/integration/pre.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { CapsuleFrag, reencrypt } from '@nucypher/nucypher-core';
import {fakeAlice, fakeBob, fakeUrsulas, reencryptKFrags} from '@nucypher/test-utils';
import {
fakeAlice,
fakeBob,
fakeUrsulas,
reencryptKFrags,
} from '@nucypher/test-utils';
import { beforeAll, expect, test } from 'vitest';

import {
Expand Down
3 changes: 2 additions & 1 deletion packages/shared/test/unit/conditions/base/contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ test('supports custom function abi', () => {
});

test('accepts custom function abi with a custom parameter', async () => {
const asJson = await conditionExpr.buildContext(fakeProvider(), {}, fakeSigner())
const asJson = await conditionExpr
.buildContext(fakeProvider(), {}, fakeSigner())
.withCustomParams(customParams)
.toJson();

Expand Down

0 comments on commit 51f2439

Please sign in to comment.