Skip to content

Commit

Permalink
Merge pull request #2075 from oasisprotocol/mz/api-oasisscan2
Browse files Browse the repository at this point in the history
Add support for Oasis Scan API v2 as a backend option for Wallet
  • Loading branch information
buberdds authored Nov 13, 2024
2 parents 5e30074 + 52e8cbd commit 67dfd2c
Show file tree
Hide file tree
Showing 120 changed files with 14,238 additions and 2 deletions.
1 change: 1 addition & 0 deletions .changelog/2075.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for Oasis Scan API v2 as a backend option for Wallet
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
"src/vendors/oasisscan/.openapi-generator-ignore": true,
"src/vendors/oasisscan/runtime.ts": true,
"src/vendors/oasisscan/index.ts": true,
"src/vendors/oasisscan-v2/apis": true,
"src/vendors/oasisscan-v2/models": true,
"src/vendors/oasisscan-v2/.openapi-generator": true,
"src/vendors/oasisscan-v2/.openapi-generator-ignore": true,
"src/vendors/oasisscan-v2/runtime.ts": true,
"src/vendors/oasisscan-v2/index.ts": true,
"src/vendors/nexus/apis": true,
"src/vendors/nexus/models": true,
"src/vendors/nexus/.openapi-generator": true,
Expand Down
17 changes: 17 additions & 0 deletions playwright/tests/oasis-scan-v2.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { test, expect } from '@playwright/test'

test('validate if API is missing historical data', async ({ request }) => {
const expectedResponse = {
code: 0,
message: 'OK',
data: null,
}

const response = await request.get('https://www.oasisscan.com/v2/mainnet/chain/block/16817955')
if (response.status() === 200) {
const jsonResponse = await response.json()
expect(jsonResponse).toEqual(expectedResponse)
} else {
console.warn(`Skipping V2 test due to API issues: ${response.status()}`)
}
})
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.OasisScanV2]: t('backends.oasisscanV2', 'Oasis Scan API v2'),
[BackendAPIs.Nexus]: t('backends.nexus', 'Nexus API'),
}

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.OasisScanV2]: t('footer.poweredBy.oasisscanV2', 'Oasis Scan API v2 & Oasis gRPC'),
[BackendAPIs.Nexus]: t('footer.poweredBy.nexus', 'Nexus API & Oasis gRPC'),
}
const poweredByLabel = backendToLabel[backend()]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,16 @@ const getState = ({
}

describe('<TransactionHistory />', () => {
const originalEnv = process.env.REACT_APP_BACKEND
beforeEach(() => {
// Ignore dispatches to fetch account from AccountPage
jest.mocked(useDispatch).mockImplementation(() => jest.fn())
})

afterEach(() => {
process.env.REACT_APP_BACKEND = originalEnv
})

it('should not display any pending or completed txs', async () => {
renderCmp(getState())

Expand All @@ -110,6 +115,13 @@ describe('<TransactionHistory />', () => {
)
})

it('should display different no transactions message for Oasis Scan v2', async () => {
process.env.REACT_APP_BACKEND = 'oasisscanV2'
renderCmp(getState({ accountNonce: 1n }))

expect(await screen.findByText('account.summary.noTransactionFoundOasisscanV2')).toBeInTheDocument()
})

it('should display pending txs alert with single pending tx and no completed transactions', async () => {
renderCmp(getState({ accountNonce: 0n, pendingLocalTxs: [getPendingTx('txHash1')] }))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,13 @@ export function TransactionHistory() {
background="background-front"
pad="large"
>
<Text>{t('account.summary.noTransactionFound', 'No transactions found.')}</Text>
{process.env.REACT_APP_BACKEND === 'oasisscanV2' ? (
<Text>
{t('account.summary.noTransactionFoundOasisscanV2', 'No transactions since November 29, 2023.')}
</Text>
) : (
<Text>{t('account.summary.noTransactionFound', 'No transactions found.')}</Text>
)}
</Box>
)}
</Box>
Expand Down
7 changes: 7 additions & 0 deletions src/app/state/account/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ export const selectPendingTransactionForAccount = createSelector(
export const hasAccountUnknownPendingTransactions = createSelector(
[selectAccountNonce, selectTransactions, selectAccountAddress],
(accountNonce, transactions, accountAddress) => {
if (!transactions.length && accountNonce && process.env.REACT_APP_BACKEND === 'oasisscanV2') {
// Don't bother when tx list is empty in this case. Oasis Scan v2 API is missing historical data.
// Account have nonce and 0 transactions due to last correctly indexed block 16817956 (2023-11-29)
return false
}
const noncesFromTxs = transactions
.filter(tx => !tx.runtimeId)
.filter(tx => tx.from !== undefined)
Expand All @@ -36,6 +41,8 @@ export const hasAccountUnknownPendingTransactions = createSelector(
if (noncesFromTxs.length <= 0) {
// TODO: last transaction that affected nonce is not in the initial page of account's transactions
if (transactions.length >= TRANSACTIONS_LIMIT) return false
// if we cannot find any noncesFromTxs this probably means that account is missing some part of historical data
if (!noncesFromTxs.length && process.env.REACT_APP_BACKEND === 'oasisscanV2') return false
// Waiting for first transactions
return BigInt(accountNonce) > 0n
}
Expand Down
22 changes: 22 additions & 0 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',
OasisScanV2 = 'oasisscanV2',
Nexus = 'nexus',
}

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

Expand All @@ -46,6 +48,12 @@ export const config: BackendConfig = {
blockExplorerParatimes: 'https://oasisscan.com/paratimes/transactions/{{txHash}}?runtime={{runtimeId}}',
blockExplorerAccount: 'https://www.oasisscan.com/accounts/detail/{{address}}',
},
[BackendAPIs.OasisScanV2]: {
explorer: 'https://api.oasisscan.com/v2/mainnet',
blockExplorer: 'https://oasisscan.com/transactions/{{txHash}}',
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}}',
Expand All @@ -67,6 +75,13 @@ export const config: BackendConfig = {
blockExplorerParatimes: 'https://testnet.oasisscan.com/paratimes/tx/{{txHash}}',
blockExplorerAccount: 'https://testnet.oasisscan.com/accounts/detail/{{address}}',
},
[BackendAPIs.OasisScanV2]: {
explorer: 'https://api.oasisscan.com/testnet',
blockExplorer: 'https://testnet.oasisscan.com/transactions/{{txHash}}',
blockExplorerParatimes:
'https://testnet.oasisscan.com/paratimes/transactions/{{txHash}}?runtime={{runtimeId}}',
blockExplorerAccount: 'https://testnet.oasisscan.com/accounts/detail/{{address}}',
},
[BackendAPIs.Nexus]: {
explorer: 'https://testnet.nexus.oasis.io/v1',
blockExplorer: 'https://testnet.oasisscan.com/transactions/{{txHash}}',
Expand All @@ -89,6 +104,13 @@ export const config: BackendConfig = {
'http://localhost:9001/data/paratimes/transactions/{{txHash}}?runtime={{runtimeId}}',
blockExplorerAccount: 'http://localhost:9001/data/accounts/detail/{{address}}',
},
[BackendAPIs.OasisScanV2]: {
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}}',
},
[BackendAPIs.Nexus]: {
explorer: 'http://localhost:9001',
blockExplorer: 'http://localhost:9001/data/transactions?operation_id={{txHash}}',
Expand Down
3 changes: 3 additions & 0 deletions src/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"total": "Total"
},
"noTransactionFound": "No transactions found.",
"noTransactionFoundOasisscanV2": "No transactions since November 29, 2023.",
"noWalletIsOpen": "To send, receive, stake and swap {{ticker}} tokens, <HomeLink>open your wallet</HomeLink>.",
"notYourAccount": "This is not your account.",
"pendingTransactions": "Pending transactions",
Expand Down Expand Up @@ -108,6 +109,7 @@
"backends": {
"oasismonitor": "Oasis Monitor API",
"oasisscan": "Oasis Scan API",
"oasisscanV2": "Oasis Scan API v2",
"nexus": "Nexus API"
},
"banner": {
Expand Down Expand Up @@ -200,6 +202,7 @@
"poweredBy": {
"oasismonitor": "Oasis Monitor API & Oasis gRPC",
"oasisscan": "Oasis Scan API & Oasis gRPC",
"oasisscanV2": "Oasis Scan API v2 & Oasis gRPC",
"nexus": "Nexus API & Oasis gRPC"
},
"terms": "<TermsLink>Terms and Conditions</TermsLink>",
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' | 'nexus'
REACT_APP_BACKEND: 'oasismonitor' | 'oasisscan' | 'oasisscanV2' | '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,11 +1,13 @@
import { getMonitorAPIs } from 'vendors/monitor'
import { getOasisscanAPIs } from 'vendors/oasisscan'
import { getOasisscanV2APIs } from 'vendors/oasisscan-v2'
import { getNexusAPIs } from 'vendors/nexus'
import { BackendAPIs } from 'config'

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

Expand Down
Loading

0 comments on commit 67dfd2c

Please sign in to comment.