-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for mainnet on web (front-end) (#102)
- Loading branch information
1 parent
45d2eec
commit d061809
Showing
48 changed files
with
830 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,10 @@ | ||
VITE_API_WEBSERVICE_URL=ws://localhost:3000 | ||
VITE_TESTNET_API_WEBSERVICE_URL=ws://localhost:3000 | ||
VITE_MAINNET_API_WEBSERVICE_URL=ws://localhost:3001 | ||
VITE_USE_API_MOCK=false | ||
VITE_GITHUB_URL=https://github.com/BVM-priv/CryptoChords/ | ||
VITE_CONTRIBUTORS_URL=https://github.com/BVM-priv/CryptoChords/blob/master/CONTRIBUTING.md | ||
VITE_FEEDBACK_URL=https://github.com/BVM-priv/CryptoChords/issues/new | ||
VITE_DISCORD_URL=https://discord.gg/RyhaPp7NvQ | ||
VITE_X_URL=https://x.com/hemi_xyz | ||
VITE_LOGO_URL=https://x.com/hemi_xyz | ||
VITE_EXPLORER_ETH_URL=https://testnet.explorer.hemi.xyz/tx/\${hash} | ||
VITE_EXPLORER_POP_URL=https://testnet.explorer.hemi.xyz/tx/\${hash} | ||
VITE_EXPLORER_BTC_URL=https://testnet.explorer.hemi.xyz/tx/\${hash} | ||
VITE_EXPLORER_BLOCK_URL=https://testnet.explorer.hemi.xyz/block/\${hash} | ||
VITE_ENABLE_MAINNET=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
VITE_API_WEBSERVICE_URL=wss://\${host}/api/testnet | ||
VITE_USE_API_MOCK=false | ||
VITE_TESTNET_API_WEBSERVICE_URL=wss://\${host}/api/testnet | ||
VITE_MAINNET_API_WEBSERVICE_URL=wss://\${host}/api/mainnet | ||
VITE_USE_API_MOCK=false | ||
VITE_ENABLE_MAINNET=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
apps/web/src/application/services/CreateTransaction/CreateTransactionDtos.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export interface CreateTransactionRequest { | ||
txType: string | ||
address: string | ||
network: string | ||
timestamp: number | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
apps/web/src/application/services/GetSelectedNetwork/GetSelectedNetworkResponseDto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface GetSelectedNetworkResponseDto { | ||
networkName: string | ||
networkWsUrl: string | ||
} |
22 changes: 22 additions & 0 deletions
22
apps/web/src/application/services/GetSelectedNetwork/GetSelectedNetworkService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { NetworkRepository } from '../../../domain/repositories/NetworkRepository' | ||
import { ObservableService } from '../../ObservableService' | ||
import { GetSelectedNetworkResponseDto } from './GetSelectedNetworkResponseDto' | ||
|
||
export class GetSelectedNetworkService extends ObservableService<void, GetSelectedNetworkResponseDto> { | ||
private readonly netwtorkRepository: NetworkRepository | ||
|
||
constructor( | ||
networkRepository: NetworkRepository, | ||
) { | ||
super() | ||
this.netwtorkRepository = networkRepository | ||
} | ||
|
||
protected async process(): Promise<GetSelectedNetworkResponseDto> { | ||
const network = await this.netwtorkRepository.getSelected() | ||
return { | ||
networkName: network.name, | ||
networkWsUrl: network.wsUrl, | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
apps/web/src/application/services/ListNetworks/ListNetworksResponseDto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { NetworkDto } from './NetworkDto' | ||
|
||
export interface ListNetworksResponseDto { | ||
networks: NetworkDto[] | ||
} | ||
|
30 changes: 30 additions & 0 deletions
30
apps/web/src/application/services/ListNetworks/ListNetworksService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { NetworkRepository } from '../../../domain/repositories/NetworkRepository' | ||
import { ObservableService } from '../../ObservableService' | ||
import { ListNetworksResponseDto } from './ListNetworksResponseDto' | ||
|
||
|
||
export class ListNetworksService extends ObservableService<void, ListNetworksResponseDto> { | ||
private readonly networkRepository: NetworkRepository | ||
|
||
constructor( | ||
networkRepository: NetworkRepository, | ||
) { | ||
super() | ||
this.networkRepository = networkRepository | ||
} | ||
|
||
protected async process(): Promise<ListNetworksResponseDto> { | ||
const [networks, selectedNetwork] = await Promise.all([ | ||
this.networkRepository.list(), | ||
this.networkRepository.getSelected() | ||
]) | ||
|
||
return { | ||
networks: networks.map(network => ({ | ||
name: network.name, | ||
wsUrl: network.wsUrl, | ||
selected: network.name === selectedNetwork.name, | ||
})) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
export interface NetworkDto { | ||
name: string | ||
wsUrl: string | ||
selected: boolean | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
apps/web/src/application/services/SwitchNetwork/SwitchNetworkRequestDto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface SwitchNetworkRequestDto { | ||
networkName: string | ||
} |
4 changes: 4 additions & 0 deletions
4
apps/web/src/application/services/SwitchNetwork/SwitchNetworkResponseDto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface SwitchNetworkResponseDto { | ||
networkName: string, | ||
networkWsUrl: string | ||
} |
53 changes: 53 additions & 0 deletions
53
apps/web/src/application/services/SwitchNetwork/SwitchNetworkService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { NetworkEnum } from '@cryptochords/shared' | ||
import { Network } from '../../../domain/entities/Network' | ||
import { CubeRepository } from '../../../domain/repositories/CubeRepository' | ||
import { NetworkRepository } from '../../../domain/repositories/NetworkRepository' | ||
import { TransactionRepository } from '../../../domain/repositories/TransactionRepository' | ||
import { ObservableService } from '../../ObservableService' | ||
import { SwitchNetworkRequestDto } from './SwitchNetworkRequestDto' | ||
import { SwitchNetworkResponseDto } from './SwitchNetworkResponseDto' | ||
|
||
export class SwitchNetworkService extends ObservableService<SwitchNetworkRequestDto, SwitchNetworkResponseDto> { | ||
private readonly transactionRepository: TransactionRepository | ||
private readonly networkRepository: NetworkRepository | ||
private readonly cubeRepository: CubeRepository | ||
|
||
constructor( | ||
transactionRepository: TransactionRepository, | ||
networkRepository: NetworkRepository, | ||
cubeRepository: CubeRepository | ||
) { | ||
super() | ||
this.transactionRepository = transactionRepository | ||
this.networkRepository = networkRepository | ||
this.cubeRepository = cubeRepository | ||
} | ||
|
||
protected async process(request: SwitchNetworkRequestDto): Promise<SwitchNetworkResponseDto> { | ||
const network = await this.validateNetwork(request.networkName) | ||
await Promise.all([ | ||
this.transactionRepository.clear(), | ||
this.cubeRepository.clear(), | ||
this.networkRepository.select(network.name) | ||
]) | ||
|
||
return { | ||
networkName: network.name, | ||
networkWsUrl: network.wsUrl | ||
} | ||
} | ||
|
||
private async validateNetwork(networkName: string): Promise<Network> { | ||
if (!networkName) { | ||
throw new Error('Network not found') | ||
} | ||
|
||
const network = await this.networkRepository.find(networkName as NetworkEnum) | ||
|
||
if (!network) { | ||
throw new Error('Network not found') | ||
} | ||
|
||
return network | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import { Network } from './Network'; | ||
import { NetworkEnum } from '../../../../../packages/shared/src/domain/enums/NetworkEnum'; | ||
import { Uuid } from '../../../../../packages/shared/src/domain/valueObjects/Uuid'; | ||
|
||
describe('Network', () => { | ||
const mockProps = { | ||
name: NetworkEnum.MAINNET, | ||
explorerUrl: 'https://explorer.mainnet.com', | ||
wsUrl: 'wss://mainnet.ws.com', | ||
}; | ||
|
||
it('should create a Network instance with default UUID', () => { | ||
const network = Network.create(mockProps); | ||
expect(network).toBeInstanceOf(Network); | ||
expect(network.name).toBe(NetworkEnum.MAINNET); | ||
expect(network.explorerUrl).toBe(mockProps.explorerUrl); | ||
expect(network.wsUrl).toBe(mockProps.wsUrl); | ||
expect(network.transactionUrl).toBe(`${mockProps.explorerUrl}/tx`); | ||
expect(network.blockUrl).toBe(`${mockProps.explorerUrl}/block`); | ||
}); | ||
|
||
it('should create a Network instance with a provided UUID', () => { | ||
const uuid = Uuid.create(); | ||
const network = Network.create(mockProps, uuid); | ||
expect(network).toBeInstanceOf(Network); | ||
expect(network.name).toBe(NetworkEnum.MAINNET); | ||
expect(network.explorerUrl).toBe(mockProps.explorerUrl); | ||
expect(network.wsUrl).toBe(mockProps.wsUrl); | ||
expect(network.transactionUrl).toBe(`${mockProps.explorerUrl}/tx`); | ||
expect(network.blockUrl).toBe(`${mockProps.explorerUrl}/block`); | ||
}); | ||
|
||
it('should return correct URLs for transactions and blocks', () => { | ||
const network = Network.create(mockProps); | ||
expect(network.transactionUrl).toBe(`${mockProps.explorerUrl}/tx`); | ||
expect(network.blockUrl).toBe(`${mockProps.explorerUrl}/block`); | ||
}); | ||
}); |
Oops, something went wrong.