Skip to content

Commit

Permalink
Simplify this code, there's no need to iterate
Browse files Browse the repository at this point in the history
  • Loading branch information
nakajima committed Sep 19, 2023
1 parent ef2ca46 commit aaa3da3
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 34 deletions.
90 changes: 57 additions & 33 deletions example/src/LaunchScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import React from "react";
import { useXmtp } from "./XmtpContext";
import * as XMTP from "xmtp-react-native-sdk";
import { useSavedKeys } from "./hooks";
import { Env } from "xmtp-react-native-sdk/lib/Client";

const appVersion = "XMTP_RN_EX/0.0.1";

Expand Down Expand Up @@ -67,20 +68,30 @@ export default function LaunchScreen({
>
Random Wallet
</Text>
{["dev", "local"].map((env) => (
<View key={`generated-${env}`} style={{ margin: 16 }}>
<Button
title={`Use Generated Wallet (${env})`}
color={env === "dev" ? "green" : "purple"}
onPress={() => {
configureWallet(
env,
XMTP.Client.createRandom({ env, appVersion }),
);
}}
/>
</View>
))}
<View key={`generated-dev`} style={{ margin: 16 }}>
<Button
title={`Use Generated Wallet (dev)`}
color="green"
onPress={() => {
configureWallet(
'dev',
XMTP.Client.createRandom({ env: 'dev', appVersion }),
);
}}
/>
</View>
<View key={`generated-local`} style={{ margin: 16 }}>
<Button
title={`Use Generated Wallet (local)`}
color="purple"
onPress={() => {
configureWallet(
'local',
XMTP.Client.createRandom({ env: 'local', appVersion }),
);
}}
/>
</View>
{!!savedKeys.keyBundle && (
<>
<Divider key="divider-saved" />
Expand All @@ -96,26 +107,39 @@ export default function LaunchScreen({
>
Saved Wallet
</Text>
{["dev", "local"].map((env) => (
<View key={`saved-${env}`} style={{ margin: 16 }}>
<Button
title={`Use Saved Wallet (${env})`}
color={env === "dev" ? "green" : "purple"}
onPress={() => {
configureWallet(
env,
XMTP.Client.createFromKeyBundle(savedKeys.keyBundle!, {
env,
appVersion,
}),
);
}}
/>
</View>
))}
<View key={`saved-clear`} style={{ margin: 16 }}>
<View key="saved-dev" style={{ margin: 16 }}>
<Button
title="Use Saved Wallet (dev)"
color="green"
onPress={() => {
configureWallet(
'dev',
XMTP.Client.createFromKeyBundle(savedKeys.keyBundle!, {
env: 'dev',
appVersion,
}),
);
}}
/>
</View>
<View key="saved-local" style={{ margin: 16 }}>
<Button
title="Use Saved Wallet (local)"
color="purple"
onPress={() => {
configureWallet(
'local',
XMTP.Client.createFromKeyBundle(savedKeys.keyBundle!, {
env: 'local',
appVersion,
}),
);
}}
/>
</View>
<View key="saved-clear" style={{ margin: 16 }}>
<Button
title={`Clear Saved Wallet`}
title="Clear Saved Wallet"
// color={"black"}
onPress={() => savedKeys.clear()}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export type NetworkOptions = {
/**
* Specify which XMTP environment to connect to. (default: `dev`)
*/
env: keyof typeof Env;
env: 'local' | 'dev' | 'production';
/**
* identifier that's included with API requests.
*
Expand Down

0 comments on commit aaa3da3

Please sign in to comment.