Skip to content

Commit a429e3e

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 0b3ff99 commit a429e3e

File tree

8 files changed

+329
-12
lines changed

8 files changed

+329
-12
lines changed

package-lock.json

Lines changed: 6 additions & 10 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
@@ -93,6 +93,7 @@ import { NanoContractRegisterScreen } from './screens/NanoContract/NanoContractR
9393
import { NewNanoContractTransactionScreen } from './screens/WalletConnect/NewNanoContractTransactionScreen';
9494
import { NanoContractRegisterQrCodeScreen } from './screens/NanoContractRegisterQrCodeScreen';
9595
import { SignMessageRequestScreen } from './screens/WalletConnect/SignMessageRequestScreen';
96+
import { SignOracleDataRequestScreen } from './screens/WalletConnect/SignOracleDataRequestScreen';
9697

9798
/**
9899
* This Stack Navigator is exhibited when there is no wallet initialized on the local storage.
@@ -459,6 +460,7 @@ const AppStack = () => {
459460
<Stack.Screen name='WalletConnectScan' component={WalletConnectScan} />
460461
<Stack.Screen name='NewNanoContractTransactionScreen' component={NewNanoContractTransactionScreen} />
461462
<Stack.Screen name='SignMessageRequest' component={SignMessageRequestScreen} />
463+
<Stack.Screen name='SignOracleDataRequestScreen' component={SignOracleDataRequestScreen} />
462464
<Stack.Screen name='PushNotification' component={PushNotification} />
463465
<Stack.Screen name='ChangePin' component={ChangePin} />
464466
<Stack.Screen

src/actions.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ export const types = {
193193
WALLETCONNECT_NEW_NANOCONTRACT_RETRY: 'WALLETCONNECT_NEW_NANOCONTRACT_RETRY',
194194
WALLETCONNECT_NEW_NANOCONTRACT_RETRY_DISMISS: 'WALLETCONNECT_NEW_NANOCONTRACT_RETRY_DISMISS',
195195
SHOW_SIGN_MESSAGE_REQUEST_MODAL: 'SHOW_SIGN_MESSAGE_REQUEST_MODAL',
196-
SHOW_NANO_CONTRACT_SEND_TX_MODAL: 'SHOW_NANO_CONTRACT_SEND_TX_MODAL'
196+
SHOW_NANO_CONTRACT_SEND_TX_MODAL: 'SHOW_NANO_CONTRACT_SEND_TX_MODAL',
197+
SHOW_SIGN_ORACLE_DATA_REQUEST_MODAL: 'SHOW_SIGN_ORACLE_DATA_REQUEST_MODAL',
197198
};
198199

199200
export const featureToggleInitialized = () => ({
@@ -1360,6 +1361,16 @@ export const unregisteredTokensUpdate = (payload) => ({
13601361
payload,
13611362
});
13621363

1364+
export const showSignOracleDataModal = (accept, deny, data, dapp) => ({
1365+
type: types.SHOW_SIGN_ORACLE_DATA_REQUEST_MODAL,
1366+
payload: {
1367+
accept,
1368+
deny,
1369+
data,
1370+
dapp,
1371+
},
1372+
});
1373+
13631374
export const showSignMessageWithAddressModal = (accept, deny, data, dapp) => ({
13641375
type: types.SHOW_SIGN_MESSAGE_REQUEST_MODAL,
13651376
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
@@ -13,6 +13,7 @@ import SignMessageModal from './SignMessageModal';
1313
import ConnectModal from './ConnectModal';
1414
import { COLORS } from '../../styles/themes';
1515
import { NewNanoContractTransactionModal } from './NanoContract/NewNanoContractTransactionModal';
16+
import SignOracleDataModal from './NanoContract/SignOracleDataModal';
1617

1718
export default () => {
1819
const dispatch = useDispatch();
@@ -43,6 +44,13 @@ export default () => {
4344
onDismiss={onDismiss}
4445
/>
4546
);
47+
case WalletConnectModalTypes.SIGN_ORACLE_DATA:
48+
return (
49+
<SignOracleDataModal
50+
{...walletConnectModal}
51+
onDismiss={onDismiss}
52+
/>
53+
);
4654
case WalletConnectModalTypes.SEND_NANO_CONTRACT_TX:
4755
return (
4856
<NewNanoContractTransactionModal
@@ -108,4 +116,5 @@ export const WalletConnectModalTypes = {
108116
CONNECT: 'CONNECT',
109117
SIGN_MESSAGE: 'SIGN_MESSAGE',
110118
SEND_NANO_CONTRACT_TX: 'SEND_NANO_CONTRACT_TX',
119+
SIGN_ORACLE_DATA: 'SIGN_ORACLE_DATA',
111120
};

0 commit comments

Comments
 (0)