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:
zhl 2023-03-27 21:36:03 +08:00
parent 94cdea34ca
commit 8d0a054a44
3 changed files with 7 additions and 5 deletions

View File

@ -12,9 +12,9 @@ class AlchemyController extends BaseController {
async beginPay(req, res) {
const user = req.user
const { chain, currency, address } = req.params
const tokenResult = await refreshToken(user.emailReal)
const tokenResult = await refreshToken(user.emailReal || user.email)
console.log(tokenResult)
if (!tokenResult.success) {
if (!tokenResult.success || tokenResult.returnCode !== '0000') {
logger.info(`fetch pay token error::code: ${tokenResult.returnCode} msg: ${tokenResult.returnMsg}`)
throw new ZError(10, 'fetch pay token error')
}

View File

@ -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

View File

@ -73,13 +73,14 @@ export async function refreshToken(email: string) {
return response.data
}
export async function createOrder(data: any) {
export async function createOrder(token: string, data: any) {
const { appid, timestamp, sign } = createSimpleSign()
const host = process.env.ALCHEMY_API_BASE
const config = {
method: 'post',
url: `${host}/merchant/getToken`,
url: `${host}/merchant/trade/create`,
headers: {
'access-token': token,
appId: appid,
timestamp: timestamp,
sign: sign,