Skip to content

Commit 02bb0ad

Browse files
authored
Add flutter support + improve language-specific aspects (stellar#179)
* Add basic Flutter support * Improve logos * Polish language specific stuff
1 parent 5195d47 commit 02bb0ad

19 files changed

+120
-73
lines changed

Diff for: docs/building-apps/wallet/component/header.mdx

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { LanguageButtons } from "@site/src/components/LanguageButtons";
2+
import { WalletGuideWarn } from "@site/src/components/WalletGuideWarn";
3+
4+
<LanguageButtons />
5+
6+
:::info
7+
8+
This guide is available on three different programming languages: Typescript, Kotlin and Flutter (Dart). You can change the shown version on each page via the buttons above.
9+
10+
:::
11+
12+
<WalletGuideWarn WIPLangs={props.WIPLangs} />
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { CodeExample } from "@site/src/components/CodeExample";
2+
3+
Finally, with the approach above we define the signer and client domain per request. If you want to define it once and use it for every authentication call your application is making, you can do so via changing the configuration:
4+
5+
<CodeExample>
6+
7+
```kotlin
8+
val appCfg = ApplicationConfiguration(WalletSigner.DomainSigner("https://my-domain.com/sign"), "my-domain.com")
9+
```
10+
11+
</CodeExample>
12+
13+
This is particularly useful for integrating with multiple anchors.

Diff for: docs/building-apps/wallet/intro.mdx

+6-8
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,11 @@ sidebar_position: 20
55

66
import { LanguageSpecific } from "@site/src/components/LanguageSpecific";
77
import { WalletCodeExample as CodeExample } from "@site/src/components/WalletCodeExample";
8-
import { LanguageButtons } from "@site/src/components/LanguageButtons";
8+
import Header from "./component/header.mdx";
99
import KtInstall from "./component/kt_install.mdx";
1010
import TsInstall from "./component/ts_install.mdx";
1111

12-
<LanguageButtons />
13-
14-
:::info
15-
16-
This guide is available on two different programming languages: Typescript and Kotlin. You can change the shown on each page via the buttons above.
17-
18-
:::
12+
<Header WIPLangs={["ts", "dart"]} />
1913

2014
## Installation
2115

@@ -37,6 +31,10 @@ val wallet = Wallet(StellarConfiguration.Testnet)
3731
let wallet = walletSdk.Wallet.TestNet();
3832
```
3933

34+
```flutter
35+
final StellarSDK sdk = StellarSDK.TESTNET;
36+
```
37+
4038
</CodeExample>
4139

4240
The wallet instance can be further configured. For example, to connect to the public network:

Diff for: docs/building-apps/wallet/overview.mdx

+2-8
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,9 @@ sidebar_position: 10
44
---
55

66
import { CodeExample } from "@site/src/components/CodeExample";
7-
import { LanguageButtons } from "@site/src/components/LanguageButtons";
7+
import Header from "./component/header.mdx";
88

9-
<LanguageButtons />
10-
11-
:::info
12-
13-
This guide is available on two different programming languages: Typescript and Kotlin. You can change the shown version on each page via the buttons above.
14-
15-
:::
9+
<Header />
1610

1711
In this guide we will use the Wallet SDK to integrate with the Stellar blockchain and connect to anchors.
1812

Diff for: docs/building-apps/wallet/sep10.mdx

+12-24
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,13 @@ title: Stellar Authentication
33
sidebar_position: 40
44
---
55

6-
import { CodeExample } from "@site/src/components/CodeExample";
6+
import { LanguageSpecific } from "@site/src/components/LanguageSpecific";
7+
import { WalletCodeExample as CodeExample } from "@site/src/components/WalletCodeExample";
8+
import { CodeExample as NonWalletCodeExample } from "@site/src/components/CodeExample";
9+
import Header from "./component/header.mdx";
10+
import GlobalClientSigner from "./component/kt/global_signer.mdx";
711

8-
import { LanguageButtons } from "@site/src/components/LanguageButtons";
9-
10-
<LanguageButtons />
11-
12-
:::info
13-
14-
This guide is available on two different programming languages: Typescript and Kotlin. You can change the shown version on each page via the buttons above.
15-
16-
:::
12+
<Header WIPLangs={["dart"]} />
1713

1814
Wallets connect to anchors using a standard way of authentication via the Stellar network defined by the [SEP-10] standard.
1915

@@ -177,17 +173,9 @@ const demoWalletSigner: WalletSigner = {
177173

178174
</CodeExample>
179175

180-
Finally, with the approach above we define the signer and client domain per request. If you want to define it once and use it for every authentication call your application is making, you can do so via changing the configuration:
181-
182-
<CodeExample>
183-
184-
```kotlin
185-
val appCfg = ApplicationConfiguration(WalletSigner.DomainSigner("https://my-domain.com/sign"), "my-domain.com")
186-
```
187-
188-
</CodeExample>
176+
[//]: # "TODO: update after WAL-882 is completed"
189177

190-
This is particularly useful for integrating with multiple anchors.
178+
<LanguageSpecific kt={<GlobalClientSigner />} />
191179

192180
### Server Side
193181

@@ -197,7 +185,7 @@ First, generate a new authentication key that will be used as a `client_domain`
197185

198186
Next, create a `SEP-1` toml file placed under `<your domain>/.well-known/stellar.toml` with the following content:
199187

200-
<CodeExample>
188+
<NonWalletCodeExample>
201189

202190
```toml
203191
ACCOUNTS = [ "Authentication public key (address)" ]
@@ -206,13 +194,13 @@ SIGNING_KEY = "Authentication public key (address)"
206194
NETWORK_PASSPHRASE = "Test SDF Network ; September 2015"
207195
```
208196

209-
</CodeExample>
197+
</NonWalletCodeExample>
210198

211199
Don't forget to change the network passphrase for Mainnet deployment.
212200

213201
Finally, let's add server implementation. This sample implementation uses express framework:
214202

215-
<CodeExample>
203+
<NonWalletCodeExample>
216204

217205
```javascript
218206
app.post("/sign", (req, res) => {
@@ -237,7 +225,7 @@ app.post("/sign", (req, res) => {
237225
});
238226
```
239227

240-
</CodeExample>
228+
</NonWalletCodeExample>
241229

242230
You can see full example [here](https://github.com/stellar/stellar-demo-wallet/blob/52071629f8d29470b61799bef9519776d9c252d2/packages/demo-wallet-server/src/index.ts). As mentioned before, this sample implementation doesn't have any protection against unauthorized requests, so you must add authorization checks as part of the request.
243231

Diff for: docs/building-apps/wallet/sep24.mdx

+3-9
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,10 @@ title: Hosted Deposit and Withdrawal
33
sidebar_position: 50
44
---
55

6-
import { CodeExample } from "@site/src/components/CodeExample";
7-
import { LanguageButtons } from "@site/src/components/LanguageButtons";
6+
import { WalletCodeExample as CodeExample } from "@site/src/components/WalletCodeExample";
7+
import Header from "./component/header.mdx";
88

9-
<LanguageButtons />
10-
11-
:::info
12-
13-
This guide is available on two different programming languages: Typescript and Kotlin. You can change the shown version on each page via the buttons above.
14-
15-
:::
9+
<Header WIPLangs={["ts", "dart"]} />
1610

1711
The [SEP-24] standard defines the standard way for anchors and wallets to interact on behalf of users. Wallets use this standard to facilitate exchanges between on-chain assets (such as stablecoins) and off-chain assets (such as fiat, or other network assets such as BTC).
1812

Diff for: docs/building-apps/wallet/stellar.mdx

+3-9
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,10 @@ title: Stellar Network
33
sidebar_position: 30
44
---
55

6-
import { CodeExample } from "@site/src/components/CodeExample";
7-
import { LanguageButtons } from "@site/src/components/LanguageButtons";
6+
import { WalletCodeExample as CodeExample } from "@site/src/components/WalletCodeExample";
7+
import Header from "./component/header.mdx";
88

9-
<LanguageButtons />
10-
11-
:::info
12-
13-
This guide is available on two different programming languages: Typescript and Kotlin. You can change the shown version on each page via the buttons above.
14-
15-
:::
9+
<Header WIPLangs={["ts", "dart"]} />
1610

1711
In the previous section we learned how to create a wallet and a `Stellar` object that provides a connection to Horizon. In this section, we will look at the usages of this class.
1812

Diff for: docusaurus.config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,8 @@ const config = {
256256
"json5",
257257
"python",
258258
"docker",
259-
"kotlin"
259+
"kotlin",
260+
"dart"
260261
],
261262
},
262263
}),

Diff for: src/components/CodeExample.js

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ export const CODE_LANGS = {
77
bash: 'bash',
88
cpp: 'C++',
99
curl: 'cURL',
10+
dart: 'Flutter',
11+
flutter: 'Flutter',
1012
docker: 'Dockerfile',
1113
go: 'Go',
1214
html: 'html',

Diff for: src/components/LanguageButtons.tsx

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
import React from "react";
22
import BrowserOnly from '@docusaurus/BrowserOnly';
3+
import {useColorMode} from '@docusaurus/theme-common';
34
import Kotlin from '@site/static/img/kt.png'
5+
import KotlinDark from '@site/static/img/kt-dark.png'
46
import Typescript from '@site/static/img/ts.png'
7+
import Flutter from '@site/static/img/flutter.png'
8+
import FlutterDark from '@site/static/img/flutter-dark.png'
59

610
export const LanguageButtons = () => {
11+
const {colorMode} = useColorMode();
12+
const isDark = colorMode === 'dark'
13+
714
return (
815
<BrowserOnly>
916
{() =>
10-
<div style={{gap: "0.6rem", display: "flex", marginBottom: "1rem"}}>
17+
<div style={{gap: "1rem", display: "flex", marginBottom: "1rem"}}>
1118
<img src={Typescript} onClick={() => setCookie("ts")} style={{maxHeight: "1.2rem"}}/>
12-
<img src={Kotlin} onClick={() => setCookie("kt")} style={{maxHeight: "1.1rem"}}/>
19+
<img src={isDark ? KotlinDark : Kotlin} onClick={() => setCookie("kt")} style={{maxHeight: "1.1rem"}}/>
20+
<img src={isDark ? FlutterDark : Flutter} onClick={() => setCookie("dart")} style={{maxHeight: "1.2rem"}}/>
1321
</div>
1422
}
1523
</BrowserOnly>

Diff for: src/components/LanguageSpecific.tsx

+9-5
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@ import React from "react";
22
import BrowserOnly from '@docusaurus/BrowserOnly';
33

44
type LanguageProps = {
5-
kt: JSX.Element;
6-
ts: JSX.Element;
5+
kt?: JSX.Element;
6+
ts?: JSX.Element;
7+
flutter?: JSX.Element;
8+
fallback?: JSX.Element;
79
};
810

911
export const walletDefaultLang = "ts"
1012

1113
export const LanguageSpecific: React.FC<LanguageProps> = (props) => {
1214
return (
13-
<BrowserOnly fallback={getToShow(props, null)}>
15+
<BrowserOnly fallback={props.fallback || getToShow(props, null)}>
1416
{() => getToShow(props, getCookie())}
1517
</BrowserOnly>
1618
);
@@ -24,9 +26,11 @@ const getToShow = (props: LanguageProps, cookie: String) => {
2426
}
2527

2628
if (cookie == "kt") {
27-
toShow = props.kt
29+
toShow = props.kt || <></>
2830
} else if (cookie == "ts") {
29-
toShow = props.ts
31+
toShow = props.ts || <></>
32+
} else if (cookie == "dart") {
33+
toShow = props.flutter || <></>
3034
}
3135

3236
return toShow

Diff for: src/components/WalletCodeExample.tsx

+22-6
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ import {Exception} from "sass";
99

1010
// TODO: when TS docs are ready set to false
1111
const ALLOW_EMPTY_DOCS = true
12+
// Set to true for local debugging
13+
const SHOW_ALL = false
1214

13-
const WALLET_LANGS = ["kt", "ts"]
15+
const WALLET_LANGS = ["kt", "ts", "dart"]
1416

1517
type WalletCodeExampleProps = {
1618
children: React.ReactElement
@@ -22,14 +24,18 @@ export const WalletCodeExample: React.FC<WalletCodeExampleProps> = ({children})
2224
</BrowserOnly>
2325
}
2426

25-
const getTabs = (children: React.ReactElement, lang: String) => {
26-
const defaultVal = CODE_LANGS[lang]
27+
const getTabs = (children: React.ReactElement, targetLanguage: String) => {
28+
const defaultVal = CODE_LANGS[targetLanguage]
2729

2830
const tabs = React.Children.map(children, (child, index) => {
2931
const codeProps = child.props.children.props;
3032
const {className = ''} = codeProps;
3133

32-
const [, language] = className.split('-');
34+
let [, language] = className.split('-');
35+
36+
if (language === "flutter") {
37+
language = "dart"
38+
}
3339

3440
return (
3541
<TabItem
@@ -50,7 +56,6 @@ const getTabs = (children: React.ReactElement, lang: String) => {
5056

5157
if (tabs.filter((x) => x.props.value === language).length === 0) {
5258
if (ALLOW_EMPTY_DOCS) {
53-
5459
tabs.push(<TabItem
5560
key={language}
5661
value={language}
@@ -67,10 +72,21 @@ const getTabs = (children: React.ReactElement, lang: String) => {
6772
}
6873
}
6974

75+
let toShowTabs = tabs
76+
77+
if (!SHOW_ALL) {
78+
for (let i = 0; i < tabs.length; i++) {
79+
const language = CODE_LANGS[targetLanguage]
80+
if (tabs[i].props.value === language) {
81+
toShowTabs = [tabs[i]]
82+
}
83+
}
84+
}
85+
7086
const gid = "wallet-lang" + defaultVal
7187
// const gid = "p-wallet" + defaultVal + Math.random()
7288

7389
return (<Tabs groupId={gid}>
74-
{tabs}
90+
{toShowTabs}
7591
</Tabs>)
7692
}

Diff for: src/components/WalletGuideWarn.tsx

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from "react";
2+
import Admonition from '@theme/Admonition';
3+
import {LanguageButtons} from "./LanguageButtons";
4+
import {CODE_LANGS} from "./CodeExample";
5+
import {LanguageSpecific} from "./LanguageSpecific";
6+
7+
type WalletGuideWarnProps = {
8+
WIPLangs?: String[]
9+
};
10+
11+
export const WalletGuideWarn: React.FC<WalletGuideWarnProps> = (props) => {
12+
const langs = (props.WIPLangs || []).map(v => CODE_LANGS[v.toLowerCase()])
13+
const admonition = <Admonition type={"danger"} title={"Important"}>Documentation for this language is currently work in progress. Some of information may not be applicable for this language, or missing. Code samples may be incomplete.</Admonition>
14+
15+
const kt = langs.indexOf("Kotlin") != -1 ? admonition : <></>
16+
const ts = langs.indexOf("TypeScript") != -1 ? admonition: <></>
17+
const flutter = langs.indexOf("Flutter") != -1 ? admonition : <></>
18+
19+
return <LanguageSpecific kt={kt} ts={ts} flutter={flutter} fallback={<></>}/>
20+
};
21+
22+
23+
24+

Diff for: static/img/flutter-dark.png

6.59 KB
Loading

Diff for: static/img/flutter.png

7.06 KB
Loading

Diff for: static/img/img.png

7.14 KB
Loading

Diff for: static/img/kt-dark.png

37.1 KB
Loading

Diff for: static/img/ts.png

-2.23 KB
Loading

Diff for: static/img/ts.svg

-1
This file was deleted.

0 commit comments

Comments
 (0)