-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Flutter examples to sep24.mdx (#187)
* Add Flutter examples to sep24.mdx * fix formatting of sep24.mdx
- Loading branch information
1 parent
5744199
commit e7e064f
Showing
1 changed file
with
95 additions
and
0 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 |
---|---|---|
|
@@ -29,6 +29,14 @@ val sep24 = anchor.sep24() | |
let sep24 = await anchor.sep24(); | ||
``` | ||
|
||
```dart | ||
// By providing the domain hosting the stellar.toml file | ||
final transferService = await TransferServerSEP24Service.fromDomain("place.domain.com"); | ||
// Or by providing the service url | ||
final transferService = TransferServerSEP24Service("http://api.stellar-anchor.org/transfer"); | ||
``` | ||
|
||
</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). | ||
|
@@ -47,6 +55,10 @@ const getAnchorServices = async (): Promise<AnchorServiceInfo> => { | |
}; | ||
``` | ||
|
||
```dart | ||
SEP24InfoResponse infoResponse = await transferService.info(); | ||
``` | ||
|
||
</CodeExample> | ||
|
||
## Interactive Flows | ||
|
@@ -90,6 +102,14 @@ let deposit = await anchor.sep24().deposit({ | |
}); | ||
``` | ||
|
||
```dart | ||
SEP24DepositRequest request = new SEP24DepositRequest(); | ||
request.assetCode = "USDC"; | ||
request.jwt = jwtToken; | ||
SEP24InteractiveResponse response = await transferService.deposit(request); | ||
``` | ||
|
||
</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. | ||
|
@@ -108,6 +128,11 @@ let url = deposit.url; | |
let id = deposit.id; | ||
``` | ||
|
||
```dart | ||
String url = response.url; | ||
String id = response.id; | ||
``` | ||
|
||
</CodeExample> | ||
|
||
Similarly to the deposit flow, a basic withdrawal flow has the same method signature and repose type: | ||
|
@@ -129,6 +154,15 @@ let url = withdrawal.url; | |
let id = withdrawal.id; | ||
``` | ||
|
||
```dart | ||
SEP24WithdrawRequest request = new SEP24WithdrawRequest(); | ||
request.assetCode = "USDC"; | ||
request.type = "bank_account"; | ||
request.jwt = jwtToken; | ||
SEP24InteractiveResponse response = await transferService.withdraw(request); | ||
``` | ||
|
||
</CodeExample> | ||
|
||
### Providing KYC Info | ||
|
@@ -163,6 +197,21 @@ let deposit = await anchor.sep24().deposit({ | |
}); | ||
``` | ||
|
||
```dart | ||
SEP24DepositRequest request = new SEP24DepositRequest(); | ||
request.assetCode = "USDC"; | ||
request.jwt = jwtToken; | ||
StandardKYCFields kycFields = StandardKYCFields(); | ||
kycFields.naturalPersonKYCFields = NaturalPersonKYCFields(); | ||
kycFields.naturalPersonKYCFields!.emailAddress = "[email protected]"; | ||
kycFields.naturalPersonKYCFields!.photoIdFront = await Util.readFile(path); | ||
request.kycFields = kycFields; | ||
SEP24InteractiveResponse response = await transferService.deposit(request); | ||
``` | ||
|
||
</CodeExample> | ||
|
||
### Changing Stellar Transfer Account | ||
|
@@ -195,6 +244,17 @@ const depositDifferentAccount = async (): Promise<InteractiveFlowResponse> => { | |
}; | ||
``` | ||
|
||
```dart | ||
SEP24DepositRequest request = new SEP24DepositRequest(); | ||
request.assetCode = "USDC"; | ||
request.account = "G..."; | ||
request.memo = "my memo"; | ||
request.memoType = "text"; | ||
request.jwt = jwtToken; | ||
SEP24InteractiveResponse response = await transferService.deposit(request); | ||
``` | ||
|
||
</CodeExample> | ||
|
||
Similarly, for a withdrawal, the origin account of the Stellar transaction could be changed: | ||
|
@@ -215,6 +275,14 @@ const withdrawal = await anchor.sep24().withdraw({ | |
}); | ||
``` | ||
|
||
```dart | ||
SEP24WithdrawRequest request = new SEP24WithdrawRequest(); | ||
request.account = "G..."; | ||
//... | ||
SEP24InteractiveResponse response = await transferService.withdraw(request); | ||
``` | ||
|
||
</CodeExample> | ||
|
||
## Getting Transaction Info | ||
|
@@ -279,6 +347,24 @@ const transaction = await anchor.sep24().getTransactionBy({ | |
}); | ||
``` | ||
|
||
```dart | ||
// single transaction | ||
SEP24TransactionRequest request = SEP24TransactionRequest(); | ||
request.stellarTransactionId = "transaction id"; | ||
request.jwt = jwtToken; | ||
SEP24TransactionResponse response = await transferService.transaction(request); | ||
SEP24Transaction transaction = response.transaction; | ||
// multiple transactions | ||
SEP24TransactionsRequest request = SEP24TransactionsRequest(); | ||
request.assetCode = "ETH"; | ||
request.jwt = jwtToken; | ||
SEP24TransactionsResponse response = await transferService.transactions(request); | ||
List<SEP24Transaction> transactions = response.transactions; | ||
``` | ||
|
||
</CodeExample> | ||
|
||
It's also possible to fetch transaction by the asset | ||
|
@@ -296,6 +382,15 @@ const transactions = await anchor.sep24().getTransactionsForAsset({ | |
}); | ||
``` | ||
|
||
```dart | ||
SEP24TransactionsRequest request = SEP24TransactionsRequest(); | ||
request.assetCode = "ETH"; | ||
request.jwt = jwtToken; | ||
SEP24TransactionsResponse response = await transferService.transactions(request); | ||
List<SEP24Transaction> transactions = response.transactions; | ||
``` | ||
|
||
</CodeExample> | ||
|
||
## Submitting Withdrawal Transfer | ||
|