Skip to content

Commit

Permalink
Merge pull request #407 from EdgeApp/matthew/actualTokenId
Browse files Browse the repository at this point in the history
Add getTokenId
  • Loading branch information
peachbits authored May 12, 2022
2 parents 07ec53d + d02a0d7 commit c6a31db
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
"babel-eslint": "^10.1.0",
"babel-loader": "^8.1.0",
"chai": "^4.2.0",
"edge-core-js": "^0.19.10",
"edge-core-js": "^0.19.15",
"eslint": "^7.14.0",
"eslint-config-standard-kit": "0.15.1",
"eslint-plugin-flowtype": "^5.2.0",
Expand Down
5 changes: 5 additions & 0 deletions src/common/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
type EdgeIo,
type EdgeMetaToken,
type EdgeParsedUri,
type EdgeToken,
type EdgeWalletInfo
} from 'edge-core-js/types'
import { serialize } from 'uri-js'
Expand Down Expand Up @@ -156,4 +157,8 @@ export class CurrencyPlugin {
return url
}
}

async getTokenId(token: EdgeToken): Promise<string> {
return this.currencyInfo.pluginId
}
}
25 changes: 12 additions & 13 deletions src/eos/eosPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
type EdgeFetchFunction,
type EdgeIo,
type EdgeParsedUri,
type EdgeToken,
type EdgeWalletInfo
} from 'edge-core-js/types'
import EosApi from 'eosjs-api'
Expand All @@ -29,20 +30,8 @@ import {
} from './eosSchema.js'
import { type EosJsConfig } from './eosTypes'

const validCharacters = '12345abcdefghijklmnopqrstuvwxyz.'

export function checkAddress(address: string): boolean {
// TODO: Check for a valid address format. The passed in
// address would be a use visible displayed address such as what would
// go into a QR code

for (let i = 0; i < address.length; i++) {
const c = address.charAt(i)
if (!validCharacters.includes(c)) {
return false
}
}
return true
return /^[a-z0-9.]{1,12}$/.test(address)
}

export class EosPlugin extends CurrencyPlugin {
Expand Down Expand Up @@ -154,6 +143,16 @@ export class EosPlugin extends CurrencyPlugin {
return encodedUri
}

async getTokenId(token: EdgeToken): Promise<string> {
const contractAddress = token?.networkLocation?.contractAddress
if (contractAddress != null) {
if (!checkAddress(contractAddress))
throw new Error('ErrorInvalidContractAddress')
return contractAddress.toLowerCase()
}
return super.getTokenId(token)
}

// change to fetch call in the future
async getAccSystemStats(account: string) {
return new Promise((resolve, reject) => {
Expand Down
11 changes: 11 additions & 0 deletions src/ethereum/ethPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
type EdgeIo,
type EdgeMetaToken,
type EdgeParsedUri,
type EdgeToken,
type EdgeWalletInfo
} from 'edge-core-js/types'
import EthereumUtil from 'ethereumjs-util'
Expand Down Expand Up @@ -336,6 +337,16 @@ export class EthereumPlugin extends CurrencyPlugin {
getSplittableTypes(walletInfo: EdgeWalletInfo): string[] {
return Object.keys(ethPlugins).map(plugin => `wallet:${plugin}`)
}

async getTokenId(token: EdgeToken): Promise<string> {
const contractAddress = token?.networkLocation?.contractAddress
if (contractAddress != null) {
if (!EthereumUtil.isValidAddress(contractAddress))
throw new Error('ErrorInvalidContractAddress')
return contractAddress.toLowerCase()
}
return super.getTokenId(token)
}
}

export function makeEthereumBasedPluginInner(
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3339,10 +3339,10 @@ [email protected]:
bindings "^1.2.1"
nan "^2.0.9"

edge-core-js@^0.19.10:
version "0.19.10"
resolved "https://registry.yarnpkg.com/edge-core-js/-/edge-core-js-0.19.10.tgz#a03e2b805cbc4538817d6170471f2e368c605765"
integrity sha512-XEi0YAVIEvwOejsKMAahmDj44ogVcjwNiM3AN0Hyo4ZR+U3AL2NzJOhWItofsXz7+HB/LeHTvhvUR8vLJB0+vA==
edge-core-js@^0.19.15:
version "0.19.15"
resolved "https://registry.yarnpkg.com/edge-core-js/-/edge-core-js-0.19.15.tgz#2e8762404a4bc64001e954bc0032869490ace884"
integrity sha512-wTp4zAwVBqwjc2WbgAG6vob/cpx9fDQRgoTdFv8tbnEfRsbH0u4osMrqGhjWN9MwYiKRYy1yRATkjS3hiQrdDg==
dependencies:
aes-js "^3.1.0"
base-x "^1.0.4"
Expand Down

0 comments on commit c6a31db

Please sign in to comment.