Skip to content

Commit 133c8f7

Browse files
authored
Merge pull request #3 from wharfkit/fix-balances
Upgraded dependencies and refactor
2 parents 5f797c0 + a9cacc1 commit 133c8f7

8 files changed

+121
-94
lines changed

.eslintrc

+9-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,15 @@
2323
"@typescript-eslint/no-explicit-any": "off",
2424
"@typescript-eslint/no-namespace": "off",
2525
"@typescript-eslint/no-non-null-assertion": "off",
26-
"@typescript-eslint/no-unused-vars": "off",
2726
"@typescript-eslint/no-empty-function": "warn",
2827
"no-inner-declarations": "off"
29-
}
28+
},
29+
"overrides": [
30+
{
31+
"files": ["src/contracts/**/*"],
32+
"rules": {
33+
"@typescript-eslint/no-unused-vars": "off"
34+
}
35+
}
36+
]
3037
}

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
"prepare": "make"
2121
},
2222
"dependencies": {
23-
"@wharfkit/antelope": "^1.0.0",
24-
"@wharfkit/contract": "^1.0.0",
23+
"@wharfkit/antelope": "^1.0.4",
24+
"@wharfkit/contract": "^1.1.4",
2525
"bn.js": "^4.11.9",
2626
"tslib": "^2.1.0"
2727
},

src/contracts/system.token.ts

+81-71
Large diffs are not rendered by default.

src/index.ts

+23-12
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,39 @@
1-
import {APIClient, Asset, AssetType, Name, NameType} from '@wharfkit/antelope'
2-
import * as SystemTokenContract from './contracts/system.token'
1+
import {Action, APIClient, Asset, AssetType, Name, NameType} from '@wharfkit/antelope'
32
import {Contract, ContractKit} from '@wharfkit/contract'
43

4+
import * as SystemTokenContract from './contracts/system.token'
5+
56
interface TokenOptions {
67
client: APIClient
7-
tokenSymbol?: Asset.SymbolType
88
contract?: Contract
99
}
1010

1111
export class Token {
12-
readonly contract: Contract
13-
readonly kit: ContractKit
12+
client: APIClient
13+
contractKit: ContractKit
14+
contract: Contract
1415

15-
constructor({contract, client}: TokenOptions) {
16-
this.kit = new ContractKit({
17-
client,
18-
})
16+
constructor({client, contract}: TokenOptions) {
17+
this.client = client
1918
this.contract = contract || new SystemTokenContract.Contract({client})
19+
this.contractKit = new ContractKit({
20+
client: client,
21+
})
2022
}
2123

22-
async transfer(from: NameType, to: NameType, amount: AssetType, memo = '') {
24+
async getContract(contractName?: NameType) {
25+
if (contractName) {
26+
return this.contractKit.load(contractName)
27+
}
28+
return this.contract
29+
}
30+
31+
async transfer(from: NameType, to: NameType, amount: AssetType, memo = ''): Promise<Action> {
2332
const quantity = Asset.from(amount)
2433

25-
return this.contract.action('transfer', {
34+
const contract = await this.getContract()
35+
36+
return contract.action('transfer', {
2637
from: Name.from(from),
2738
to: Name.from(to),
2839
quantity,
@@ -35,7 +46,7 @@ export class Token {
3546
symbolCode?: Asset.SymbolCodeType,
3647
contractName?: NameType
3748
): Promise<Asset> {
38-
const contract = contractName ? await this.kit.load(contractName) : this.contract
49+
const contract = await this.getContract(contractName)
3950
const table = contract.table('accounts', accountName)
4051

4152
let tableQuery

test/data/4422fa1bdbdd5e3cee74c23fc75e0e78aaab31d3.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
"status": 200,
1111
"json": {
1212
"rows": [
13-
"20670a030000000004454f5300000000"
13+
"8639a3030000000004454f5300000000"
1414
],
1515
"more": false,
1616
"next_key": ""
1717
},
18-
"text": "{\"rows\":[\"20670a030000000004454f5300000000\"],\"more\":false,\"next_key\":\"\"}"
18+
"text": "{\"rows\":[\"8639a3030000000004454f5300000000\"],\"more\":false,\"next_key\":\"\"}"
1919
}

test/data/5e885b4772861d842984526c3b03e8027cedc18a.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
"status": 200,
1111
"json": {
1212
"rows": [
13-
"20670a030000000004454f5300000000"
13+
"8639a3030000000004454f5300000000"
1414
],
1515
"more": false,
1616
"next_key": ""
1717
},
18-
"text": "{\"rows\":[\"20670a030000000004454f5300000000\"],\"more\":false,\"next_key\":\"\"}"
18+
"text": "{\"rows\":[\"8639a3030000000004454f5300000000\"],\"more\":false,\"next_key\":\"\"}"
1919
}

test/tests/index.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,9 @@ suite('Token', function () {
6262

6363
assert.equal(String(action.account), 'eosio.token')
6464
assert.equal(String(action.name), 'transfer')
65-
6665
const decoded = Serializer.decode({
6766
data: action.data,
68-
type: SystemTokenContract.Types.Transfer,
67+
type: SystemTokenContract.Types.transfer,
6968
})
7069
assert.equal(String(decoded.from), 'teamgreymass')
7170
assert.equal(String(decoded.to), 'teamgreymass')

yarn.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@
416416
dependencies:
417417
tslib "^2.1.0"
418418

419-
"@wharfkit/contract@^1.0.0":
419+
"@wharfkit/contract@^1.0.0", "@wharfkit/contract@^1.1.4":
420420
version "1.1.5"
421421
resolved "https://registry.yarnpkg.com/@wharfkit/contract/-/contract-1.1.5.tgz#2ca10090330cbb458049890076089237b644eb0e"
422422
integrity sha512-I4w2QFvD/zb4uj5z0U4uQJLRCiZEbrT+AJ9/5goGm6SU42fsRud/k55qSBzW8Ij00OAv2h1+e8rR7xzUruXC9g==

0 commit comments

Comments
 (0)