Skip to content

Commit

Permalink
Add Flutter examples to sep24.mdx (#187)
Browse files Browse the repository at this point in the history
* Add Flutter examples to sep24.mdx

* fix formatting of sep24.mdx
  • Loading branch information
christian-rogobete authored Aug 1, 2023
1 parent 5744199 commit e7e064f
Showing 1 changed file with 95 additions and 0 deletions.
95 changes: 95 additions & 0 deletions docs/building-apps/wallet/sep24.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -47,6 +55,10 @@ const getAnchorServices = async (): Promise<AnchorServiceInfo> => {
};
```

```dart
SEP24InfoResponse infoResponse = await transferService.info();
```

</CodeExample>

## Interactive Flows
Expand Down Expand Up @@ -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.
Expand All @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit e7e064f

Please sign in to comment.