-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from wharfkit/style-mirror
Style mirror
- Loading branch information
Showing
33 changed files
with
1,844 additions
and
975 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,33 @@ | ||
import {APIClient, Name, NameType} from '@wharfkit/antelope' | ||
import {Contract} from '@wharfkit/contract' | ||
|
||
import {Account} from './account' | ||
|
||
export interface AccountKitArgs { | ||
client: APIClient | ||
contract?: Contract | ||
} | ||
|
||
export class AccountKit { | ||
readonly client: APIClient | ||
readonly contract?: Contract | ||
|
||
constructor(args: AccountKitArgs) { | ||
if (args.contract) { | ||
this.contract = args.contract | ||
} | ||
if (args.client) { | ||
this.client = args.client | ||
} else { | ||
throw new Error('A `client` must be passed when initializing the AccountKit.') | ||
} | ||
} | ||
|
||
/** | ||
* Load an Account by name from an API endpoint | ||
* | ||
* @param account The name of the account to load | ||
* @returns | ||
*/ | ||
async load(accountName: NameType): Promise<Account> { | ||
const account = Name.from(accountName) | ||
|
||
let accountData | ||
|
||
try { | ||
accountData = await this.client.v1.chain.get_account(account) | ||
} catch (error) { | ||
throw new Error(`Account ${account} does not exist`) | ||
} | ||
|
||
return new Account({ | ||
accountData: accountData, | ||
client: this.client, | ||
contract: this.contract, | ||
data: await this.client.v1.chain.get_account(accountName), | ||
}) | ||
} | ||
} |
Oops, something went wrong.