Skip to content

Commit 1bbcda4

Browse files
feat: sign oracle data (#509)
* chore: add undeclared style * refactor: rename effect requestTokens to requestUnregisteredTokens * feat: fire sentry error notification for method info not found * feat: improve title of Arguments component * refactor: reanem style value to field * fix: FeedbackContent margin style Remarks: The `marginVertical` and `marginHorizontal` are not being applied. Probably this is a bug in ReactNative. * lint: comply with rules * fix: typo * chore: added dependencies and shims needed by walletconnect * refactor: using object destructuring in shims * refactor: typo * refactor: removed unused import on NanoContactTransactionHeader * chore: removed walletconnect libraries from package * feat: added hathor-rpc-handler from the deployed lib * chore: add undeclared style * refactor: rename effect requestTokens to requestUnregisteredTokens * feat: fire sentry error notification for method info not found * feat: improve title of Arguments component * refactor: reanem style value to field * fix: FeedbackContent margin style Remarks: The `marginVertical` and `marginHorizontal` are not being applied. Probably this is a bug in ReactNative. * lint: comply with rules * fix: typo * chore: added dependencies and shims needed by walletconnect * refactor: using object destructuring in shims * refactor: typo * refactor: removed unused import on NanoContactTransactionHeader * chore: removed walletconnect libraries from package * refactor: enable walletconnect by default (#541) * feat: implement Nano Contract integration with Wallet Connect * chore: add undeclared style * refactor: rename effect requestTokens to requestUnregisteredTokens * feat: fire sentry error notification for method info not found * feat: improve title of Arguments component * refactor: reanem style value to field * fix: FeedbackContent margin style Remarks: The `marginVertical` and `marginHorizontal` are not being applied. Probably this is a bug in ReactNative. * lint: comply with rules * fix: typo * chore: added dependencies and shims needed by walletconnect * refactor: using object destructuring in shims * refactor: typo * refactor: removed unused import on NanoContactTransactionHeader * chore: removed walletconnect libraries from package * feat: added hathor-rpc-handler from the deployed lib * chore: changed CI version to 18x and 20x * refactor: enabled walletconnect by default * chore: updated package-lock * chore: updated walletconnect dependencies to be equal to the patch * refactor: default network is nano testnet (#542) * chore: add undeclared style * refactor: rename effect requestTokens to requestUnregisteredTokens * feat: fire sentry error notification for method info not found * feat: improve title of Arguments component * refactor: reanem style value to field * fix: FeedbackContent margin style Remarks: The `marginVertical` and `marginHorizontal` are not being applied. Probably this is a bug in ReactNative. * lint: comply with rules * fix: typo * refactor: using object destructuring in shims * refactor: typo * refactor: removed unused import on NanoContactTransactionHeader * chore: removed walletconnect libraries from package * feat: added hathor-rpc-handler from the deployed lib * refactor: enabled walletconnect by default * refactor: added nano testnet as default network * feat: allow the user to select the nano testnet in network settings * refactor: removed walletservice urls from constants on nano testnet * refactor: remove nc status from tx details (#546) * refactor: remove nc status from tx details * feat: add status label for voided tx * feat: add event coin token as default alongside with hathor (#547) * feat: add register nano contract buttom if nc not registered on new nc transaction (#545) * feat: add register nano contract buttom if nc not registered on new nc transaction * feat: add failure feedback modal for Nano Contract registration failure * feat: restore ready state of nano contract registration also in the success path * refactor: skip directly to the ChoosePinScreen (#543) * refactor: skip directly to the ChoosePinScreen * refactor: added a constant to determine whether to show the confirmation screen * refactor: default skip_seed_confirmation to true --------- Co-authored-by: Alex Ruzenhack <[email protected]> * refactor: ignore confirmation modal (#544) * refactor: ignore modal confirmation screen * refactor: added a config to skip walletconnect confirmation modals * feat: skip confirmation modal on sign message modal as well --------- Co-authored-by: Alex Ruzenhack <[email protected]> * chore: add undeclared style * refactor: rename effect requestTokens to requestUnregisteredTokens * feat: fire sentry error notification for method info not found * feat: improve title of Arguments component * refactor: reanem style value to field * fix: FeedbackContent margin style Remarks: The `marginVertical` and `marginHorizontal` are not being applied. Probably this is a bug in ReactNative. * lint: comply with rules * fix: typo * chore: added dependencies and shims needed by walletconnect * refactor: using object destructuring in shims * refactor: typo * refactor: removed unused import on NanoContactTransactionHeader * chore: removed walletconnect libraries from package * refactor: enabled walletconnect by default * chore: updated walletconnect dependencies to be equal to the patch * refactor: default network is nano testnet (#542) * chore: add undeclared style * refactor: rename effect requestTokens to requestUnregisteredTokens * feat: fire sentry error notification for method info not found * feat: improve title of Arguments component * refactor: reanem style value to field * fix: FeedbackContent margin style Remarks: The `marginVertical` and `marginHorizontal` are not being applied. Probably this is a bug in ReactNative. * lint: comply with rules * fix: typo * refactor: using object destructuring in shims * refactor: typo * refactor: removed unused import on NanoContactTransactionHeader * chore: removed walletconnect libraries from package * feat: added hathor-rpc-handler from the deployed lib * refactor: enabled walletconnect by default * refactor: added nano testnet as default network * feat: allow the user to select the nano testnet in network settings * refactor: removed walletservice urls from constants on nano testnet * refactor: remove nc status from tx details (#546) * refactor: remove nc status from tx details * feat: add status label for voided tx * feat: add event coin token as default alongside with hathor (#547) * feat: add register nano contract buttom if nc not registered on new nc transaction (#545) * feat: add register nano contract buttom if nc not registered on new nc transaction * feat: add failure feedback modal for Nano Contract registration failure * feat: restore ready state of nano contract registration also in the success path * refactor: skip directly to the ChoosePinScreen (#543) * refactor: skip directly to the ChoosePinScreen * refactor: added a constant to determine whether to show the confirmation screen * refactor: default skip_seed_confirmation to true --------- Co-authored-by: Alex Ruzenhack <[email protected]> * feat: added sign oracle data request component and screen * refactor: removed onReadMore * refactor: skip confirmation on sign oracle data * refactor: stop sending baseStyles to sign oracle request and refactored acceptedNc to acceptedData --------- Co-authored-by: Alex Ruzenhack <[email protected]>
1 parent eb36418 commit 1bbcda4

File tree

8 files changed

+326
-10
lines changed

8 files changed

+326
-10
lines changed

package-lock.json

Lines changed: 4 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/App.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ import { NewNanoContractTransactionScreen } from './screens/WalletConnect/NewNan
9494
import { NanoContractRegisterQrCodeScreen } from './screens/NanoContractRegisterQrCodeScreen';
9595
import { SignMessageRequestScreen } from './screens/WalletConnect/SignMessageRequestScreen';
9696
import { CreateTokenRequestScreen } from './screens/WalletConnect/CreateTokenScreen';
97+
import { SignOracleDataRequestScreen } from './screens/WalletConnect/SignOracleDataRequestScreen';
9798

9899
/**
99100
* This Stack Navigator is exhibited when there is no wallet initialized on the local storage.
@@ -461,6 +462,7 @@ const AppStack = () => {
461462
<Stack.Screen name='NewNanoContractTransactionScreen' component={NewNanoContractTransactionScreen} />
462463
<Stack.Screen name='SignMessageRequest' component={SignMessageRequestScreen} />
463464
<Stack.Screen name='CreateTokenRequest' component={CreateTokenRequestScreen} />
465+
<Stack.Screen name='SignOracleDataRequestScreen' component={SignOracleDataRequestScreen} />
464466
<Stack.Screen name='PushNotification' component={PushNotification} />
465467
<Stack.Screen name='ChangePin' component={ChangePin} />
466468
<Stack.Screen

src/actions.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ export const types = {
205205
WALLETCONNECT_CREATE_TOKEN_RETRY: 'WALLETCONNECT_CREATE_TOKEN_RETRY',
206206
WALLETCONNECT_CREATE_TOKEN_RETRY_DISMISS: 'WALLETCONNECT_CREATE_TOKEN_RETRY_DISMISS',
207207
SET_USE_SAFE_BIOMETRY_MODE: 'SET_USE_SAFE_BIOMETRY_MODE',
208+
SHOW_SIGN_ORACLE_DATA_REQUEST_MODAL: 'SHOW_SIGN_ORACLE_DATA_REQUEST_MODAL',
208209
};
209210

210211
export const featureToggleInitialized = () => ({
@@ -1438,6 +1439,16 @@ export const unregisteredTokensDownloadEnd = () => ({
14381439
type: types.UNREGISTEREDTOKENS_DOWNLOAD_END,
14391440
});
14401441

1442+
export const showSignOracleDataModal = (accept, deny, data, dapp) => ({
1443+
type: types.SHOW_SIGN_ORACLE_DATA_REQUEST_MODAL,
1444+
payload: {
1445+
accept,
1446+
deny,
1447+
data,
1448+
dapp,
1449+
},
1450+
});
1451+
14411452
export const showSignMessageWithAddressModal = (accept, deny, data, dapp) => ({
14421453
type: types.SHOW_SIGN_MESSAGE_REQUEST_MODAL,
14431454
payload: {
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/**
2+
* Copyright (c) Hathor Labs and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
import React, { useEffect } from 'react';
9+
import { useDispatch } from 'react-redux';
10+
import { useNavigation } from '@react-navigation/native';
11+
import { t } from 'ttag';
12+
import { StyleSheet, Text } from 'react-native';
13+
import { COLORS } from '../../../styles/themes';
14+
import { ModalBase } from '../../ModalBase';
15+
import { WarnDisclaimer } from '../WarnDisclaimer';
16+
import { walletConnectReject } from '../../../actions';
17+
import { WALLETCONNECT_SKIP_CONFIRMATION_MODAL } from '../../../config';
18+
19+
const styles = StyleSheet.create({
20+
body: {
21+
paddingBottom: 24,
22+
},
23+
text: {
24+
fontSize: 14,
25+
lineHeight: 20,
26+
},
27+
bold: {
28+
fontWeight: 'bold',
29+
},
30+
selectionContainer: {
31+
borderRadius: 8,
32+
paddingVertical: 8,
33+
paddingHorizontal: 16,
34+
backgroundColor: COLORS.freeze100,
35+
},
36+
});
37+
38+
export default ({
39+
onDismiss,
40+
data,
41+
}) => {
42+
const navigation = useNavigation();
43+
const dispatch = useDispatch();
44+
45+
const onReject = () => {
46+
onDismiss();
47+
dispatch(walletConnectReject());
48+
};
49+
50+
const navigateToSignOracleDataScreen = () => {
51+
onDismiss();
52+
navigation.navigate('SignOracleDataRequestScreen', { signOracleData: data });
53+
};
54+
55+
useEffect(() => {
56+
if (WALLETCONNECT_SKIP_CONFIRMATION_MODAL) {
57+
navigateToSignOracleDataScreen();
58+
}
59+
}, []);
60+
61+
return (
62+
<ModalBase show onDismiss={onReject}>
63+
<ModalBase.Title>{t`New Sign Oracle Data Request`}</ModalBase.Title>
64+
<ModalBase.Body style={styles.body}>
65+
<WarnDisclaimer />
66+
<Text style={styles.text}>
67+
{t`You have received a new Sign Oracle Data Request. Please`}
68+
<Text style={styles.bold}>
69+
{' '}{t`carefully review the details`}{' '}
70+
</Text>
71+
{t`before deciding to accept or decline.`}
72+
</Text>
73+
</ModalBase.Body>
74+
<ModalBase.Button
75+
title={t`Review Sign Oracle Data Request details`}
76+
onPress={navigateToSignOracleDataScreen}
77+
/>
78+
<ModalBase.DiscreteButton
79+
title={t`Cancel`}
80+
onPress={onReject}
81+
/>
82+
</ModalBase>
83+
);
84+
};
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/**
2+
* Copyright (c) Hathor Labs and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
import {
9+
StyleSheet,
10+
View,
11+
ScrollView,
12+
TouchableWithoutFeedback,
13+
Text,
14+
} from 'react-native';
15+
import { useDispatch } from 'react-redux';
16+
import { useNavigation } from '@react-navigation/native';
17+
import { t } from 'ttag';
18+
import {
19+
walletConnectAccept,
20+
walletConnectReject
21+
} from '../../actions';
22+
import { COLORS } from '../../styles/themes';
23+
import NewHathorButton from '../NewHathorButton';
24+
import { DappContainer } from './NanoContract/DappContainer';
25+
import { commonStyles } from './theme';
26+
import { NanoContractIcon } from '../Icons/NanoContract.icon';
27+
28+
export const SignOracleDataRequestData = ({ data }) => (
29+
<View style={[commonStyles.card, commonStyles.cardSplit]}>
30+
<View style={commonStyles.cardSplitIcon}>
31+
<NanoContractIcon type='fill' color={COLORS.white} />
32+
</View>
33+
<View style={commonStyles.cardSplitContent}>
34+
<View>
35+
<Text style={styles.property}>{t`Oracle data to sign`}</Text>
36+
<Text style={styles.value}>{data.data}</Text>
37+
</View>
38+
<View style={commonStyles.cardSeparator} />
39+
<View>
40+
<Text style={styles.property}>{t`Oracle`}</Text>
41+
<Text style={styles.value}>{data.oracle}</Text>
42+
</View>
43+
</View>
44+
</View>
45+
);
46+
47+
export const SignOracleDataRequest = ({ signOracleData }) => {
48+
const { dapp, data } = signOracleData;
49+
const { message, address } = data;
50+
const dispatch = useDispatch();
51+
const navigation = useNavigation();
52+
53+
const onAcceptSignOracleDataRequest = () => {
54+
const acceptedData = { address, message };
55+
56+
// Signal the user has accepted the current request and pass the accepted data.
57+
dispatch(walletConnectAccept(acceptedData));
58+
navigation.goBack();
59+
};
60+
61+
const onDeclineTransaction = () => {
62+
dispatch(walletConnectReject());
63+
navigation.goBack();
64+
};
65+
66+
return (
67+
<ScrollView style={styles.wide}>
68+
<TouchableWithoutFeedback>
69+
<View style={styles.wrapper}>
70+
<View style={styles.content}>
71+
<DappContainer dapp={dapp} />
72+
<SignOracleDataRequestData data={data} />
73+
{/* User actions */}
74+
<View style={styles.actionContainer}>
75+
<NewHathorButton
76+
title={t`Accept Request`}
77+
onPress={onAcceptSignOracleDataRequest}
78+
/>
79+
<NewHathorButton
80+
title={t`Decline Request`}
81+
onPress={onDeclineTransaction}
82+
secondary
83+
danger
84+
/>
85+
</View>
86+
</View>
87+
</View>
88+
</TouchableWithoutFeedback>
89+
</ScrollView>
90+
);
91+
};
92+
93+
const styles = StyleSheet.create({
94+
wide: {
95+
width: '100%'
96+
},
97+
wrapper: {
98+
flex: 1,
99+
paddingHorizontal: 16,
100+
backgroundColor: COLORS.lowContrastDetail, // Defines an outer area on the main list content
101+
},
102+
content: {
103+
flex: 1,
104+
rowGap: 24,
105+
width: '100%',
106+
paddingVertical: 16,
107+
},
108+
balanceReceived: {
109+
color: 'hsla(180, 85%, 34%, 1)',
110+
fontWeight: 'bold',
111+
},
112+
actionContainer: {
113+
flexDirection: 'column',
114+
gap: 8,
115+
paddingBottom: 48,
116+
},
117+
declineModalBody: {
118+
paddingBottom: 24,
119+
},
120+
value: [commonStyles.text, commonStyles.value],
121+
});

src/components/WalletConnect/WalletConnectModal.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import ConnectModal from './ConnectModal';
1414
import { COLORS } from '../../styles/themes';
1515
import { NewNanoContractTransactionModal } from './NanoContract/NewNanoContractTransactionModal';
1616
import CreateTokenModal from './CreateTokenModal';
17+
import SignOracleDataModal from './NanoContract/SignOracleDataModal';
1718

1819
export default () => {
1920
const dispatch = useDispatch();
@@ -44,6 +45,13 @@ export default () => {
4445
onDismiss={onDismiss}
4546
/>
4647
);
48+
case WalletConnectModalTypes.SIGN_ORACLE_DATA:
49+
return (
50+
<SignOracleDataModal
51+
{...walletConnectModal}
52+
onDismiss={onDismiss}
53+
/>
54+
);
4755
case WalletConnectModalTypes.SEND_NANO_CONTRACT_TX:
4856
return (
4957
<NewNanoContractTransactionModal
@@ -117,4 +125,5 @@ export const WalletConnectModalTypes = {
117125
SIGN_MESSAGE: 'SIGN_MESSAGE',
118126
SEND_NANO_CONTRACT_TX: 'SEND_NANO_CONTRACT_TX',
119127
CREATE_TOKEN: 'CREATE_TOKEN',
128+
SIGN_ORACLE_DATA: 'SIGN_ORACLE_DATA',
120129
};

0 commit comments

Comments
 (0)