Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(swap): Transformers fix for asset ascii name #3115

Merged
merged 9 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/wallet-mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
"@yoroi/links": "1.5.1",
"@yoroi/resolver": "2.0.4",
"@yoroi/staking": "1.5.1",
"@yoroi/swap": "1.5.1",
"@yoroi/swap": "1.5.2",
"@yoroi/theme": "^1.0.0",
"@yoroi/transfer": "1.0.0",
"add": "2.0.6",
Expand Down
4 changes: 3 additions & 1 deletion packages/swap/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@yoroi/swap",
"version": "1.5.1",
"version": "1.5.2",
"description": "The Swap package of Yoroi SDK",
"keywords": [
"yoroi",
Expand Down Expand Up @@ -140,6 +140,7 @@
"immer": "^10.0.2"
},
"devDependencies": {
"@emurgo/yoroi-lib": "0.15.0",
"@commitlint/config-conventional": "^17.0.2",
"@react-native-async-storage/async-storage": "^1.19.3",
"@react-native-community/eslint-config": "^3.0.2",
Expand Down Expand Up @@ -171,6 +172,7 @@
"typescript": "^5.3.3"
},
"peerDependencies": {
"@emurgo/yoroi-lib": "0.15.0",
"@react-native-async-storage/async-storage": ">= 1.19.3 <= 1.20.0",
"react": ">= 16.8.0 <= 19.0.0",
"react-query": "^3.39.3"
Expand Down
15 changes: 15 additions & 0 deletions packages/swap/src/adapters/openswap-api/api.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,21 @@ const getTokens: Balance.TokenInfo[] = [
ticker: 'ELADR',
metadatas: {},
},
{
id: '2d420236ffaada336c21e3f4520b799f6e246d8618f2fc89a4907da6.FFFFFF',
group: '2d420236ffaada336c21e3f4520b799f6e246d8618f2fc89a4907da6',
fingerprint: 'asset1ud7y8pzglxmf68jtww3xhpes9j87akx4mtyx28',
name: 'FFFFFF',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

invalid ascii name, should fallback to 'FFFFFF' hex name

decimals: 6,
description: 'Proof Of Contribution.',
image:
'https://tokens.muesliswap.com/static/img/tokens/2d420236ffaada336c21e3f4520b799f6e246d8618f2fc89a4907da6.4564756c6164646572546f6b656e.png',
kind: 'ft',
symbol: undefined,
icon: undefined,
ticker: 'ELADR',
metadatas: {},
},
]

export const apiMocks = {
Expand Down
18 changes: 18 additions & 0 deletions packages/swap/src/adapters/openswap-api/openswap.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,24 @@ const getTokens: ListTokensResponse = [
},
categories: [],
},
{
supply: {
total: '45000000003000000',
circulating: null,
},
status: 'verified',
website: 'https://eduladder.com',
symbol: 'ELADR',
decimalPlaces: 6,
image:
'https://tokens.muesliswap.com/static/img/tokens/2d420236ffaada336c21e3f4520b799f6e246d8618f2fc89a4907da6.4564756c6164646572546f6b656e.png',
description: 'Proof Of Contribution.',
address: {
policyId: '2d420236ffaada336c21e3f4520b799f6e246d8618f2fc89a4907da6',
name: 'FFFFFF',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ibid idem

},
categories: [],
},
]

const getTokenPairs: TokenPairsResponse = [
Expand Down
8 changes: 6 additions & 2 deletions packages/swap/src/helpers/transformers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import AssetFingerprint from '@emurgo/cip14-js'
import {Swap, Balance} from '@yoroi/types'
import {isString} from '@yoroi/common'
import {AssetNameUtils} from '@emurgo/yoroi-lib/dist/internals/utils/assets'

import {Quantities} from '../utils/quantities'
import {supportedProviders} from '../translators/constants'
Expand Down Expand Up @@ -123,7 +124,7 @@ export const transformersMaker = (
policyId: openswapToken.address.policyId,
assetNameHex: openswapToken.address.name,
}),
name: asUtf8(openswapToken.address.name),
name: asTokenName(openswapToken.address.name),
decimals: openswapToken.decimalPlaces,
description: openswapToken.description,
image: openswapToken.image,
Expand Down Expand Up @@ -266,7 +267,10 @@ export const asTokenFingerprint = ({
return assetFingerprint.fingerprint()
}

export const asUtf8 = (hex: string) => Buffer.from(hex, 'hex').toString('utf-8')
export const asTokenName = (hex: string) => {
const {asciiName, hexName} = AssetNameUtils.resolveProperties(hex)
return asciiName ?? hexName
}

function isSupportedProvider(
provider: string,
Expand Down
Loading