Skip to content

Commit

Permalink
feat: Remove deprecated networks (#93)
Browse files Browse the repository at this point in the history
* feat: Remove deprecated networks

* feat: Update tests
  • Loading branch information
cyaiox authored May 10, 2024
1 parent 4f385eb commit 20c9a58
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 107 deletions.
40 changes: 18 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ Connect to the Ethereum network with ease
# Table of contents

- [API](#api)
- [ConnectionManager](#ConnectionManager)
- [ConnectionManager](#connectionmanager)
- [connection](#connection)
- [Storage](#Storage)
- [LocalStorage](#LocalStorage)
- [Storage](#storage)
- [LocalStorage](#localstorage)
- [Types](#types)
- [ProviderType](#ProviderType)
- [ChainId](#ChainId)
- [ConnectionResponse](#ConnectionResponse)
- [ProviderType](#providertype)
- [ChainId](#chainid)
- [ConnectionResponse](#connectionresponse)
- [Example](#example)
- [Development](#development)
- [Copyright](#copyright)
Expand All @@ -25,11 +25,11 @@ The API surface is fairly small, you'll mainly be using the exported `connection

## ConnectionManager

Handles the connection to the Ethereum network. It takes a [`Storage`](#Storage) as the only argument, which will be used to store the last used connection.
Handles the connection to the Ethereum network. It takes a [`Storage`](#storage) as the only argument, which will be used to store the last used connection.

### .connect()

Connects to the supplied provider type and chain. It'll default to `mainnet` if no chain is supplied. After a successfull call the params will be stored using the supplied [Storage](#Storage), which will allow you to call `tryPreviousConnection()`.
Connects to the supplied provider type and chain. It'll default to `mainnet` if no chain is supplied. After a successfull call the params will be stored using the supplied [Storage](#storage), which will allow you to call `tryPreviousConnection()`.

**Definition**

Expand All @@ -44,7 +44,7 @@ async connect(

```typescript
const connection = new ConnectionManager(new Storage())
await connection.connect(ProviderType.INJECTED, ChainId.ETHEREUM_ROPSTEN)
await connection.connect(ProviderType.INJECTED, ChainId.ETHEREUM_SEPOLIA)
```

### .tryPreviousConnection()
Expand All @@ -62,9 +62,9 @@ async tryPreviousConnection(): Promise<ConnectionResponse>
```typescript
// Calls connect first
const connection = new ConnectionManager(new Storage())
await connection.connect(ProviderType.INJECTED, ChainId.ETHEREUM_ROPSTEN)
await connection.connect(ProviderType.INJECTED, ChainId.ETHEREUM_SEPOLIA)

await connection.tryPreviousConnection() // Connects with ProviderType.INJECTED ChainId.ETHEREUM.ROPSTEN
await connection.tryPreviousConnection() // Connects with ProviderType.INJECTED ChainId.ETHEREUM.SEPOLIA
```

### .disconnect()
Expand All @@ -81,7 +81,7 @@ async disconnect()

```typescript
const connection = new ConnectionManager(new Storage())
connection.connect(ProviderType.INJECTED, ChainId.ETHEREUM_ROPSTEN)
connection.connect(ProviderType.INJECTED, ChainId.ETHEREUM_SEPOLIA)

// (...)

Expand All @@ -90,7 +90,7 @@ connection.disconnect()

### .getConnectionData()

Returns the data used for the last successfull [.connect()](#connect) call. It's used by [.tryPreviousConnection](#trypreviousconnection) to determine which connection to use. Check [ConnectionData](#ConnectionData) for more info on the returned type
Returns the data used for the last successfull [.connect()](#connect) call. It's used by [.tryPreviousConnection](#trypreviousconnection) to determine which connection to use. Check [ConnectionData](#connectiondata) for more info on the returned type

**Definition**

Expand All @@ -102,7 +102,7 @@ getConnectionData(): ConnectionData | undefined

```typescript
const connection = new ConnectionManager(new Storage())
connection.connect(ProviderType.INJECTED, ChainId.ETHEREUM_ROPSTEN)
connection.connect(ProviderType.INJECTED, ChainId.ETHEREUM_SEPOLIA)

// (...)

Expand Down Expand Up @@ -159,13 +159,13 @@ async createProvider(
```typescript
const provider = await connection.createProvider(
Provider.FORTMATIC,
ChainId.ETHEREUM_ROPSTEN
ChainId.ETHEREUM_SEPOLIA
)
```
## connection
Instance of [`ConnectionManager`](#ConnectionManager), using [`LocalStorage`](#LocalStorage) as it's internal storage engine, which translates to:
Instance of [`ConnectionManager`](#connectionmanager), using [`LocalStorage`](#localstorage) as it's internal storage engine, which translates to:
```typescript
export const connection = new ConnectionMager(new LocalStorage())
Expand Down Expand Up @@ -207,13 +207,9 @@ Different Ethereum chains
```typescript
enum ChainId {
ETHEREUM_MAINNET = 0x1,
ETHEREUM_ROPSTEN = 0x3,
ETHEREUM_RINKEBY = 0x4,
ETHEREUM_GOERLI = 0x5,
ETHEREUM_KOVAN = 0x45,
MATIC_MUMBAI = 0x13881,
MATIC_AMOY = 0x13882,
ETHEREUM_SEPOLIA = 0xaa36a7,
MATIC_MAINNET = 0x89
MATIC_AMOY = 0x13882,
}
```
Expand Down
17 changes: 1 addition & 16 deletions src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ const configuration = Object.freeze({
[ProviderType.FORTMATIC]: {
apiKeys: {
[ChainId.ETHEREUM_MAINNET]: 'pk_live_F8E24DF8DD5BCBC5',
[ChainId.ETHEREUM_ROPSTEN]: 'pk_test_5B728BEFE5C10911',
[ChainId.ETHEREUM_RINKEBY]: 'pk_test_5B728BEFE5C10911',
[ChainId.ETHEREUM_KOVAN]: 'pk_test_5B728BEFE5C10911',
[ChainId.ETHEREUM_GOERLI]: 'pk_test_5B728BEFE5C10911',
[ChainId.ETHEREUM_SEPOLIA]: 'pk_test_5B728BEFE5C10911'
},
urls: getRpcUrls(ProviderType.FORTMATIC)
Expand Down Expand Up @@ -42,13 +38,9 @@ const configuration = Object.freeze({
ChainId.FANTOM_MAINNET
]
},
[ChainId.ETHEREUM_GOERLI]: {
chains: [ChainId.ETHEREUM_GOERLI],
optionalChains: [ChainId.MATIC_MUMBAI, ChainId.MATIC_AMOY]
},
[ChainId.ETHEREUM_SEPOLIA]: {
chains: [ChainId.ETHEREUM_SEPOLIA],
optionalChains: [ChainId.MATIC_MUMBAI, ChainId.MATIC_AMOY]
optionalChains: [ChainId.MATIC_AMOY]
}
}
},
Expand All @@ -57,10 +49,8 @@ const configuration = Object.freeze({
urls: getRpcUrls(ProviderType.MAGIC),
chains: [
ChainId.ETHEREUM_MAINNET,
ChainId.ETHEREUM_GOERLI,
ChainId.ETHEREUM_SEPOLIA,
ChainId.MATIC_MAINNET,
ChainId.MATIC_MUMBAI,
ChainId.MATIC_AMOY,
ChainId.OPTIMISM_MAINNET,
ChainId.ARBITRUM_MAINNET,
Expand All @@ -79,12 +69,7 @@ export function getRpcUrls(providerType: ProviderType) {
const rpcUrls = {
[ChainId.ETHEREUM_MAINNET]: 'https://rpc.decentraland.org/mainnet',
[ChainId.ETHEREUM_SEPOLIA]: 'https://rpc.decentraland.org/sepolia',
[ChainId.ETHEREUM_ROPSTEN]: 'https://rpc.decentraland.org/ropsten',
[ChainId.ETHEREUM_RINKEBY]: 'https://rpc.decentraland.org/rinkeby',
[ChainId.ETHEREUM_GOERLI]: 'https://rpc.decentraland.org/goerli',
[ChainId.ETHEREUM_KOVAN]: 'https://rpc.decentraland.org/kovan',
[ChainId.MATIC_MAINNET]: 'https://rpc.decentraland.org/polygon',
[ChainId.MATIC_MUMBAI]: 'https://rpc.decentraland.org/mumbai',
[ChainId.MATIC_AMOY]: 'https://rpc.decentraland.org/amoy',
[ChainId.ARBITRUM_MAINNET]: 'https://rpc.decentraland.org/arbitrum',
[ChainId.OPTIMISM_MAINNET]: 'https://rpc.decentraland.org/optimism',
Expand Down
24 changes: 12 additions & 12 deletions test/ConnectionManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe('ConnectionManager', () => {

const result = await connectionManager.connect(
ProviderType.INJECTED,
ChainId.ETHEREUM_ROPSTEN
ChainId.ETHEREUM_SEPOLIA
)
const activateResult = await stubConnector.activate()

Expand All @@ -84,7 +84,7 @@ describe('ConnectionManager', () => {
},
providerType: ProviderType.INJECTED,
account: activateResult.account,
chainId: ChainId.ETHEREUM_ROPSTEN
chainId: ChainId.ETHEREUM_SEPOLIA
})
)
})
Expand All @@ -95,7 +95,7 @@ describe('ConnectionManager', () => {

const result = await connectionManager.connect(
ProviderType.INJECTED,
ChainId.ETHEREUM_ROPSTEN
ChainId.ETHEREUM_SEPOLIA
)
const { account } = await stubConnector.activate()

Expand All @@ -106,7 +106,7 @@ describe('ConnectionManager', () => {
},
providerType: ProviderType.INJECTED,
account,
chainId: ChainId.ETHEREUM_ROPSTEN
chainId: ChainId.ETHEREUM_SEPOLIA
})
)
})
Expand All @@ -118,12 +118,12 @@ describe('ConnectionManager', () => {

await connectionManager.connect(
ProviderType.NETWORK,
ChainId.ETHEREUM_KOVAN
ChainId.ETHEREUM_SEPOLIA
)

const value = JSON.stringify({
providerType: ProviderType.NETWORK,
chainId: ChainId.ETHEREUM_KOVAN
chainId: ChainId.ETHEREUM_SEPOLIA
})
expect(storage.get(configuration.storageKey)).to.eq(value)
})
Expand Down Expand Up @@ -178,16 +178,16 @@ describe('ConnectionManager', () => {
await connectionManager.connect(ProviderType.INJECTED)

// mock change in the chainId
stubConnector.setChainId(ChainId.ETHEREUM_ROPSTEN)
stubConnector.setChainId(ChainId.ETHEREUM_SEPOLIA)

const result = await connectionManager.tryPreviousConnection()

expect(
getConnectorStub.firstCall.calledWith(ProviderType.INJECTED)
).to.eq(true)
expect(result.chainId).to.eq(ChainId.ETHEREUM_ROPSTEN)
expect(result.chainId).to.eq(ChainId.ETHEREUM_SEPOLIA)
expect(connectionManager.getConnectionData()!.chainId).to.eq(
ChainId.ETHEREUM_ROPSTEN
ChainId.ETHEREUM_SEPOLIA
)
})
})
Expand All @@ -199,12 +199,12 @@ describe('ConnectionManager', () => {

await connectionManager.connect(
ProviderType.INJECTED,
ChainId.ETHEREUM_KOVAN
ChainId.ETHEREUM_SEPOLIA
)

expect(connectionManager.getConnectionData()).to.deep.eq({
providerType: ProviderType.INJECTED,
chainId: ChainId.ETHEREUM_KOVAN
chainId: ChainId.ETHEREUM_SEPOLIA
})
})

Expand Down Expand Up @@ -339,7 +339,7 @@ describe('ConnectionManager', () => {

describe('#buildConnector', () => {
const browser: any = global
const chainId = ChainId.ETHEREUM_KOVAN
const chainId = ChainId.ETHEREUM_SEPOLIA

after(() => {
delete browser.window
Expand Down
Loading

0 comments on commit 20c9a58

Please sign in to comment.