-
Notifications
You must be signed in to change notification settings - Fork 125
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
add TS examples for equivalent SDK methods #177
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a61a2fa
add docs for intro and sep-10
piyalbasu 17338b3
add sep24 docs
piyalbasu 1b05291
add return type for getAuthToken
piyalbasu e277c64
add stellar docs
piyalbasu 6e2f49f
run prettier
piyalbasu 0e6c79a
Trigger
Ifropc c3ca86a
PR comments
piyalbasu fc74902
rm line about HTTP client
piyalbasu 3866819
Trigger
Ifropc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,10 @@ Let's start with getting an instance of `Interactive` class, responsible for all | |
val sep24 = anchor.sep24() | ||
``` | ||
|
||
```typescript | ||
let sep24 = await anchor.interactive(); | ||
``` | ||
|
||
</CodeExample> | ||
|
||
First, let's get the information about the anchor's support for [SEP-24]. This request doesn't require authentication, and will return generic info, such as supported currencies, and features supported by the anchor. You can get a full list of returned fields in the [SEP-24 specification](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0024.md#info). | ||
|
@@ -40,6 +44,12 @@ suspend fun getAnchorServices(): AnchorServiceInfo { | |
} | ||
``` | ||
|
||
```typescript | ||
const getAnchorServices = async (): Promise<AnchorServiceInfo> => { | ||
anchor.getServicesInfo(); | ||
}; | ||
``` | ||
|
||
</CodeExample> | ||
|
||
## Interactive Flows | ||
|
@@ -54,6 +64,10 @@ To initiate an operation, we need to know an asset. You may want to hard-code it | |
val asset = info.currencies.first { it.code == "USDC" }.assetId | ||
``` | ||
|
||
```typescript | ||
const asset = info.currencies.find(({ code }) => code === "USDC").assetId; | ||
``` | ||
|
||
</CodeExample> | ||
|
||
:::info | ||
|
@@ -74,6 +88,14 @@ Let's start with a basic deposit: | |
val deposit = sep24.deposit(asset, token) | ||
``` | ||
|
||
```typescript | ||
let deposit = await anchor.interactive().deposit({ | ||
accountAddress: accountKp.publicKey(), | ||
assetCode, | ||
authToken, | ||
}); | ||
``` | ||
|
||
</CodeExample> | ||
|
||
As a result, you will get an [interactive response](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0024.md#deposit-and-withdraw-shared-responses) from the anchor. | ||
|
@@ -87,6 +109,11 @@ val url = deposit.url | |
val id = deposit.id | ||
``` | ||
|
||
```typescript | ||
let url = deposit.url; | ||
let id = deposit.id; | ||
``` | ||
|
||
</CodeExample> | ||
|
||
Similarly to the deposit flow, a basic withdrawal flow has the same method signature and repose type: | ||
|
@@ -99,6 +126,16 @@ val url = withdrawal.url | |
val id = withdrawal.id | ||
``` | ||
|
||
```typescript | ||
let withdrawal = await anchor.interactive().withdraw({ | ||
accountAddress: accountKp.publicKey(), | ||
assetCode, | ||
authToken, | ||
}); | ||
let url = withdrawal.url; | ||
let id = withdrawal.id; | ||
``` | ||
|
||
</CodeExample> | ||
|
||
### Providing KYC Info | ||
|
@@ -125,6 +162,15 @@ val sep9 = mapOf("email_address" to "[email protected]") | |
val deposit = sep24.deposit(asset, token, sep9) | ||
``` | ||
|
||
```typescript | ||
let deposit = await anchor.interactive().deposit({ | ||
accountAddress: accountKp.publicKey(), | ||
assetCode, | ||
authToken, | ||
extraFields: { email_address: "[email protected]" }, | ||
}); | ||
``` | ||
|
||
</CodeExample> | ||
|
||
### Changing Stellar Transfer Account | ||
|
@@ -143,6 +189,19 @@ suspend fun depositDifferentAccount(): InteractiveFlowResponse { | |
} | ||
``` | ||
|
||
```typescript | ||
const recipientAccount = "G..."; | ||
// TODO: Add `memo` param when the SDK supports it | ||
const depositDifferentAccount = async (): Promise<InteractiveFlowResponse> => { | ||
return anchor.interactive().deposit({ | ||
accountAddress: accountKp.publicKey(), | ||
assetCode, | ||
authToken, | ||
fundsAccountAddress: recipientAccount, | ||
}); | ||
}; | ||
``` | ||
|
||
</CodeExample> | ||
|
||
Similarly, for a withdrawal, the origin account of the Stellar transaction could be changed: | ||
|
@@ -154,6 +213,16 @@ val originAccount = "G..." | |
val withdrawal = sep24.withdraw(asset, token, withdrawalAccount = originAccount) | ||
``` | ||
|
||
```typescript | ||
const originAccount = "G..."; | ||
const withdrawal = await anchor.interactive().withdraw({ | ||
accountAddress: accountKp.publicKey(), | ||
assetCode, | ||
authToken, | ||
fundsAccountAddress: recipientAccount, | ||
}); | ||
``` | ||
|
||
</CodeExample> | ||
|
||
## Getting Transaction Info | ||
|
@@ -173,6 +242,19 @@ val watcher = sep24.watcher() | |
val result = watcher.watchOneTransaction(token, "transaction id") | ||
``` | ||
|
||
```typescript | ||
let watcher = anchor.watcher(); | ||
|
||
let result = watcher.watchOneTransaction({ | ||
authToken, | ||
assetCode, | ||
Ifropc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
id: successfulTransaction.id, | ||
onMessage, | ||
onSuccess, | ||
onError, | ||
}); | ||
``` | ||
|
||
</CodeExample> | ||
|
||
Alternatively, we can track multiple transactions for the same asset. | ||
|
@@ -226,6 +308,13 @@ While `Watcher` class offers powerful tracking capabilities, sometimes it's requ | |
val transaction = sep24.getTransactionBy(token, id = "transaction id") | ||
``` | ||
|
||
```typescript | ||
const transaction = await anchor.getTransactionBy({ | ||
authToken, | ||
id: transactionId, | ||
}); | ||
``` | ||
|
||
</CodeExample> | ||
|
||
It's also possible to fetch transaction by the asset | ||
|
@@ -236,6 +325,13 @@ It's also possible to fetch transaction by the asset | |
val transactions = sep24.getTransactionsForAsset(asset, token) | ||
``` | ||
|
||
```typescript | ||
const transactions = await anchor.getTransactionsForAsset({ | ||
authToken, | ||
assetCode, | ||
}); | ||
``` | ||
|
||
</CodeExample> | ||
|
||
[sep-9]: https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-000p.md | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can you add TODO here to modify code when memo is supported?