feat: Refactor Alchemy endpoint and headers
- Add `access-token` header and update API endpoint in `createOrder` function of Alchemy service - Improve logging functionality in logger module - Miscellaneous updates and fixes in Alchemy controller - Overall improvements to code quality and maintainability
This commit is contained in:
parent
94cdea34ca
commit
8d0a054a44
@ -12,9 +12,9 @@ class AlchemyController extends BaseController {
|
|||||||
async beginPay(req, res) {
|
async beginPay(req, res) {
|
||||||
const user = req.user
|
const user = req.user
|
||||||
const { chain, currency, address } = req.params
|
const { chain, currency, address } = req.params
|
||||||
const tokenResult = await refreshToken(user.emailReal)
|
const tokenResult = await refreshToken(user.emailReal || user.email)
|
||||||
console.log(tokenResult)
|
console.log(tokenResult)
|
||||||
if (!tokenResult.success) {
|
if (!tokenResult.success || tokenResult.returnCode !== '0000') {
|
||||||
logger.info(`fetch pay token error::code: ${tokenResult.returnCode} msg: ${tokenResult.returnMsg}`)
|
logger.info(`fetch pay token error::code: ${tokenResult.returnCode} msg: ${tokenResult.returnMsg}`)
|
||||||
throw new ZError(10, 'fetch pay token error')
|
throw new ZError(10, 'fetch pay token error')
|
||||||
}
|
}
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
const logger = require('tracer').colorConsole({ dateformat: 'yyyy-mm-dd HH:MM:ss.L' })
|
const level = process.env.NODE_ENV === 'production' ? 'info' : 'log'
|
||||||
|
const logger = require('tracer').colorConsole({ dateformat: 'yyyy-mm-dd HH:MM:ss.L', level })
|
||||||
export default logger
|
export default logger
|
||||||
|
@ -73,13 +73,14 @@ export async function refreshToken(email: string) {
|
|||||||
return response.data
|
return response.data
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createOrder(data: any) {
|
export async function createOrder(token: string, data: any) {
|
||||||
const { appid, timestamp, sign } = createSimpleSign()
|
const { appid, timestamp, sign } = createSimpleSign()
|
||||||
const host = process.env.ALCHEMY_API_BASE
|
const host = process.env.ALCHEMY_API_BASE
|
||||||
const config = {
|
const config = {
|
||||||
method: 'post',
|
method: 'post',
|
||||||
url: `${host}/merchant/getToken`,
|
url: `${host}/merchant/trade/create`,
|
||||||
headers: {
|
headers: {
|
||||||
|
'access-token': token,
|
||||||
appId: appid,
|
appId: appid,
|
||||||
timestamp: timestamp,
|
timestamp: timestamp,
|
||||||
sign: sign,
|
sign: sign,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user