Skip to content

Commit f9005fe

Browse files
authored
Merge pull request #2298 from oasisprotocol/lw/runtime-methods-type
Move knownRuntimeTxMethods to api.ts
2 parents c877853 + 2439795 commit f9005fe

5 files changed

Lines changed: 40 additions & 52 deletions

File tree

.changelog/2298.trivial.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Move knownRuntimeTxMethods to api.ts

src/app/components/RuntimeTransactionMethod/index.tsx

Lines changed: 9 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ import DeveloperBoard from '@mui/icons-material/DeveloperBoard'
1414
import DeveloperBoardOffIcon from '@mui/icons-material/DeveloperBoardOff'
1515
import LockIcon from '@mui/icons-material/Lock'
1616
import { MethodIcon } from '../ConsensusTransactionMethod'
17-
import { GetRuntimeTransactionsParams, Layer, RuntimeTransaction } from '../../../oasis-nexus/api'
17+
import {
18+
GetRuntimeTransactionsParams,
19+
KnownRuntimeTxMethod,
20+
knownRuntimeTxMethods,
21+
Layer,
22+
RuntimeTransaction,
23+
} from '../../../oasis-nexus/api'
1824
import { paraTimesConfig } from '../../../config'
1925
import { exhaustedTypeWarning } from '../../../types/errors'
2026
import { RuntimeTxMethodFilteringType } from '../../hooks/useCommonParams'
@@ -72,31 +78,6 @@ const getRuntimeTransactionLabel = (t: TFunction, method: KnownRuntimeTxMethod)
7278
}
7379
}
7480

75-
const knownRuntimeTxMethods = [
76-
'accounts.Transfer',
77-
'evm.Call',
78-
'evm.Create',
79-
'consensus.Deposit',
80-
'consensus.Withdraw',
81-
'consensus.Delegate',
82-
'consensus.Undelegate',
83-
'rofl.Create',
84-
'rofl.Register',
85-
'rofl.Remove',
86-
'rofl.Update',
87-
'roflmarket.ProviderCreate',
88-
'roflmarket.ProviderUpdate',
89-
'roflmarket.ProviderUpdateOffers',
90-
'roflmarket.ProviderRemove',
91-
'roflmarket.InstanceCreate',
92-
'roflmarket.InstanceTopUp',
93-
'roflmarket.InstanceCancel',
94-
'roflmarket.InstanceExecuteCmds',
95-
'roflmarket.InstanceChangeAdmin',
96-
'',
97-
] as const
98-
export type KnownRuntimeTxMethod = (typeof knownRuntimeTxMethods)[number]
99-
10081
export type RuntimeTxMethodFilterOption = {
10182
value: RuntimeTxMethodFilteringType
10283
label: string
@@ -115,7 +96,7 @@ export const getRuntimeTxMethodOptions = (t: TFunction, layer: Layer) => {
11596
}
11697

11798
export const getRuntimeRoflUpdatesMethodOptions = (t: TFunction) => {
118-
const options = ['rofl.Create', 'rofl.Remove', 'rofl.Update'] as const
99+
const options = ['rofl.Create', 'rofl.Remove', 'rofl.Update'] satisfies KnownRuntimeTxMethod[]
119100

120101
return options.map(
121102
(method): RuntimeTxMethodFilterOption => ({
@@ -131,27 +112,7 @@ export const getRuntimeRoflUpdatesMethodOptions = (t: TFunction) => {
131112
* May be undefined if the transaction was malformed.
132113
*
133114
* In theory, this could be any string as the runtimes evolve.
134-
* In practice, the nexus currently expects only the following methods:
135-
* - "accounts.Transfer"
136-
* - "consensus.Deposit"
137-
* - "consensus.Withdraw"
138-
* - "consensus.Delegate"
139-
* - "consensus.Undelegate"
140-
* - "evm.Create"
141-
* - "evm.Call"
142-
* - "rofl.Create"
143-
* - "rofl.Update"
144-
* - "rofl.Remove"
145-
* - "rofl.Register"
146-
* - "roflmarket.ProviderCreate"
147-
* - "roflmarket.ProviderUpdate"
148-
* - "roflmarket.ProviderUpdateOffers"
149-
* - "roflmarket.ProviderRemove"
150-
* - "roflmarket.InstanceCreate"
151-
* - "roflmarket.InstanceTopUp"
152-
* - "roflmarket.InstanceCancel"
153-
* - "roflmarket.InstanceExecuteCmds"
154-
* - "roflmarket.InstanceChangeAdmin"
115+
* In practice, the nexus currently expects only KnownRuntimeTxMethod.
155116
*/
156117
const getRuntimeTransactionIcon = (method: KnownRuntimeTxMethod, label: string, truncate?: boolean) => {
157118
const props = {

src/app/hooks/useCommonParams.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import {
55
GetConsensusEventsParams,
66
RuntimeEventType,
77
ConsensusEventType,
8+
KnownRuntimeTxMethod,
89
} from '../../oasis-nexus/api'
9-
import { KnownRuntimeTxMethod } from '../components/RuntimeTransactionMethod'
1010

1111
export const TX_METHOD_QUERY_ARG_NAME = 'tx_method'
1212

src/app/utils/transaction.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { consensusDecimals } from '../../config'
2-
import { ConsensusTxMethod, Transaction } from '../../oasis-nexus/api'
2+
import { ConsensusTxMethod, KnownRuntimeTxMethod, Transaction } from '../../oasis-nexus/api'
33
import { fromBaseUnits } from './number-utils'
44

55
export const getConsensusTransactionToAddress = (transaction: Transaction) => {
@@ -33,7 +33,7 @@ export const getConsensusTransactionAmount = (transaction: Transaction) => {
3333
}
3434
}
3535
export const isRoflTransaction = (method: string | undefined): boolean => {
36-
const roflMethods = [
36+
const roflMethods: string[] = [
3737
'rofl.Create',
3838
'rofl.Update',
3939
'rofl.Remove',
@@ -47,6 +47,6 @@ export const isRoflTransaction = (method: string | undefined): boolean => {
4747
'roflmarket.InstanceCancel',
4848
'roflmarket.InstanceExecuteCmds',
4949
'roflmarket.InstanceChangeAdmin',
50-
]
50+
] satisfies KnownRuntimeTxMethod[]
5151
return method ? roflMethods.includes(method) : false
5252
}

src/oasis-nexus/api.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,32 @@ declare module './generated/api' {
160160
}
161161
}
162162

163+
/** From docs for {@link generated.RuntimeTransaction.method} */
164+
export const knownRuntimeTxMethods = [
165+
'accounts.Transfer',
166+
'evm.Call',
167+
'evm.Create',
168+
'consensus.Deposit',
169+
'consensus.Withdraw',
170+
'consensus.Delegate',
171+
'consensus.Undelegate',
172+
'rofl.Create',
173+
'rofl.Register',
174+
'rofl.Remove',
175+
'rofl.Update',
176+
'roflmarket.ProviderCreate',
177+
'roflmarket.ProviderUpdate',
178+
'roflmarket.ProviderUpdateOffers',
179+
'roflmarket.ProviderRemove',
180+
'roflmarket.InstanceCreate',
181+
'roflmarket.InstanceTopUp',
182+
'roflmarket.InstanceCancel',
183+
'roflmarket.InstanceExecuteCmds',
184+
'roflmarket.InstanceChangeAdmin',
185+
'',
186+
] as const
187+
export type KnownRuntimeTxMethod = (typeof knownRuntimeTxMethods)[number]
188+
163189
export const isAccountEmpty = (account: RuntimeAccount | Account) => {
164190
if (account.layer === 'consensus') {
165191
const {

0 commit comments

Comments
 (0)