Skip to content

Commit

Permalink
Removed unnecessary JSON.stringify() usages when calling axios
Browse files Browse the repository at this point in the history
  • Loading branch information
marcvelmer committed Sep 4, 2023
1 parent dce838c commit 5fc4163
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/api/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export abstract class AccountAPI extends API {
*/
public static setInfo(url: string, payload: string, metadata: string): Promise<IAccountSetInfoResponse> {
return axios
.post<IAccountSetInfoResponse>(url + AccountAPIMethods.SET_INFO, JSON.stringify({ txPayload: payload, metadata }))
.post<IAccountSetInfoResponse>(url + AccountAPIMethods.SET_INFO, { txPayload: payload, metadata })
.then((response) => response.data)
.catch(this.isApiError);
}
Expand Down
5 changes: 1 addition & 4 deletions src/api/census3/census.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,7 @@ export abstract class Census3CensusAPI extends Census3API {
blockNumber?: number
): Promise<ICensus3CensusCreateResponse> {
return axios
.post<ICensus3CensusCreateResponse>(
url + Census3CensusAPIMethods.CREATE,
JSON.stringify({ strategyId, blockNumber, anonymous })
)
.post<ICensus3CensusCreateResponse>(url + Census3CensusAPIMethods.CREATE, { strategyId, blockNumber, anonymous })
.then((response) => response.data)
.catch(this.isApiError);
}
Expand Down
5 changes: 1 addition & 4 deletions src/api/census3/strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,7 @@ export abstract class Census3StrategyAPI extends Census3API {
strategy: string
): Promise<ICensus3StrategyCreateResponse> {
return axios
.post<ICensus3StrategyCreateResponse>(
url + Census3StrategyAPIMethods.CREATE,
JSON.stringify({ tokens, strategy })
)
.post<ICensus3StrategyCreateResponse>(url + Census3StrategyAPIMethods.CREATE, { tokens, strategy })
.then((response) => response.data)
.catch(this.isApiError);
}
Expand Down
2 changes: 1 addition & 1 deletion src/api/census3/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export abstract class Census3TokenAPI extends Census3API {
*/
public static create(url: string, id: string, type: string, startBlock: number, tag?: string[]): Promise<void> {
return axios
.post(url + Census3TokenAPIMethods.CREATE, JSON.stringify({ id, type, startBlock, tag: tag?.join() }))
.post(url + Census3TokenAPIMethods.CREATE, { id, type, startBlock, tag: tag?.join() })
.then((response) => response.data)
.catch(this.isApiError);
}
Expand Down
2 changes: 1 addition & 1 deletion src/api/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ export abstract class ChainAPI extends API {
*/
public static submitTx(url: string, payload: string): Promise<IChainSubmitTxResponse> {
return axios
.post<IChainSubmitTxResponse>(url + ChainAPIMethods.SUBMIT_TX, JSON.stringify({ payload }))
.post<IChainSubmitTxResponse>(url + ChainAPIMethods.SUBMIT_TX, { payload })
.then((response) => response.data)
.catch(this.isApiError);
}
Expand Down
4 changes: 2 additions & 2 deletions src/api/csp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export abstract class CspAPI extends API {
return axios
.post<ICspIntermediateStepResponse | ICspFinalStepResponse>(
url + CspAPIMethods.STEP + '/' + strip0x(electionId) + '/' + signatureType + '/' + authType + '/' + stepNr,
JSON.stringify(authToken ? { authToken, authData: data } : { authData: data })
authToken ? { authToken, authData: data } : { authData: data }
)
.then((response) => response.data)
.catch(this.isApiError);
Expand All @@ -142,7 +142,7 @@ export abstract class CspAPI extends API {
return axios
.post<ICspSignResponse>(
url + CspAPIMethods.SIGN.replace('{id}', electionId).replace('{signatureType}', signatureType),
JSON.stringify({ payload, token })
{ payload, token }
)
.then((response) => response.data)
.catch(this.isApiError);
Expand Down
13 changes: 8 additions & 5 deletions src/api/election.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ export abstract class ElectionAPI extends API {
*/
public static create(url: string, payload: string, metadata: string): Promise<IElectionCreateResponse> {
return axios
.post<IElectionCreateResponse>(url + ElectionAPIMethods.CREATE, JSON.stringify({ txPayload: payload, metadata }))
.post<IElectionCreateResponse>(url + ElectionAPIMethods.CREATE, { txPayload: payload, metadata })
.then((response) => response.data)
.catch(this.isApiError);
}
Expand Down Expand Up @@ -483,10 +483,13 @@ export abstract class ElectionAPI extends API {
maxVoteOverwrite: number
): Promise<IElectionCalculatePriceResponse> {
return axios
.post<IElectionCalculatePriceResponse>(
url + ElectionAPIMethods.PRICE,
JSON.stringify({ maxCensusSize, electionBlocks, encryptedVotes, anonymousVotes, maxVoteOverwrite })
)
.post<IElectionCalculatePriceResponse>(url + ElectionAPIMethods.PRICE, {
maxCensusSize,
electionBlocks,
encryptedVotes,
anonymousVotes,
maxVoteOverwrite,
})
.then((response) => response.data)
.catch(this.isApiError);
}
Expand Down
2 changes: 1 addition & 1 deletion src/api/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export abstract class FileAPI extends API {
*/
public static cid(url: string, payload: string): Promise<IFileCIDResponse> {
return axios
.post<IFileCIDResponse>(url + FileAPIMethods.CID, JSON.stringify({ payload }))
.post<IFileCIDResponse>(url + FileAPIMethods.CID, { payload })
.then((response) => response.data)
.catch(this.isApiError);
}
Expand Down
2 changes: 1 addition & 1 deletion src/api/vote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export abstract class VoteAPI extends API {
*/
public static submit(url: string, payload: string): Promise<IVoteSubmitResponse> {
return axios
.post<IVoteSubmitResponse>(url + VoteAPIMethods.VOTE, JSON.stringify({ txPayload: payload }))
.post<IVoteSubmitResponse>(url + VoteAPIMethods.VOTE, { txPayload: payload })
.then((response) => response.data)
.catch(this.isApiError);
}
Expand Down

0 comments on commit 5fc4163

Please sign in to comment.