Skip to content

Commit 642904f

Browse files
authored
chore: gnoboard: Resolve ts:check errors, put in Makefile (#182)
Similar to dSocial PR gnoverse/dsocial#132, we want to use `npm run ts:check` in the Makefile for gnoboard, but first we must resolve the errors. This PR has five commits: 1. Add ts:check to package.json 2. A [previous commit](b586114) changes gnoboard to use `KeyInfo` instead of the alias `GnoAccount` . It seems that this was missed in one file, so we make the same change. 3. In the catch clause, we call `GRPCError` which expects `ConnectError` or null. But the error in the catch can be any type. So add an explicit check for `instanceof ConnectError` . 4. The definition of `NetworkList` includes `onNetworkChange`, but ChangeNetwork.stories doesn't have it. However, `onNetworkChange` isn't used by the storybook, so we put a noop function. 5. Now that the errors are fixed, we can update the gnoboard Makefile. Add a target ts_check to do `npm run ts:check`. Add this as a dependency to the node_modules target, which is used by all the others. --------- Signed-off-by: Jeff Thompson <[email protected]>
1 parent b586114 commit 642904f

File tree

7 files changed

+37
-22
lines changed

7 files changed

+37
-22
lines changed

examples/js/expo/gnoboard/Makefile

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@ go_service_files := $(shell find $(PROJECT_DIR)/service -iname '*.go')
2424
go_files := $(go_framework_files) $(go_service_files)
2525
go_deps := $(PROJECT_DIR)/go.mod $(PROJECT_DIR)/go.sum $(go_files)
2626

27+
ts_check:
28+
npm run ts:check
29+
2730
# - Node: Handle node_modules
2831

29-
node_modules: package.json package-lock.json
32+
node_modules: ts_check package.json package-lock.json
3033
$(call check-program, npm)
3134
(npm install && touch $@) || true
3235
.PHONY: node_modules

examples/js/expo/gnoboard/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"lint:fix": "eslint --fix 'src/**/*.{js,jsx,ts,tsx,json}'",
1212
"format": "prettier --write 'src/**/*.{js,jsx,ts,tsx,css,md,json}' --config ./.prettierrc",
1313
"storybook-generate": "sb-rn-get-stories",
14+
"ts:check": "tsc",
1415
"storybook-watch": "sb-rn-watcher"
1516
},
1617
"dependencies": {

examples/js/expo/gnoboard/src/components/change-network/ChangeNetwork.stories.tsx

+7-3
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,24 @@ export default {
2323
};
2424

2525
export const Basic = () => {
26+
// This callback isn't used by the storybook
27+
const onNetworkChange = async () => {}
2628
return (
2729
<>
28-
<NetworkList networkMetainfos={chains} currentNetworkId='test3' />
30+
<NetworkList networkMetainfos={chains} currentChainId='test3' onNetworkChange={onNetworkChange} />
2931
</>
3032
);
3133
};
3234

3335
export const ListItem = ({ networkMetainfo }: Props) => {
36+
// This callback isn't used by the storybook
37+
const onPress = async () => {}
3438
return (
3539
<>
3640
<Spacer />
37-
<NetworkListItem networkMetainfo={networkMetainfo} currentNetworkId={undefined} />
41+
<NetworkListItem networkMetainfo={networkMetainfo} currentChainId={undefined} onPress={onPress} />
3842
<Spacer />
39-
<NetworkListItem networkMetainfo={networkMetainfo} currentNetworkId={'test3'} />
43+
<NetworkListItem networkMetainfo={networkMetainfo} currentChainId={'test3'} onPress={onPress} />
4044
</>
4145
);
4246
};

examples/js/expo/gnoboard/src/components/common/side-menu-account-item/side-menu-account-item.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import Button from '@gno/components/buttons';
22
import { Spacer } from '@gno/components/row';
3-
import { GnoAccount } from '@gno/native_modules/types';
3+
import { KeyInfo } from '@gnolang/gnonative';
44

55
interface SideMenuAccountItemProps {
6-
account: GnoAccount;
7-
changeAccount: (account: GnoAccount) => void;
6+
account: KeyInfo;
7+
changeAccount: (account: KeyInfo) => void;
88
}
99

1010
const SideMenuAccountItem = (props: SideMenuAccountItemProps) => {

examples/js/expo/gnoboard/src/screens/devmode/index.tsx

+8-6
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ function DevMode() {
3535
console.log('response: ', response);
3636
setAppConsole(Buffer.from(response.result).toString());
3737
}
38-
} catch (error: ConnectError | unknown) {
39-
const err = new GRPCError(error);
40-
if (err.errCode() === ErrCode.ErrDecryptionFailed) {
41-
const account = await gnonative.getActiveAccount();
42-
setReenterPassword(account.key?.name);
43-
return;
38+
} catch (error) {
39+
if (error instanceof ConnectError) {
40+
const err = new GRPCError(error);
41+
if (err.errCode() === ErrCode.ErrDecryptionFailed) {
42+
const account = await gnonative.getActiveAccount();
43+
setReenterPassword(account.key?.name);
44+
return;
45+
}
4446
}
4547
console.log(error);
4648
setAppConsole('error' + JSON.stringify(error));

examples/js/expo/gnoboard/src/screens/switch-accounts/ReenterPassword.tsx

+8-5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Text from '@gno/components/texts';
77
import { ErrCode, GRPCError, useGnoNativeContext } from '@gnolang/gnonative';
88
import { useState } from 'react';
99
import { Modal as NativeModal } from 'react-native';
10+
import { ConnectError } from '@connectrpc/connect';
1011

1112
export type Props = {
1213
visible: boolean;
@@ -27,12 +28,14 @@ const ReenterPassword = ({ visible, accountName, onClose }: Props) => {
2728
await gnonative.setPassword(password);
2829
onClose(true);
2930
} catch (error) {
30-
const err = new GRPCError(error);
31-
if (err.errCode() === ErrCode.ErrDecryptionFailed) {
32-
setError('Wrong password, please try again.');
33-
} else {
34-
setError(JSON.stringify(error));
31+
if (error instanceof ConnectError) {
32+
const err = new GRPCError(error);
33+
if (err.errCode() === ErrCode.ErrDecryptionFailed) {
34+
setError('Wrong password, please try again.');
35+
return;
36+
}
3537
}
38+
setError(JSON.stringify(error));
3639
}
3740
};
3841

examples/js/expo/gnoboard/src/screens/wallet/home/index.tsx

+6-4
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ export const Home: React.FC = () => {
3535
const balance = await gnonative.queryAccount(response.key.address);
3636
setBalance(balance);
3737
}
38-
} catch (error: ConnectError | unknown) {
39-
const err = new GRPCError(error);
40-
if (err.errCode() === ErrCode.ErrNoActiveAccount) {
41-
setUnknownAddress(true);
38+
} catch (error) {
39+
if (error instanceof ConnectError) {
40+
const err = new GRPCError(error);
41+
if (err.errCode() === ErrCode.ErrNoActiveAccount) {
42+
setUnknownAddress(true);
43+
}
4244
}
4345
} finally {
4446
setLoading(undefined);

0 commit comments

Comments
 (0)