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

Add support for Nexus API as a backend option for Wallet #2076

Merged
merged 19 commits into from
Nov 6, 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
1 change: 1 addition & 0 deletions .changelog/2076.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for Nexus API as a backend option for Wallet
8 changes: 7 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
"src/vendors/oasisscan/.openapi-generator": true,
"src/vendors/oasisscan/.openapi-generator-ignore": true,
"src/vendors/oasisscan/runtime.ts": true,
"src/vendors/oasisscan/index.ts": true
"src/vendors/oasisscan/index.ts": true,
"src/vendors/nexus/apis": true,
"src/vendors/nexus/models": true,
"src/vendors/nexus/.openapi-generator": true,
"src/vendors/nexus/.openapi-generator-ignore": true,
"src/vendors/nexus/runtime.ts": true,
"src/vendors/nexus/index.ts": true
}
}
2 changes: 2 additions & 0 deletions internals/getSecurityHeaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ const getCsp = ({ isExtension, isDev }) =>
https://grpc.oasis.io
https://testnet.grpc.oasis.io
https://api.oasisscan.com
https://nexus.oasis.io
https://testnet.nexus.oasis.io
${isDev ? localnet : ''}
${isDev ? hmr : ''}
;
Expand Down
1 change: 1 addition & 0 deletions src/app/components/ErrorFormatter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export function ErrorFormatter(props: Props) {
const backendToLabel = {
[BackendAPIs.OasisMonitor]: t('backends.oasismonitor', 'Oasis Monitor API'),
[BackendAPIs.OasisScan]: t('backends.oasisscan', 'Oasis Scan API'),
[BackendAPIs.Nexus]: t('backends.nexus', 'Nexus API'),
}

const errorMap: { [code in WalletErrors]: string | React.ReactElement } = {
Expand Down
1 change: 1 addition & 0 deletions src/app/components/Footer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const Footer = memo(() => {
const backendToLabel = {
[BackendAPIs.OasisMonitor]: t('footer.poweredBy.oasismonitor', 'Oasis Monitor API & Oasis gRPC'),
[BackendAPIs.OasisScan]: t('footer.poweredBy.oasisscan', 'Oasis Scan API & Oasis gRPC'),
[BackendAPIs.Nexus]: t('footer.poweredBy.nexus', 'Nexus API & Oasis gRPC'),
}
const poweredByLabel = backendToLabel[backend()]

Expand Down
5 changes: 5 additions & 0 deletions src/app/lib/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,8 @@ export const getDefaultFeeAmount = (isDepositing: boolean, paraTimeConfig: ParaT
export function parseConsensusToLayerBaseUnit(feeAmount: string, decimals: number): BigNumber {
return new BigNumber(feeAmount).shiftedBy(decimals).shiftedBy(-consensusDecimals)
}

export function removeTrailingZeros(value: string, zeros: number): string {
const bigValue = new BigNumber(value)
return bigValue.dividedBy(new BigNumber(10).pow(zeros)).toFixed()
}
24 changes: 22 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const consensusDecimals = 9
export enum BackendAPIs {
OasisMonitor = 'oasismonitor',
OasisScan = 'oasisscan',
Nexus = 'nexus',
}

type BackendApiUrls = {
Expand All @@ -23,6 +24,7 @@ type BackendProviders = {
min_delegation: number // from nic.stakingConsensusParameters().min_delegation
[BackendAPIs.OasisMonitor]: BackendApiUrls
[BackendAPIs.OasisScan]: BackendApiUrls
[BackendAPIs.Nexus]: BackendApiUrls
}

type BackendConfig = {
Expand All @@ -44,6 +46,12 @@ export const config: BackendConfig = {
blockExplorerParatimes: 'https://oasisscan.com/paratimes/transactions/{{txHash}}?runtime={{runtimeId}}',
blockExplorerAccount: 'https://www.oasisscan.com/accounts/detail/{{address}}',
},
[BackendAPIs.Nexus]: {
explorer: 'https://nexus.oasis.io/v1',
blockExplorer: 'https://oasisscan.com/transactions/{{txHash}}',
blockExplorerParatimes: 'https://explorer.oasis.io/mainnet/{{runtimeId}}/tx/{{txHash}}',
blockExplorerAccount: 'https://www.oasisscan.com/accounts/detail/{{address}}',
},
},
testnet: {
grpc: 'https://testnet.grpc.oasis.io',
Expand All @@ -56,8 +64,13 @@ export const config: BackendConfig = {
[BackendAPIs.OasisScan]: {
explorer: 'https://api.oasisscan.com/testnet',
blockExplorer: 'https://testnet.oasisscan.com/transactions/{{txHash}}',
blockExplorerParatimes:
'https://testnet.oasisscan.com/paratimes/transactions/{{txHash}}?runtime={{runtimeId}}',
blockExplorerParatimes: 'https://testnet.oasisscan.com/paratimes/tx/{{txHash}}',
blockExplorerAccount: 'https://testnet.oasisscan.com/accounts/detail/{{address}}',
},
[BackendAPIs.Nexus]: {
explorer: 'https://testnet.nexus.oasis.io/v1',
blockExplorer: 'https://testnet.oasisscan.com/transactions/{{txHash}}',
blockExplorerParatimes: 'https://explorer.oasis.io/testnet/{{runtimeId}}/transactions/{{txHash}}',
blockExplorerAccount: 'https://testnet.oasisscan.com/accounts/detail/{{address}}',
},
},
Expand All @@ -76,6 +89,13 @@ export const config: BackendConfig = {
'http://localhost:9001/data/paratimes/transactions/{{txHash}}?runtime={{runtimeId}}',
blockExplorerAccount: 'http://localhost:9001/data/accounts/detail/{{address}}',
},
[BackendAPIs.Nexus]: {
explorer: 'http://localhost:9001',
blockExplorer: 'http://localhost:9001/data/transactions?operation_id={{txHash}}',
blockExplorerParatimes:
'http://localhost:9001/data/paratimes/transactions/{{txHash}}?runtime={{runtimeId}}',
blockExplorerAccount: 'http://localhost:9001/data/accounts/detail/{{address}}',
},
},
}

Expand Down
6 changes: 4 additions & 2 deletions src/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@
"appTitle": "ROSE Wallet",
"backends": {
"oasismonitor": "Oasis Monitor API",
"oasisscan": "Oasis Scan API"
"oasisscan": "Oasis Scan API",
"nexus": "Nexus API"
},
"banner": {
"buildPreview": "Please note this is an experimental build of ROSE Wallet and your secrets are not safe. ONLY USE IT FOR TESTING.",
Expand Down Expand Up @@ -198,7 +199,8 @@
"github": "ROSE Wallet is <GithubLink>open source</GithubLink> and powered by",
"poweredBy": {
"oasismonitor": "Oasis Monitor API & Oasis gRPC",
"oasisscan": "Oasis Scan API & Oasis gRPC"
"oasisscan": "Oasis Scan API & Oasis gRPC",
"nexus": "Nexus API & Oasis gRPC"
},
"terms": "<TermsLink>Terms and Conditions</TermsLink>",
"version": "Version: <ReleaseLink/> (commit: <CommitLink/>) built at {{buildTime}}"
Expand Down
2 changes: 1 addition & 1 deletion src/types/env.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
declare namespace NodeJS {
export interface ProcessEnv {
REACT_APP_BACKEND: 'oasismonitor' | 'oasisscan'
REACT_APP_BACKEND: 'oasismonitor' | 'oasisscan' | 'nexus'
REACT_APP_TRANSAK_URL: string
REACT_APP_TRANSAK_PARTNER_ID: string
REACT_APP_LOCALNET: '1' | undefined
Expand Down
2 changes: 2 additions & 0 deletions src/vendors/backend.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { getMonitorAPIs } from 'vendors/monitor'
import { getOasisscanAPIs } from 'vendors/oasisscan'
import { getNexusAPIs } from 'vendors/nexus'
import { BackendAPIs } from 'config'

const backendNameToApi = {
[BackendAPIs.OasisMonitor]: getMonitorAPIs,
[BackendAPIs.OasisScan]: getOasisscanAPIs,
[BackendAPIs.Nexus]: getNexusAPIs,
}

export const backend = () => process.env.REACT_APP_BACKEND || BackendAPIs.OasisMonitor
Expand Down
Loading
Loading