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'
32import { Contract , ContractKit } from '@wharfkit/contract'
43
4+ import * as SystemTokenContract from './contracts/system.token'
5+
56interface TokenOptions {
67 client : APIClient
7- tokenSymbol ?: Asset . SymbolType
88 contract ?: Contract
99}
1010
1111export 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
0 commit comments