Skip to content

Commit 813439a

Browse files
Merge pull request #127 from pubky/fix/import-flow
fix: import flow
2 parents e4113ac + 71bc843 commit 813439a

File tree

5 files changed

+57
-20
lines changed

5 files changed

+57
-20
lines changed

android/app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ android {
8282
applicationId "to.pubky.ring"
8383
minSdkVersion rootProject.ext.minSdkVersion
8484
targetSdkVersion rootProject.ext.targetSdkVersion
85-
versionCode 8
86-
versionName "1.3"
85+
versionCode 9
86+
versionName "1.4"
8787
}
8888

8989
signingConfigs {

ios/pubkyring.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@
289289
buildSettings = {
290290
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
291291
CLANG_ENABLE_MODULES = YES;
292-
CURRENT_PROJECT_VERSION = 2;
292+
CURRENT_PROJECT_VERSION = 1;
293293
DEVELOPMENT_TEAM = KYH47R284B;
294294
ENABLE_BITCODE = NO;
295295
INFOPLIST_FILE = pubkyring/Info.plist;
@@ -300,7 +300,7 @@
300300
"$(inherited)",
301301
"@executable_path/Frameworks",
302302
);
303-
MARKETING_VERSION = 0.4;
303+
MARKETING_VERSION = 0.5;
304304
OTHER_LDFLAGS = (
305305
"$(inherited)",
306306
"-ObjC",
@@ -320,7 +320,7 @@
320320
buildSettings = {
321321
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
322322
CLANG_ENABLE_MODULES = YES;
323-
CURRENT_PROJECT_VERSION = 2;
323+
CURRENT_PROJECT_VERSION = 1;
324324
DEVELOPMENT_TEAM = KYH47R284B;
325325
INFOPLIST_FILE = pubkyring/Info.plist;
326326
INFOPLIST_KEY_CFBundleDisplayName = "Pubky Ring";
@@ -330,7 +330,7 @@
330330
"$(inherited)",
331331
"@executable_path/Frameworks",
332332
);
333-
MARKETING_VERSION = 0.4;
333+
MARKETING_VERSION = 0.5;
334334
OTHER_LDFLAGS = (
335335
"$(inherited)",
336336
"-ObjC",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pubkyring",
3-
"version": "0.0.18",
3+
"version": "0.0.18-1",
44
"private": false,
55
"scripts": {
66
"android": "react-native run-android",

src/components/EmptyState.tsx

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import React, { ReactElement, useCallback, useMemo } from 'react';
22
import { StyleSheet } from 'react-native';
33
import { View, Text, ArrowRight, Plus, Button, NavButton, CircleAlert } from '../theme/components.ts';
4-
import { createNewPubky } from '../utils/pubky.ts';
4+
import {
5+
createNewPubky,
6+
importPubky as importPubkyUtil,
7+
} from '../utils/pubky.ts';
58
import { useDispatch } from 'react-redux';
69
import PubkyRingHeader from './PubkyRingHeader';
710
import { importFile } from '../utils/rnfs.ts';
811
import { showEditPubkyPrompt, showToast } from '../utils/helpers.ts';
912
import { SheetManager } from 'react-native-actions-sheet';
1013
import { useNavigation } from '@react-navigation/native';
14+
import { err, ok, Result } from '@synonymdev/result';
15+
import { IGenerateSecretKey, mnemonicPhraseToKeypair } from '@synonymdev/react-native-pubky';
1116

1217
const EmptyState = (): ReactElement => {
1318
const dispatch = useDispatch();
@@ -31,29 +36,62 @@ const EmptyState = (): ReactElement => {
3136
}, 200);
3237
}, [dispatch]);
3338

34-
const importPubky = useCallback(async () => {
35-
const res = await importFile(dispatch);
36-
if (res.isErr()) {
37-
if (res.error?.message) {
39+
const importPubky = useCallback(async (mnemonic = ''): Promise<Result<string>> => {
40+
if (mnemonic) {
41+
const secretKeyRes: Result<IGenerateSecretKey> = await mnemonicPhraseToKeypair(mnemonic);
42+
if (secretKeyRes.isErr()) {
43+
const msg = secretKeyRes.error.message;
44+
showToast({
45+
type: 'error',
46+
title: 'Error',
47+
description: msg,
48+
});
49+
return err(msg);
50+
}
51+
52+
const secretKey: string = secretKeyRes.value.secret_key;
53+
const pubky = await importPubkyUtil({ secretKey, dispatch, mnemonic });
54+
if (pubky.isErr()) {
55+
const msg = pubky.error.message;
3856
showToast({
3957
type: 'error',
4058
title: 'Error',
41-
description: res.error.message,
59+
description: msg,
4260
});
61+
return err(msg);
4362
}
44-
} else {
63+
await SheetManager.hide('add-pubky');
4564
setTimeout( () => {
4665
showEditPubkyPrompt({
4766
title: 'Setup',
48-
pubky: res.value,
67+
pubky: pubky.value,
4968
});
5069
}, 200);
70+
return ok('Successfully created pubky.');
71+
}
72+
const res = await importFile(dispatch);
73+
if (res.isErr()) {
74+
const msg = res.error?.message ?? 'Unable to import file.';
5175
showToast({
52-
type: 'success',
53-
title: 'Success',
54-
description: 'Pubky imported successfully',
76+
type: 'error',
77+
title: 'Error',
78+
description: msg,
5579
});
80+
return err(msg);
5681
}
82+
setTimeout( () => {
83+
showEditPubkyPrompt({
84+
title: 'Setup',
85+
pubky: res.value,
86+
});
87+
}, 200);
88+
const msg = 'Pubky imported successfully';
89+
showToast({
90+
type: 'success',
91+
title: 'Success',
92+
description: msg,
93+
});
94+
return ok(msg);
5795
}, [dispatch]);
5896

5997
const onPress = useCallback(() => {

src/screens/HomeScreen.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,7 @@ const HomeScreen = (): ReactElement => {
297297
}}
298298
icon={<Plus size={16} />}
299299
/>
300-
// eslint-disable-next-line react-hooks/exhaustive-deps
301-
), []);
300+
), [createPubky, importPubky]);
302301

303302
const onFooterPress = useCallback( () => {
304303
try {

0 commit comments

Comments
 (0)