-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implementing wallet.createWallet #16
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { Coinbase } from "./coinbase"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import { ApiClients } from "./types"; | ||
import { User as UserModel } from "./../client/api"; | ||
import { Coinbase } from "./coinbase"; | ||
import { Wallet } from "./wallet"; | ||
|
||
/** | ||
* A representation of a User. | ||
|
@@ -13,18 +15,39 @@ export class User { | |
/** | ||
* Initializes a new User instance. | ||
* | ||
* @param {UserModel} user - The user model. | ||
* @param {ApiClients} client - The API clients. | ||
* @param user - The user model. | ||
* @param client - The API clients. | ||
*/ | ||
constructor(user: UserModel, client: ApiClients) { | ||
this.client = client; | ||
this.model = user; | ||
} | ||
|
||
/** | ||
* Creates a new Wallet belonging to the User. | ||
* | ||
* @throws {APIError} - If the request fails. | ||
* @throws {ArgumentError} - If the model or client is not provided. | ||
* @throws {InternalError} - If address derivation or caching fails. | ||
* @returns the new Wallet | ||
Comment on lines
+31
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets be consistent on if we add the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to use - for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tracking with |
||
*/ | ||
async createWallet(): Promise<Wallet> { | ||
const payload = { | ||
wallet: { | ||
network_id: Coinbase.networkList.BaseSepolia, | ||
}, | ||
}; | ||
const walletData = await this.client.wallet!.createWallet(payload); | ||
return Wallet.init(walletData.data!, { | ||
wallet: this.client.wallet!, | ||
address: this.client.address!, | ||
}); | ||
} | ||
|
||
/** | ||
* Returns the user's ID. | ||
* | ||
* @returns {string} The user's ID. | ||
* @returns The user's ID. | ||
*/ | ||
public getId(): string { | ||
return this.model.id; | ||
|
@@ -33,9 +56,9 @@ export class User { | |
/** | ||
* Returns a string representation of the User. | ||
* | ||
* @returns {string} The string representation of the User. | ||
* @returns The string representation of the User. | ||
*/ | ||
toString(): string { | ||
return `Coinbase:User{userId: ${this.model.id}}`; | ||
return `User{ userId: ${this.model.id} }`; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yuga-cb's feedback