-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
changes to ts-wallet-sdk docs (#196)
* make changes to typescript wallet sdk docs * prettier * remove todo * remove ts from wip
- Loading branch information
Showing
9 changed files
with
218 additions
and
147 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { CodeExample } from "@site/src/components/CodeExample"; | ||
|
||
### Configuring the Client | ||
|
||
The Kotlin wallet SDK uses the [ktor client](https://ktor.io/docs/getting-started-ktor-client.html) for all network requests (excluding Horizon, where the Stellar SDK's HTTP client is used). Currently, the okhttp engine is configured to be used with the client. You can read more about how to configure the ktor client [here](https://ktor.io/docs/create-client.html#configure-client). | ||
|
||
For example, the client can be globally configured: | ||
|
||
<CodeExample> | ||
|
||
```kotlin | ||
val walletCustomClient = | ||
Wallet( | ||
StellarConfiguration.Testnet, | ||
ApplicationConfiguration( | ||
defaultClientConfig = { | ||
engine { this.config { this.connectTimeout(Duration.ofSeconds(10)) } } | ||
install(HttpRequestRetry) { | ||
retryOnServerErrors(maxRetries = 5) | ||
exponentialDelay() | ||
} | ||
} | ||
) | ||
) | ||
``` | ||
|
||
</CodeExample> | ||
|
||
This Kotlin code will set the connect timeout to ten seconds via the [okhttp configuration](https://ktor.io/docs/http-client-engines.html#okhttp) and also installs the [retry plugin](https://ktor.io/docs/client-retry.html). You can also specify client configuration for specific wallet SDK classes. | ||
|
||
For example, to change connect timeout when connecting to some anchor server: | ||
|
||
<CodeExample> | ||
|
||
```kotlin | ||
val anchorCustomClient = | ||
walletCustomClient.anchor("example.com") { | ||
engine { this.config { this.connectTimeout(Duration.ofSeconds(30)) } } | ||
} | ||
``` | ||
|
||
</CodeExample> | ||
|
||
### Closing Resources | ||
|
||
After the wallet class is no longer used, it's necessary to close all clients used by it. While in some applications it may not be required (e.g. the wallet lives for the whole lifetime of the application), in other cases it can be required. If your wallet class is short-lived, it's recommended to close client resources using a close function: | ||
|
||
<CodeExample> | ||
|
||
```kotlin | ||
fun closeWallet() { | ||
wallet.close() | ||
} | ||
``` | ||
|
||
</CodeExample> |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { CodeExample } from "@site/src/components/CodeExample"; | ||
|
||
There is one more available configuration for a wallet that allows it to configure internal logic of the SDK. For example, to test with local servers on an HTTP protocol, HTTP can be manually enabled. | ||
|
||
<CodeExample> | ||
|
||
```kotlin | ||
val walletCustom = Wallet( | ||
StellarConfiguration.Testnet, | ||
ApplicationConfiguration { defaultRequest { url { protocol = URLProtocol.HTTP } } } | ||
) | ||
``` | ||
|
||
</CodeExample> |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { CodeExample } from "@site/src/components/CodeExample"; | ||
|
||
Next, let's get the channel provided by `WatcherResult` to receive events. | ||
|
||
<CodeExample> | ||
|
||
```kt | ||
do { | ||
val event = result.channel.receive() | ||
when (event) { | ||
is StatusChange -> | ||
println("Status changed to ${event.status}. Transaction: ${event.transaction}") | ||
is ExceptionHandlerExit -> println("Exception handler exited the job") | ||
is ChannelClosed -> println("Channel closed. Job is done") | ||
} | ||
} while (event !is ChannelClosed) | ||
``` | ||
|
||
</CodeExample> | ||
|
||
This code example will consume all events coming from the channel until it's closed. There are three types of events: | ||
|
||
- `StatusChange`: indicates that transaction status has changed. | ||
- `ExceptionHandlerExit`: indicates that the exception handler exited the processing loop. With default retry handler it happens when retries are exhausted. | ||
- `ChannelClosed`: indicates that the channel is closed and no more events will be emitted. This event will always fire. If `ExceptionHandlerExit` happened, channel will close right after. Otherwise, (under normal circumstances) it will stop when all transactions reach terminal statuses. | ||
|
||
:::info | ||
|
||
Events are stored in the channel until they are received, and calling the `receive()` method will block the channel until a message is received. You can read more about how channels work in the [channel documentation](https://kotlinlang.org/docs/coroutines-and-channels.html#channels). | ||
|
||
::: |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { CodeExample } from "@site/src/components/CodeExample"; | ||
|
||
### Configuring the Client | ||
|
||
The Typescript wallet SDK uses the [axios client](https://axios-http.com/docs/intro) for all network requests. You can read more about how to configure the axios client [here](https://axios-http.com/docs/instance). | ||
|
||
For example, we can configure our axios client to be globally configured with a timeout: | ||
|
||
<CodeExample> | ||
|
||
```typescript | ||
const customClient: AxiosInstance = axios.create({ | ||
timeout: 1000, | ||
}); | ||
let appConfig = new ApplicationConfiguration(DefaultSigner, customClient); | ||
let wal = new Wallet({ | ||
stellarConfiguration: StellarConfiguration.TestNet(), | ||
applicationConfiguration: appConfig, | ||
}); | ||
``` | ||
|
||
</CodeExample> | ||
|
||
You can find more [configure options here.](https://axios-http.com/docs/req_config) |
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
Oops, something went wrong.