Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nt/hive auth #2935

Merged
merged 51 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
4ae752f
added loginWithHiveAuth method for putting together final user data
noumantahir Oct 24, 2024
c821e44
added hook to handle post login actions
noumantahir Oct 24, 2024
0369b1a
added HIVE AUTH accomation TODO tags
noumantahir Oct 24, 2024
1fa13cc
debugged and testing hive auth related login routines
noumantahir Oct 24, 2024
c68384c
set new auth type values
noumantahir Oct 24, 2024
47f499d
added hive auth modal with basic login support
noumantahir Oct 24, 2024
d04aa63
Merge branch 'development' into nt/hive-auth
noumantahir Oct 28, 2024
a9c07be
updated dhive to allow using hsClient for both hivesigner and hiveauth
noumantahir Oct 28, 2024
5c0987e
handled authType related changes for hive auth in rest of app
noumantahir Oct 28, 2024
d15c42c
Merge remote-tracking branch 'origin/development' into nt/hive-auth
noumantahir Oct 29, 2024
ef6f9cd
fixed auth type check logic
noumantahir Oct 29, 2024
ae63d8b
added TODO tags
noumantahir Oct 29, 2024
946f344
introduce transaction ops array builder
noumantahir Oct 30, 2024
287667a
complete hive auth transaction flow
noumantahir Oct 30, 2024
7cb734a
passing missing fundType prop
noumantahir Oct 31, 2024
397302d
lint
noumantahir Oct 31, 2024
db16e3e
fine tuned hive auth ui flow
noumantahir Oct 31, 2024
2637e07
directly processing transaction
noumantahir Oct 31, 2024
c78a186
Merge branch 'development' into nt/hive-auth
noumantahir Nov 5, 2024
b0731d2
complete support for hive related ops building
noumantahir Nov 5, 2024
3e05949
comment unused condition
noumantahir Nov 5, 2024
1ef90a0
using outlined icons
noumantahir Nov 6, 2024
5511fb2
fine tuned username validity bhaviour
noumantahir Nov 6, 2024
caf5823
delegation support with hive auth
noumantahir Nov 6, 2024
7781bd1
added unstake support for hive auth
noumantahir Nov 6, 2024
df4d5e8
added hive auth session expiry check at login and account switch
noumantahir Nov 6, 2024
cd21ff8
fixed expiry check logic
noumantahir Nov 6, 2024
2025a00
added 'has' scheme to queryable list
noumantahir Nov 8, 2024
cce7d35
refactor transfer ops builder
noumantahir Nov 8, 2024
86a2d81
trade token support using hive auth
noumantahir Nov 8, 2024
7c4b482
repurpose hive engine json builer to return opArray
noumantahir Nov 8, 2024
20d274a
separated op array builder and json builder for engine token
noumantahir Nov 8, 2024
84998ce
support for hive auth engine actions
noumantahir Nov 8, 2024
6eebcf2
build op array for spk related actions
noumantahir Nov 8, 2024
46296ae
lint
noumantahir Nov 8, 2024
99c2b56
Merge remote-tracking branch 'origin/development' into nt/hive-auth
noumantahir Nov 8, 2024
18332c1
fixed path bug
noumantahir Nov 8, 2024
f91d0dd
added sub component handling auth input and status rendering
noumantahir Nov 10, 2024
8c18eb0
updated hive auth button text
noumantahir Nov 11, 2024
9e6e8d5
fine tuned username input
noumantahir Nov 11, 2024
2ed8a9c
moved hive auth actions as into a hook
noumantahir Nov 11, 2024
8a4b95e
replaced some try catchs with assert
noumantahir Nov 11, 2024
3966f9e
updated translations, added some useful comments
noumantahir Nov 11, 2024
919cf8b
minor fixes
noumantahir Nov 11, 2024
6ccef1f
removed old decrypt method
noumantahir Nov 11, 2024
61a371f
minor fixes
noumantahir Nov 11, 2024
52aa88c
lint
noumantahir Nov 11, 2024
52d1e0b
better handling optional error callback
noumantahir Nov 11, 2024
caa3233
styles refactoring
noumantahir Nov 11, 2024
7360878
info update
noumantahir Nov 11, 2024
5e222d6
close modal on transaction complete
noumantahir Nov 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" />
</intent>

<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="has" />
</intent>
</queries>

<application
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { name as appName } from './app.json';
import 'react-native-url-polyfill/auto';
import 'intl';
import 'intl/locale-data/jsonp/en-US';
import 'react-native-get-random-values';

// set check frequency options
const EcencyApp = require('./App').default;
Expand Down
7 changes: 5 additions & 2 deletions ios/Ecency/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>LSMinimumSystemVersion</key>
<string>13.0.0</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
Expand Down Expand Up @@ -42,8 +40,11 @@
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>LSApplicationCategoryType</key>
<string></string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>has</string>
<string>message</string>
<string>readdle-spark</string>
<string>airmail</string>
Expand All @@ -57,6 +58,8 @@
<string>protonmail</string>
<string>szn-email</string>
</array>
<key>LSMinimumSystemVersion</key>
<string>13.0.0</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAllowsArbitraryLoads</key>
Expand Down
10 changes: 8 additions & 2 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,8 @@ PODS:
- React-Core
- react-native-flipper (0.164.0):
- React-Core
- react-native-get-random-values (1.11.0):
- React-Core
- react-native-heic-converter (1.3.2):
- React
- react-native-netinfo (11.2.1):
Expand All @@ -1157,7 +1159,7 @@ PODS:
- React-Core
- react-native-restart (0.0.24):
- React-Core
- react-native-safe-area-context (4.8.0):
- react-native-safe-area-context (4.11.1):
- React-Core
- react-native-udp (4.1.7):
- CocoaAsyncSocket
Expand Down Expand Up @@ -1511,6 +1513,7 @@ DEPENDENCIES:
- react-native-create-thumbnail (from `../node_modules/react-native-create-thumbnail`)
- react-native-date-picker (from `../node_modules/react-native-date-picker`)
- react-native-flipper (from `../node_modules/react-native-flipper`)
- react-native-get-random-values (from `../node_modules/react-native-get-random-values`)
- react-native-heic-converter (from `../node_modules/react-native-heic-converter`)
- "react-native-netinfo (from `../node_modules/@react-native-community/netinfo`)"
- react-native-orientation-locker (from `../node_modules/react-native-orientation-locker`)
Expand Down Expand Up @@ -1710,6 +1713,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native-date-picker"
react-native-flipper:
:path: "../node_modules/react-native-flipper"
react-native-get-random-values:
:path: "../node_modules/react-native-get-random-values"
react-native-heic-converter:
:path: "../node_modules/react-native-heic-converter"
react-native-netinfo:
Expand Down Expand Up @@ -1909,6 +1914,7 @@ SPEC CHECKSUMS:
react-native-create-thumbnail: e022bcdcba8a0b4529a50d3fa1a832ec921be39d
react-native-date-picker: db26a4dc48fe4e7c3c3afd5008519fad1091c524
react-native-flipper: c33a4995958ef12a2b2f8290d63bed7adeed7634
react-native-get-random-values: 21325b2244dfa6b58878f51f9aa42821e7ba3d06
react-native-heic-converter: 8f7cd7a143ef013a54540ef7ebbc232cecb4fa87
react-native-netinfo: 8a7fd3f7130ef4ad2fb4276d5c9f8d3f28d2df3d
react-native-orientation-locker: 4409c5b12b65f942e75449872b4f078b6f27af81
Expand All @@ -1917,7 +1923,7 @@ SPEC CHECKSUMS:
react-native-receive-sharing-intent: 62ab28c50e6ae56d32b9e841d7452091312a0bc7
react-native-render-html: 984dfe2294163d04bf5fe25d7c9f122e60e05ebe
react-native-restart: 45c8dca02491980f2958595333cbccd6877cb57e
react-native-safe-area-context: d1c8161a1e9560f7066e8926a7d825eb57c5dab5
react-native-safe-area-context: 5141f11858b033636f1788b14f32eaba92cee810
react-native-udp: df79c3cb72c4e71240cd3ce4687bfb8a137140d5
react-native-version-number: b415bbec6a13f2df62bf978e85bc0d699462f37f
react-native-video: c26780b224543c62d5e1b2a7244a5cd1b50e8253
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"expo": "^50.0.8",
"expo-image": "~1.10.6",
"expo-local-authentication": "~13.8.0",
"hive-auth-wrapper": "https://github.com/noumantahir/hive-auth-wrapper.git",
"hive-uri": "^0.2.5",
"hivesigner": "^3.3.4",
"https-browserify": "~0.0.0",
Expand Down Expand Up @@ -122,6 +123,7 @@
"react-native-extended-stylesheet": "^0.10.0",
"react-native-flipper": "^0.164.0",
"react-native-gesture-handler": "^2.14.0",
"react-native-get-random-values": "^1.11.0",
"react-native-heic-converter": "^1.3.1",
"react-native-highlight-words": "^1.0.1",
"react-native-iap": "^12.11.0",
Expand Down Expand Up @@ -189,6 +191,7 @@
"tty-browserify": "0.0.0",
"url": "~0.10.1",
"util": "~0.10.3",
"uuid": "^11.0.2",
"vm-browserify": "0.0.4",
"yarn": "^1.22.22"
},
Expand Down
Binary file added src/assets/HiveAuth_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import {
} from '../../../providers/hive/auth';
import { getUserDataWithUsername } from '../../../realm/realm';

import { logout, toggleAccountsBottomSheet } from '../../../redux/actions/uiAction';
import {
logout,
showActionModal,
toggleAccountsBottomSheet,
} from '../../../redux/actions/uiAction';
import AccountsBottomSheet from '../view/accountsBottomSheetView';

// Constants
Expand All @@ -28,6 +32,7 @@ import { clearSubscribedCommunitiesCache } from '../../../redux/actions/cacheAct
import { fetchSubscribedCommunities } from '../../../redux/actions/communitiesAction';
import { decryptKey } from '../../../utils/crypto';
import { repairUserAccountData } from '../../../utils/migrationHelpers';
import ROUTES from '../../../constants/routeNames';

const AccountsBottomSheetContainer = () => {
const intl = useIntl();
Expand Down Expand Up @@ -82,6 +87,38 @@ const AccountsBottomSheetContainer = () => {
dispatch(logout());
};

const _checkHiveAuthExpiry = (authData: any) => {
if (authData?.username) {
const curTime = new Date().getTime();
if (curTime > authData.hiveAuthExpiry) {
dispatch(
showActionModal({
title: intl.formatMessage({ id: 'alert.warning' }),
body: intl.formatMessage({ id: 'alert.auth_expired' }),
buttons: [
{
text: intl.formatMessage({ id: 'alert.cancel' }),
style: 'destructive',
onPress: () => {
console.log('cancel pressed');
},
},
{
text: intl.formatMessage({ id: 'alert.verify' }),
onPress: () => {
RootNavigation.navigate({
name: ROUTES.SCREENS.LOGIN,
params: { username: authData.username },
});
},
},
],
}),
);
}
}
};

const _handleSwitch = async (switchingAccount = {}) => {
try {
const accountData = accounts.filter(
Expand Down Expand Up @@ -116,8 +153,16 @@ const AccountsBottomSheetContainer = () => {

[_currentAccount.local] = realmData;

if ((currentAccount.local.authType = AUTH_TYPE.HIVE_AUTH)) {
_checkHiveAuthExpiry(_currentAccount.local);
}

// migreate account to use access token for master key auth type
if (realmData[0].authType !== AUTH_TYPE.STEEM_CONNECT && realmData[0].accessToken === '') {
if (
realmData[0].authType !== AUTH_TYPE.STEEM_CONNECT &&
realmData[0].authType !== AUTH_TYPE.HIVE_AUTH &&
realmData[0].accessToken === ''
) {
_currentAccount = await migrateToMasterKeyWithAccessToken(
_currentAccount,
realmData[0],
Expand Down
92 changes: 92 additions & 0 deletions src/components/hiveAuthModal/children/authInputContent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import React, { useEffect, useState } from 'react';
import { useIntl } from 'react-intl';
import { debounce } from 'lodash';
import Animated, { FadeOut, LinearTransition, ZoomIn, ZoomOut } from 'react-native-reanimated';
import styles from '../styles/hiveAuthModal.styles';
import { lookupAccounts } from '../../../providers/hive/dhive';
import { FormInput, MainButton } from '../..';
import HIVE_AUTH_ICON from '../../../assets/HiveAuth_logo.png';

interface AuthInputContentProps {
initUsername?: string;
handleAuthRequest: (username: string) => void;
}

export const AuthInputContent = ({ initUsername, handleAuthRequest }: AuthInputContentProps) => {
const intl = useIntl();

const [username, setUsername] = useState(initUsername || '');
const [isUsernameValid, setIsUsernameValid] = useState(false);

const debouncedCheckValidity = debounce((uname: string) => {
_checkUsernameIsValid(uname);
}, 500);

useEffect(() => {
if (initUsername) {
setUsername(initUsername);
}
}, [initUsername]);

useEffect(() => {
debouncedCheckValidity(username);
return () => debouncedCheckValidity.cancel();
}, [username]);

const _handleUsernameChange = (username: string) => {
const formattedUsername = username.trim().toLowerCase();
setUsername(formattedUsername);
};

const _checkUsernameIsValid = async (uname: string) => {
try {
const accts = await lookupAccounts(uname);
const isValid = accts.includes(uname);
setIsUsernameValid(isValid);
} catch (err) {
setIsUsernameValid(false);
}
};

const onSignInPress = () => {
if (handleAuthRequest) {
handleAuthRequest(username);
}
};

return (
<Animated.View style={styles.authInputContent} exiting={FadeOut}>
<Animated.View style={styles.authInputWrapper} layout={LinearTransition}>
<FormInput
rightIconName="at"
leftIconName="close"
iconType="MaterialCommunityIcons"
isValid={!username || isUsernameValid}
onChange={_handleUsernameChange}
placeholder={intl.formatMessage({
id: 'login.username',
})}
isEditable
type="username"
isFirstImage
value={username}
inputStyle={styles.input}
wrapperStyle={styles.inputWrapper}
onBlur={() => _checkUsernameIsValid(username)}
/>
</Animated.View>

{isUsernameValid && (
<Animated.View entering={ZoomIn} exiting={ZoomOut}>
<MainButton
text={intl.formatMessage({ id: 'login.signin_with_hiveauth' })}
textStyle={styles.loginBtnText}
style={styles.loginBtnWrapper}
onPress={onSignInPress}
source={HIVE_AUTH_ICON}
/>
</Animated.View>
)}
</Animated.View>
);
};
56 changes: 56 additions & 0 deletions src/components/hiveAuthModal/children/statusContent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import React from 'react';
import { Text, ActivityIndicator } from 'react-native';

import EStyleSheet from 'react-native-extended-stylesheet';
import Animated, {
LinearTransition,
FadeInUp,
FadeOutDown,
ZoomIn,
ZoomOut,
} from 'react-native-reanimated';
import styles from '../styles/hiveAuthModal.styles';
import { Icon } from '../..';
import { HiveAuthStatus } from '../hooks/useHiveAuth';

interface StatusContentProps {
status: HiveAuthStatus;
statusText: string;
}

export const StatusContent = ({ status, statusText }: StatusContentProps) => {
const _renderResultIcon = (iconName: string, colorId: string) => (
<Animated.View entering={ZoomIn.springify().duration(500)} exiting={ZoomOut}>
<Icon
iconType="AntDesign"
name={iconName}
color={EStyleSheet.value(colorId)}
size={88}
style={styles.resultIcon}
/>
</Animated.View>
);

return (
<>
{status === HiveAuthStatus.SUCCESS && _renderResultIcon('checkcircleo', '$primaryGreen')}
{status === HiveAuthStatus.ERROR && _renderResultIcon('closecircleo', '$primaryRed')}

<Animated.View
style={styles.statusContent}
layout={LinearTransition}
entering={FadeInUp}
exiting={FadeOutDown}
>
{status === HiveAuthStatus.PROCESSING && (
<ActivityIndicator
style={styles.activityIndicator}
size="large"
color={EStyleSheet.value('$primaryBlue')}
/>
)}
<Text style={styles.statusText}>{statusText}</Text>
</Animated.View>
</>
);
};
Loading