Skip to content

Commit

Permalink
Merge pull request #4 from consenlabs/feat-support-lowercase-symbol
Browse files Browse the repository at this point in the history
Feat support lowercase symbol
  • Loading branch information
Xaber20110202 authored Jul 30, 2019
2 parents 9908da0 + a710773 commit 8a0c88d
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tokenlon-mmsk",
"version": "0.2.6",
"version": "0.2.7",
"description": "",
"main": "lib/index.js",
"types": "src/globals.d.ts",
Expand Down
5 changes: 3 additions & 2 deletions src/router/getBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { getSupportedTokens } from '../utils/token'
import { getTokenlonTokenBalance } from '../utils/balance'

export const getBalance = async (ctx) => {
const { query } = ctx
try {
const tokenList = getSupportedTokens()
const token = tokenList.find(t => t.symbol === ctx.query.token)
const token = query.token ? tokenList.find(t => t.symbol.toUpperCase() === query.token.toUpperCase()) : null

if (token && token.contractAddress) {
const balance = await getTokenlonTokenBalance(token)
Expand All @@ -16,7 +17,7 @@ export const getBalance = async (ctx) => {
} else {
ctx.body = {
result: false,
message: `Don't support token ${ctx.query.token} trade`,
message: `Don't support token ${query.token} trade`,
}
}
} catch (e) {
Expand Down
2 changes: 2 additions & 0 deletions src/router/getRate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import * as _ from 'lodash'
import { getIndicativePrice } from '../request/marketMaker'
import { checkParams } from '../validations'
import { transferIndicativePriceResultToRateBody } from '../utils/rate'
import { translateBaseQuote } from '../utils/token'

export const getRate = async (ctx) => {
const { query } = ctx
translateBaseQuote(query)
const checkResult = checkParams(query, false)
if (!checkResult.result) {
ctx.body = checkResult
Expand Down
3 changes: 2 additions & 1 deletion src/router/newOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import * as _ from 'lodash'
import { getPrice } from '../request/marketMaker'
import { PriceApiResult } from '../request/marketMaker/interface'
import { getFormatedSignedOrder } from '../utils/order'
import { getSupportedTokens } from '../utils/token'
import { getSupportedTokens, translateBaseQuote } from '../utils/token'
import { updaterStack } from '../utils/intervalUpdater'
import { checkParams } from '../validations'
import { transferPriceResultToRateBody } from '../utils/rate'

export const newOrder = async (ctx) => {
const { query } = ctx
translateBaseQuote(query)
const checkResult = checkParams(query, true)
let rateBody = {} as any

Expand Down
2 changes: 1 addition & 1 deletion src/router/version.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const version = (ctx) => {
ctx.body = {
result: true,
version: '0.2.6',
version: '0.2.7',
}
}
17 changes: 17 additions & 0 deletions src/utils/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,21 @@ export const isSupportedBaseQuote = (tokens: SupportedToken[], baseQuote): boole

export const getTokenBySymbol = (tokens, symbol) => {
return tokens.find(t => t.symbol === symbol)
}

// 处理接口大小写情况,转换为系统设定格式
export const translateBaseQuote = (baseQuote) => {
const tokens = getSupportedTokens()
if (_.isString(baseQuote.base)) {
const found = tokens.find(t => t.symbol.toUpperCase() === baseQuote.base.toUpperCase())
if (found) {
baseQuote.base = found.symbol
}
}
if (_.isString(baseQuote.quote)) {
const found = tokens.find(t => t.symbol.toUpperCase() === baseQuote.quote.toUpperCase())
if (found) {
baseQuote.quote = found.symbol
}
}
}

0 comments on commit 8a0c88d

Please sign in to comment.