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'
3
2
import { Contract , ContractKit } from '@wharfkit/contract'
4
3
4
+ import * as SystemTokenContract from './contracts/system.token'
5
+
5
6
interface TokenOptions {
6
7
client : APIClient
7
- tokenSymbol ?: Asset . SymbolType
8
8
contract ?: Contract
9
9
}
10
10
11
11
export class Token {
12
- readonly contract : Contract
13
- readonly kit : ContractKit
12
+ client : APIClient
13
+ contractKit : ContractKit
14
+ contract : Contract
14
15
15
- constructor ( { contract, client} : TokenOptions ) {
16
- this . kit = new ContractKit ( {
17
- client,
18
- } )
16
+ constructor ( { client, contract} : TokenOptions ) {
17
+ this . client = client
19
18
this . contract = contract || new SystemTokenContract . Contract ( { client} )
19
+ this . contractKit = new ContractKit ( {
20
+ client : client ,
21
+ } )
20
22
}
21
23
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 > {
23
32
const quantity = Asset . from ( amount )
24
33
25
- return this . contract . action ( 'transfer' , {
34
+ const contract = await this . getContract ( )
35
+
36
+ return contract . action ( 'transfer' , {
26
37
from : Name . from ( from ) ,
27
38
to : Name . from ( to ) ,
28
39
quantity,
@@ -35,7 +46,7 @@ export class Token {
35
46
symbolCode ?: Asset . SymbolCodeType ,
36
47
contractName ?: NameType
37
48
) : Promise < Asset > {
38
- const contract = contractName ? await this . kit . load ( contractName ) : this . contract
49
+ const contract = await this . getContract ( contractName )
39
50
const table = contract . table ( 'accounts' , accountName )
40
51
41
52
let tableQuery
0 commit comments