@@ -17,7 +17,7 @@ import WalletsService from 'services/wallets'
1717import SkipDataAndType from 'services/settings/skip-data-and-type'
1818import { ConnectionStatusSubject } from 'models/subjects/node'
1919import { SystemScriptSubject } from 'models/subjects/system-script'
20- import { CatchControllerError } from 'decorators/errors '
20+ import { MapApiResponse } from 'decorators'
2121import { ResponseCode } from 'utils/const'
2222import { TransactionWithoutHash } from 'types/cell-types'
2323
@@ -27,7 +27,9 @@ import { TransactionWithoutHash } from 'types/cell-types'
2727 */
2828export default class ApiController {
2929 // App
30- public static loadInitData = async ( ) => {
30+
31+ @MapApiResponse
32+ public static async loadInitData ( ) {
3133 const walletsService = WalletsService . getInstance ( )
3234 const networksService = NetworksService . getInstance ( )
3335 const [
@@ -114,69 +116,71 @@ export default class ApiController {
114116 return { status : ResponseCode . Success , result : initState }
115117 }
116118
117- public static handleViewError = ( error : string ) => {
119+ @MapApiResponse
120+ public static handleViewError ( error : string ) {
118121 if ( env . isDevMode ) {
119122 console . error ( error )
120123 }
121124 }
122125
126+ @MapApiResponse
123127 public static async contextMenu ( params : { type : string ; id : string } ) {
124128 return popContextMenu ( params )
125129 }
126130
127131 // Wallets
128132
129- @CatchControllerError
133+ @MapApiResponse
130134 public static async getAllWallets ( ) {
131135 return WalletsController . getAll ( )
132136 }
133137
134- @CatchControllerError
138+ @MapApiResponse
135139 public static async getCurrentWallet ( ) {
136140 return WalletsController . getCurrent ( )
137141 }
138142
139- @CatchControllerError
140- public static async importMnemonic ( params : { name : string , password : string , mnemonic : string } ) {
143+ @MapApiResponse
144+ public static async importMnemonic ( params : { name : string ; password : string ; mnemonic : string } ) {
141145 return WalletsController . importMnemonic ( params )
142146 }
143147
144- @CatchControllerError
145- public static async importKeystore ( params : { name : string , password : string , keystorePath : string } ) {
148+ @MapApiResponse
149+ public static async importKeystore ( params : { name : string ; password : string ; keystorePath : string } ) {
146150 return WalletsController . importKeystore ( params )
147151 }
148152
149- @CatchControllerError
150- public static async createWallet ( params : { name : string , password : string , mnemonic : string } ) {
153+ @MapApiResponse
154+ public static async createWallet ( params : { name : string ; password : string ; mnemonic : string } ) {
151155 return WalletsController . create ( params )
152156 }
153157
154- @CatchControllerError
155- public static async updateWallet ( params : { id : string , password : string , name : string , newPassword ?: string } ) {
156- WalletsController . update ( params )
158+ @MapApiResponse
159+ public static async updateWallet ( params : { id : string ; password : string ; name : string ; newPassword ?: string } ) {
160+ return WalletsController . update ( params )
157161 }
158162
159- @CatchControllerError
163+ @MapApiResponse
160164 public static async deleteWallet ( { id = '' , password = '' } ) {
161165 return WalletsController . delete ( { id, password } )
162166 }
163167
164- @CatchControllerError
168+ @MapApiResponse
165169 public static async backupWallet ( { id = '' , password = '' } ) {
166170 return WalletsController . backup ( { id, password } )
167171 }
168172
169- @CatchControllerError
173+ @MapApiResponse
170174 public static async setCurrentWallet ( id : string ) {
171175 return WalletsController . activate ( id )
172176 }
173177
174- @CatchControllerError
178+ @MapApiResponse
175179 public static async getAddressesByWalletID ( id : string ) {
176180 return WalletsController . getAllAddresses ( id )
177181 }
178182
179- @CatchControllerError
183+ @MapApiResponse
180184 public static async sendCapacity ( params : {
181185 id : string
182186 walletID : string
@@ -191,17 +195,17 @@ export default class ApiController {
191195 return WalletsController . sendCapacity ( params )
192196 }
193197
194- @CatchControllerError
198+ @MapApiResponse
195199 public static async sendTx ( params : {
196200 walletID : string
197- tx : TransactionWithoutHash ,
201+ tx : TransactionWithoutHash
198202 password : string
199203 description ?: string
200204 } ) {
201205 return WalletsController . sendTx ( params )
202206 }
203207
204- @CatchControllerError
208+ @MapApiResponse
205209 public static async generateTx ( params : {
206210 walletID : string
207211 items : {
@@ -214,12 +218,12 @@ export default class ApiController {
214218 return WalletsController . generateTx ( params )
215219 }
216220
217- @CatchControllerError
221+ @MapApiResponse
218222 public static async computeCycles ( params : { walletID : string ; capacities : string } ) {
219223 return WalletsController . computeCycles ( params )
220224 }
221225
222- @CatchControllerError
226+ @MapApiResponse
223227 public static async updateAddressDescription ( params : {
224228 walletID : string
225229 address : string
@@ -230,46 +234,46 @@ export default class ApiController {
230234
231235 // Networks
232236
233- @CatchControllerError
237+ @MapApiResponse
234238 public static async getAllNetworks ( ) {
235239 return NetworksController . getAll ( )
236240 }
237241
238- @CatchControllerError
242+ @MapApiResponse
239243 public static async createNetwork ( { name, remote, type = NetworkType . Normal , chain = 'ckb' } : Network ) {
240244 return NetworksController . create ( { name, remote, type, chain } )
241245 }
242246
243- @CatchControllerError
247+ @MapApiResponse
244248 public static async updateNetwork ( id : NetworkID , options : Partial < Network > ) {
245249 return NetworksController . update ( id , options )
246250 }
247251
248- @CatchControllerError
252+ @MapApiResponse
249253 public static async getCurrentNetworkID ( ) {
250254 return NetworksController . currentID ( )
251255 }
252256
253- @CatchControllerError
257+ @MapApiResponse
254258 public static async setCurrentNetowrk ( id : NetworkID ) {
255259 return NetworksController . activate ( id )
256260 }
257261
258262 // Transactions
259263
260- @CatchControllerError
264+ @MapApiResponse
261265 public static async getTransactionList (
262266 params : Controller . Params . TransactionsByKeywords ,
263267 ) {
264268 return TransactionsController . getAllByKeywords ( params )
265269 }
266270
267- @CatchControllerError
271+ @MapApiResponse
268272 public static async getTransaction ( walletID : string , hash : string ) {
269273 return TransactionsController . get ( walletID , hash )
270274 }
271275
272- @CatchControllerError
276+ @MapApiResponse
273277 public static async updateTransactionDescription ( params : { hash : string ; description : string } ) {
274278 return TransactionsController . updateDescription ( params )
275279 }
@@ -280,7 +284,7 @@ export default class ApiController {
280284
281285 // Misc
282286
283- @CatchControllerError
287+ @MapApiResponse
284288 public static async updateSkipDataAndType ( skip : boolean ) {
285289 return SkipDataAndTypeController . update ( skip )
286290 }
0 commit comments