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

1220 add polygon amoy support #1222

Merged
merged 5 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const NotificationScreen = () => {
image: undefined,
url: 'https://push.org/',
theme: 'light',
chainName: 'POLYGON_TEST_MUMBAI',
chainName: 'POLYGON_TEST_AMOY',
cta: 'https://github.com/ethereum-push-notification-service/',
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function extractTimeStamp(notificationBody: string): {

type chainNameType =
| 'ETH_TEST_SEPOLIA'
| 'POLYGON_TEST_MUMBAI'
| 'POLYGON_TEST_AMOY'
| 'ETH_MAINNET'
| 'POLYGON_MAINNET'
| 'BSC_MAINNET'
Expand Down
4 changes: 2 additions & 2 deletions packages/uireactnative/src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ export const GLOBALS = {
label: 'ETHEREUM MAINNET',
icon: EthereumSVG,
},
POLYGON_TEST_MUMBAI: {
label: 'POLYGON MUMBAI',
POLYGON_TEST_AMOY: {
label: 'POLYGON AMOY',
icon: PolygonSVG,
},
POLYGON_MAINNET: {
Expand Down
64 changes: 31 additions & 33 deletions packages/uiweb/src/lib/components/chat/ConnectButton/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { IChatTheme } from '../theme';

import coinbaseWalletModule from '@web3-onboard/coinbase'
import coinbaseWalletModule from '@web3-onboard/coinbase';
import { ConnectButtonSub } from './ConnectButton';
import { BLOCKNATIVE_PROJECT_ID, InfuraAPIKey } from '../../../config';
import { Web3OnboardProvider } from '@web3-onboard/react';
import injectedModule, { ProviderLabel } from '@web3-onboard/injected-wallets';
import walletConnectModule from '@web3-onboard/walletconnect'
import walletConnectModule from '@web3-onboard/walletconnect';
import init from '@web3-onboard/core';
import PushIcon from "../../../icons/Bell.svg"
import PushIcon from '../../../icons/Bell.svg';

const APP_META_DATA = {
name: 'Push Protocol',
Expand All @@ -17,86 +17,84 @@ const APP_META_DATA = {

recommendedInjectedWallets: [
{ name: 'MetaMask', url: 'https://metamask.io' },
]
}
],
};

const wcv2InitOptions = {
projectId: BLOCKNATIVE_PROJECT_ID,
requiredChains: [1, 56]
}
requiredChains: [1, 56],
};

const walletConnect = walletConnectModule(wcv2InitOptions)
const coinbaseWalletSdk = coinbaseWalletModule({ darkMode: true })
const walletConnect = walletConnectModule(wcv2InitOptions);
const coinbaseWalletSdk = coinbaseWalletModule({ darkMode: true });
const CHAINS = [
{
id: '0x1',
token: 'ETH',
label: 'Ethereum Mainnet',
rpcUrl: `https://mainnet.infura.io/v3/${InfuraAPIKey}`
rpcUrl: `https://mainnet.infura.io/v3/${InfuraAPIKey}`,
},
{
id: '0xAA36A7',
token: 'ETH',
label: 'Sepolia',
rpcUrl: `https://sepolia.infura.io/v3/${InfuraAPIKey}`
rpcUrl: `https://sepolia.infura.io/v3/${InfuraAPIKey}`,
},
{
id: '0x13881',
id: '0x13882',
token: 'MATIC',
label: 'Polygon - Mumbai',
rpcUrl: 'https://matic-mumbai.chainstacklabs.com'
label: 'Polygon - Amoy',
rpcUrl: 'https://rpc-amoy.polygon.technology',
},
{
id: '0x38',
token: 'BNB',
label: 'Binance',
rpcUrl: 'https://bsc-dataseed.binance.org/'
rpcUrl: 'https://bsc-dataseed.binance.org/',
},
{
id: '0xA',
token: 'OETH',
label: 'Optimism',
rpcUrl: 'https://mainnet.optimism.io'
rpcUrl: 'https://mainnet.optimism.io',
},
{
id: '0xA4B1',
token: 'ARB-ETH',
label: 'Arbitrum',
rpcUrl: 'https://rpc.ankr.com/arbitrum'
}
]


const wallets = [injectedModule(), walletConnect, coinbaseWalletSdk]


rpcUrl: 'https://rpc.ankr.com/arbitrum',
},
];

const wallets = [injectedModule(), walletConnect, coinbaseWalletSdk];

const web3OnBoard = init({
wallets,
chains:CHAINS,
appMetadata:APP_META_DATA,
chains: CHAINS,
appMetadata: APP_META_DATA,
accountCenter: {
desktop: {
enabled: false
enabled: false,
},
mobile: {
enabled: false
}
enabled: false,
},
},
connect: {
autoConnectLastWallet: true,
}
})
},
});

interface IConnectButtonCompProps {
autoConnect?: boolean;
}

export const ConnectButtonComp: React.FC<IConnectButtonCompProps> = ({ autoConnect }) => {
export const ConnectButtonComp: React.FC<IConnectButtonCompProps> = ({
autoConnect,
}) => {
return (
<Web3OnboardProvider web3Onboard={web3OnBoard}>
<ConnectButtonSub autoConnect={autoConnect} />
</Web3OnboardProvider>
);
};
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { InfuraAPIKey } from "../../../../config";
import { InfuraAPIKey } from '../../../../config';

const getInfuraUrlFor = (network: string, key: string) =>
`https://${network}.infura.io/v3/${key}`;
Expand All @@ -8,26 +8,26 @@ const getRpcURL = (network: string, key: string) => {
};

export const getChainRPC = (chainId: number): string => {
const key = InfuraAPIKey;
const key = InfuraAPIKey;

switch (chainId) {
case 1:
return getRpcURL("mainnet", key);
return getRpcURL('mainnet', key);
case 137:
return getRpcURL("polygon-mainnet", key);
return getRpcURL('polygon-mainnet', key);
case 10:
return getRpcURL("optimism-mainnet", key);
return getRpcURL('optimism-mainnet', key);
case 56:
return "https://bsc-dataseed.binance.org/";
return 'https://bsc-dataseed.binance.org/';
case 11155111:
return getRpcURL("sepolia", key);
return getRpcURL('sepolia', key);
case 11155420:
return getRpcURL("optimism-sepolia", key);
case 80001:
return getRpcURL("polygon-mumbai", key);
return getRpcURL('optimism-sepolia', key);
case 80002:
return getRpcURL('polygon-amoy', key);
case 97:
return "https://data-seed-prebsc-1-s1.binance.org:8545";
return 'https://data-seed-prebsc-1-s1.binance.org:8545';
default:
return getRpcURL("mainnet", key);
return getRpcURL('mainnet', key);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default {
label: 'ETHEREUM MAINNET',
icon: createSVGIcon(<EthereumSvg />, 'Ethereum Mainnet'),
},
POLYGON_TEST_MUMBAI: {
POLYGON_TEST_AMOY: {
label: 'POLYGON AMOY',
icon: createSVGIcon(<PolygonSvg />, 'Polygon Amoy'),
},
Expand Down
74 changes: 39 additions & 35 deletions packages/uiweb/src/lib/components/widget/ConnectButton/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@

import coinbaseWalletModule from '@web3-onboard/coinbase'
import coinbaseWalletModule from '@web3-onboard/coinbase';
import { ConnectButtonSub } from './ConnectButton';
import { BLOCKNATIVE_PROJECT_ID, InfuraAPIKey } from '../../../config';
import { Web3OnboardProvider } from '@web3-onboard/react';
import injectedModule from '@web3-onboard/injected-wallets';
import walletConnectModule from '@web3-onboard/walletconnect'
import walletConnectModule from '@web3-onboard/walletconnect';
import init from '@web3-onboard/core';
import PushIcon from "../../../icons/Bell.svg"
import PushIcon from '../../../icons/Bell.svg';
import { SignerType } from '@pushprotocol/restapi';

const APP_META_DATA = {
Expand All @@ -17,90 +16,95 @@ const APP_META_DATA = {

recommendedInjectedWallets: [
{ name: 'MetaMask', url: 'https://metamask.io' },
]
}
],
};

const wcv2InitOptions = {
projectId: BLOCKNATIVE_PROJECT_ID,
requiredChains: [1, 56]
}
requiredChains: [1, 56],
};

const walletConnect = walletConnectModule(wcv2InitOptions)
const coinbaseWalletSdk = coinbaseWalletModule({ darkMode: true })
const walletConnect = walletConnectModule(wcv2InitOptions);
const coinbaseWalletSdk = coinbaseWalletModule({ darkMode: true });
const CHAINS = [
{
id: '0x1',
token: 'ETH',
label: 'Ethereum Mainnet',
rpcUrl: `https://mainnet.infura.io/v3/${InfuraAPIKey}`
rpcUrl: `https://mainnet.infura.io/v3/${InfuraAPIKey}`,
},
{
id: '0xAA36A7',
token: 'ETH',
label: 'Sepolia',
rpcUrl: `https://sepolia.infura.io/v3/${InfuraAPIKey}`
rpcUrl: `https://sepolia.infura.io/v3/${InfuraAPIKey}`,
},
{
id: '0x13881',
token: 'MATIC',
label: 'Polygon - Mumbai',
rpcUrl: 'https://matic-mumbai.chainstacklabs.com'
label: 'Polygon - Amoy',
rpcUrl: 'https://rpc-amoy.polygon.technology',
},
{
id: '0x38',
token: 'BNB',
label: 'Binance',
rpcUrl: 'https://bsc-dataseed.binance.org/'
rpcUrl: 'https://bsc-dataseed.binance.org/',
},
{
id: '0xA',
token: 'OETH',
label: 'Optimism',
rpcUrl: 'https://mainnet.optimism.io'
rpcUrl: 'https://mainnet.optimism.io',
},
{
id: '0xA4B1',
token: 'ARB-ETH',
label: 'Arbitrum',
rpcUrl: 'https://rpc.ankr.com/arbitrum'
}
]


const wallets = [injectedModule(), walletConnect, coinbaseWalletSdk]


rpcUrl: 'https://rpc.ankr.com/arbitrum',
},
];

const wallets = [injectedModule(), walletConnect, coinbaseWalletSdk];

const web3OnBoard = init({
wallets,
chains:CHAINS,
appMetadata:APP_META_DATA,
chains: CHAINS,
appMetadata: APP_META_DATA,
accountCenter: {
desktop: {
enabled: false
enabled: false,
},
mobile: {
enabled: false
}
enabled: false,
},
},
connect: {
autoConnectLastWallet: true,
},
})
});

interface IConnectButtonCompProps {
autoconnect?: boolean;
setAccount: React.Dispatch<React.SetStateAction<string| null>>;
setAccount: React.Dispatch<React.SetStateAction<string | null>>;
signer: SignerType | undefined;
setSigner: React.Dispatch<React.SetStateAction<SignerType | undefined>>;

}

export const ConnectButtonComp: React.FC<IConnectButtonCompProps> = ({ autoconnect,setAccount,setSigner,signer }) => {
export const ConnectButtonComp: React.FC<IConnectButtonCompProps> = ({
autoconnect,
setAccount,
setSigner,
signer,
}) => {
return (
<Web3OnboardProvider web3Onboard={web3OnBoard}>
<ConnectButtonSub autoconnect={autoconnect} setAccount={setAccount} setSigner={setSigner} signer={signer} />
<ConnectButtonSub
autoconnect={autoconnect}
setAccount={setAccount}
setSigner={setSigner}
signer={signer}
/>
</Web3OnboardProvider>
);
};
};
6 changes: 3 additions & 3 deletions packages/uiweb/src/lib/config/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const allowedNetworks = {
],
dev: [
11155111, // for eth sepolia
80002, //for mumbai amoy
80002, //for polygon amoy
97, // bnb testnet
11155420, // optimism sepolia testnet
421614, // for arbitrum testnet
Expand All @@ -99,7 +99,7 @@ export const allowedNetworks = {
staging: [
// 42, //for kovan
11155111, // for sepolia
80002, //for mumbai amoy
80002, //for polygon amoy
97, // bnb testnet
11155420, // optimism sepolia testnet
421614, // for arbitrum testnet
Expand All @@ -108,7 +108,7 @@ export const allowedNetworks = {
],
local: [
11155111, // for eth sepolia
80002, //for mumbai amoy
80002, //for polygon amoy
97, // bnb testnet
11155420, // optimism sepolia testnet
421614, // for arbitrum testnet
Expand Down
2 changes: 1 addition & 1 deletion packages/uiweb/src/lib/helpers/udResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { Env } from '@pushprotocol/restapi';

export const getUdResolver = (env:Env): Resolution => {
const l1ChainId = allowedNetworks[env].includes(1) ? 1 : 5;
const l2ChainId = allowedNetworks[env].includes(137) ? 137 : 80001;
const l2ChainId = allowedNetworks[env].includes(137) ? 137 : 80002;
// ToDo: Enable for sepolia chainId once UD supports it
// const l1ChainId = appConfig.allowedNetworks.includes(1) ? 1 : 11155111;
return Resolution.fromEthersProvider({
Expand Down
Loading