Skip to content

Commit

Permalink
fix: snakecase fields
Browse files Browse the repository at this point in the history
  • Loading branch information
bangjelkoski committed Aug 26, 2022
1 parent 6c38525 commit 96b5b47
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/sdk-ts/src/core/MsgBase.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import snakecaseKeys from 'snakecase-keys'
import { objectKeysToEip712Types, TypedDataField } from './eip712'
import { prepareSignBytes } from './utils'

Expand Down Expand Up @@ -47,7 +48,7 @@ export abstract class MsgBase<

return {
type: type as string,
value: value,
value: snakecaseKeys(value) as Omit<AminoRepresentation, 'type'>,
}
}

Expand Down
22 changes: 19 additions & 3 deletions packages/sdk-ts/src/core/eip712.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { EthereumChainId } from '@injectivelabs/ts-types'
import { BigNumberInBase } from '@injectivelabs/utils'
import snakecaseKeys from 'snakecase-keys'
import { DEFAULT_GAS_LIMIT, DEFAULT_STD_FEE } from '../utils'
import { Msgs } from './msgs'

Expand Down Expand Up @@ -182,18 +183,18 @@ export const objectKeysToEip712Types = (
const output = new Map<string, TypedDataField[]>()
const types = new Array<TypedDataField>()

for (const property in object) {
for (const property in snakecaseKeys(object)) {
if (property === '@type' || property === 'type') {
continue
}

const val = object[property]
const val = snakecaseKeys(object)[property]
const type = typeof val

if (type === 'boolean') {
types.push({ name: property, type: 'bool' })
} else if (type === 'number' || type === 'bigint') {
types.push({ name: property, type: 'uint256' })
types.push({ name: property, type: getNumberType(property) })
} else if (type === 'string') {
types.push({ name: property, type: 'string' })
} else if (type === 'object') {
Expand Down Expand Up @@ -505,3 +506,18 @@ export const protoTypeToAminoType = (type: string): string => {
throw new Error('Unknown message type: ' + type)
}
}

export const getNumberType = (property?: string) => {
if (!property) {
return 'uint256'
}

switch (true) {
case ['order_mask'].includes(property):
return 'int32'
default:
'uint256'
}

return 'uint256'
}

0 comments on commit 96b5b47

Please sign in to comment.