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

feat: nano contract integration with wallet connect #495

Merged
merged 31 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
46b578b
feat: implement Nano Contract integration with Wallet Connect
alexruzenhack Jun 20, 2024
4c3cb9d
feat: adapt new nc tx to initialize, set result and withdrawal
alexruzenhack Jul 10, 2024
1e15334
feat: make ncAddress react to firstAddress the right way
alexruzenhack Jul 11, 2024
a35a521
feat: add name to method arguments
alexruzenhack Jul 16, 2024
e2af7d0
i18n: udpate files
alexruzenhack Jul 17, 2024
12e4539
i18n: update translations and fix some typos
alexruzenhack Jul 17, 2024
5c968a2
review: apply suggestions and do some fixes
alexruzenhack Aug 8, 2024
30f55d9
refactor: load of token details not refistered but used in actions
alexruzenhack Aug 9, 2024
15c0a78
lint: comply with rules
alexruzenhack Aug 9, 2024
24de542
chore: remove unused action
alexruzenhack Aug 14, 2024
2f9418e
chore: add undeclared style
alexruzenhack Aug 14, 2024
86f5f27
refactor: walletConnect.tokens to unregisteredTokens
alexruzenhack Aug 14, 2024
970b501
chore: remove unused actions, reducer and saga effect
alexruzenhack Aug 14, 2024
e273ab2
chore: improving feedback message
alexruzenhack Aug 14, 2024
9994676
refactor: move requestTokens from walletConnect saga to tokens saga
alexruzenhack Aug 14, 2024
18bccab
refactor: rename effect requestTokens to requestUnregisteredTokens
alexruzenhack Aug 14, 2024
ea57d7d
feat: fire sentry error notification for method info not found
alexruzenhack Aug 14, 2024
39a8dbd
feat: improve title of Arguments component
alexruzenhack Aug 14, 2024
1232f3d
chore: remove blueprint info action and reducer
alexruzenhack Aug 14, 2024
ef3c95b
feat: retrieve fallback arg entries when blueprint is loading
alexruzenhack Aug 14, 2024
d32b6ae
feat: add nft check to action token on Actions component
alexruzenhack Aug 14, 2024
dbf3d0a
chore: apply suggestions and improve documentation on new nc tx request
alexruzenhack Aug 14, 2024
216396c
lint: comply with rules
alexruzenhack Aug 14, 2024
17784c2
fix: check if blueprintInfo is not null
alexruzenhack Aug 14, 2024
e3c65d0
refactor: reanem style value to field
alexruzenhack Aug 14, 2024
73fc6fd
type: recursar
alexruzenhack Aug 14, 2024
7ba9afa
i18n: update translation files
alexruzenhack Aug 14, 2024
e764d9d
feat: add blueprint download to the tx loading flag and a redundancy
alexruzenhack Aug 15, 2024
5e90771
fix: FeedbackContent margin style
alexruzenhack Aug 15, 2024
cad4cf2
lint: comply with rules
alexruzenhack Aug 15, 2024
26b2f96
fix: typo
alexruzenhack Aug 16, 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
295 changes: 221 additions & 74 deletions locale/da/texts.po

Large diffs are not rendered by default.

302 changes: 226 additions & 76 deletions locale/pt-br/texts.po

Large diffs are not rendered by default.

295 changes: 221 additions & 74 deletions locale/ru-ru/texts.po

Large diffs are not rendered by default.

294 changes: 220 additions & 74 deletions locale/texts.pot

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ import { NetworkStatusBar } from './components/NetworkSettings/NetworkStatusBar'
import { NanoContractDetailsScreen } from './screens/NanoContract/NanoContractDetailsScreen';
import { NanoContractTransactionScreen } from './screens/NanoContract/NanoContractTransactionScreen';
import { NanoContractRegisterScreen } from './screens/NanoContract/NanoContractRegisterScreen';
import { NewNanoContractTransactionScreen } from './screens/WalletConnect/NewNanoContractTransactionScreen';
import { NewNanoContractTransactionModal } from './components/WalletConnect/NanoContract/NewNanoContractTransactionModal';

/**
* This Stack Navigator is exhibited when there is no wallet initialized on the local storage.
Expand Down Expand Up @@ -387,6 +389,7 @@ const AppStack = () => {
<Stack.Screen name='WalletConnectList' component={WalletConnectList} />
<Stack.Screen name='WalletConnectManual' component={WalletConnectManual} />
<Stack.Screen name='WalletConnectScan' component={WalletConnectScan} />
<Stack.Screen name='NewNanoContractTransactionScreen' component={NewNanoContractTransactionScreen} />
<Stack.Screen name='PushNotification' component={PushNotification} />
<Stack.Screen name='ChangePin' component={ChangePin} />
<Stack.Screen
Expand Down Expand Up @@ -733,6 +736,7 @@ const App = () => (
>
<NetworkStatusBar />
<RootStack />
<NewNanoContractTransactionModal />
</NavigationContainer>
<WalletConnectModal />
<GlobalErrorHandler />
Expand Down
131 changes: 130 additions & 1 deletion src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
metadataApi,
} from '@hathor/wallet-lib';
import {
METADATA_CONCURRENT_DOWNLOAD,
METADATA_CONCURRENT_DOWNLOAD, WALLETCONNECT_NEW_NANOCONTRACT_TX_STATUS,
} from './constants';
import { mapToTxHistory } from './utils';

Expand Down Expand Up @@ -57,6 +57,8 @@ export const types = {
TOKEN_METADATA_LOADED: 'TOKEN_METADATA_LOADED',
SET_UNIQUE_DEVICE_ID: 'SET_UNIQUE_DEVICE_ID',
SET_IS_SHOWING_PIN_SCREEN: 'SET_IS_SHOWING_PIN_SCREEN',
/* It initiates download of tokens metadata. */
TOKENS_FETCH_METADATA_REQUESTED: 'TOKENS_FETCH_METADATA_REQUESTED',
TOKEN_FETCH_METADATA_REQUESTED: 'TOKEN_FETCH_METADATA_REQUESTED',
TOKEN_FETCH_METADATA_SUCCESS: 'TOKEN_FETCH_METADATA_SUCCESS',
TOKEN_FETCH_METADATA_FAILED: 'TOKEN_FETCH_METADATA_FAILED',
Expand Down Expand Up @@ -113,6 +115,9 @@ export const types = {
SET_WALLET_CONNECT: 'SET_WALLET_CONNECT',
SET_WALLET_CONNECT_MODAL: 'SET_WALLET_CONNECT_MODAL',
SET_WALLET_CONNECT_SESSIONS: 'SET_WALLET_CONNECT_SESSIONS',
WALLET_CONNECT_ACCEPT: 'WALLET_CONNECT_ACCEPT',
WALLET_CONNECT_REJECT: 'WALLET_CONNECT_REJECT',
SET_NEW_NANO_CONTRACT_TRANSACTION: 'SET_NEW_NANO_CONTRACT_TRANSACTION',
pedroferreira1 marked this conversation as resolved.
Show resolved Hide resolved
SET_UNLEASH_CLIENT: 'SET_UNLEASH_CLIENT',
WC_URI_INPUTTED: 'WC_URI_INPUTTED',
WC_CANCEL_SESSION: 'WC_CANCEL_SESSION',
Expand Down Expand Up @@ -163,6 +168,14 @@ export const types = {
NANOCONTRACT_UNREGISTER_SUCCESS: 'NANOCONTRACT_UNREGISTER_SUCCESS',
/* It initiates a process to change the address on registered Nano Contract. */
NANOCONTRACT_ADDRESS_CHANGE_REQUEST: 'NANOCONTRACT_ADDRESS_CHANGE_REQUEST',
/* It triggers a process to fetch blueprint info. */
NANOCONTRACT_BLUEPRINTINFO_REQUEST: 'NANOCONTRACT_BLUEPRINTINFO_REQUEST',
/* It signals a failure on fetch blueprint info. */
NANOCONTRACT_BLUEPRINTINFO_FAILURE: 'NANOCONTRACT_BLUEPRINTINFO_FAILURE',
/* It signals a success on fetch blueprint info. */
NANOCONTRACT_BLUEPRINTINFO_SUCCESS: 'NANOCONTRACT_BLUEPRINTINFO_SUCCESS',
/* It signals the blueprint info state is ready. */
NANOCONTRACT_BLUEPRINTINFO_READY: 'NANOCONTRACT_BLUEPRINTINFO_READY',
/* It triggers a process to fetch all wallet addresses. */
SELECTADDRESS_ADDRESSES_REQUEST: 'SELECTADDRESS_ADDRESSES_REQUEST',
/* It signals the fetch has loaded all the addresses with success. */
Expand All @@ -175,6 +188,8 @@ export const types = {
FIRSTADDRESS_SUCCESS: 'FIRSTADDRESS_SUCCESS',
/* It signals a fetch failure due to an error. */
FIRSTADDRESS_FAILURE: 'FIRSTADDRESS_FAILURE',
/* It updates the redux state of new nano contract transaction status on wallet connect register. */
WALLETCONNECT_NEW_NANOCONTRACT_STATUS: 'WALLETCONNECT_NEW_NANOCONTRACT_STATUS',
pedroferreira1 marked this conversation as resolved.
Show resolved Hide resolved
};

export const featureToggleInitialized = () => ({
Expand Down Expand Up @@ -235,6 +250,30 @@ export const walletConnectCancelSession = (sessionKey) => ({
payload: sessionKey,
});

/**
* @param {Object} data Data that the user has accepted.
*/
export const walletConnectAccept = (data) => ({
type: types.WALLET_CONNECT_ACCEPT,
payload: data,
});

export const walletWalletReject = () => ({
andreabadesso marked this conversation as resolved.
Show resolved Hide resolved
type: types.WALLET_CONNECT_REJECT,
});

/**
* @param {Object} ncRequest
* @param {boolean} ncRequest.show
* @param {Object} ncRequest.data
* @param {Object} ncRequest.data.nc
* @param {Object} ncRequest.data.dapp
*/
export const setNewNanoContractTransaction = (ncRequest) => ({
type: types.SET_NEW_NANO_CONTRACT_TRANSACTION,
payload: ncRequest
});

/**
* isShowingPinScreen {bool}
* */
Expand Down Expand Up @@ -1205,3 +1244,93 @@ export const firstAddressFailure = (failurePayload) => ({
type: types.FIRSTADDRESS_FAILURE,
payload: failurePayload,
});

/**
* Request the downalod of token metadata for a list of tokens.
pedroferreira1 marked this conversation as resolved.
Show resolved Hide resolved
* @param {string[]} tokens A list of token uid
*/
export const tokensFetchMetadataRequest = (tokens) => ({
pedroferreira1 marked this conversation as resolved.
Show resolved Hide resolved
type: types.TOKENS_FETCH_METADATA_REQUESTED,
tokens
});

/**
* Signals update on new nano contract status to ready.
*/
export const setNewNanoContractStatusReady = () => ({
type: types.WALLETCONNECT_NEW_NANOCONTRACT_STATUS,
payload: WALLETCONNECT_NEW_NANOCONTRACT_TX_STATUS.READY,
});

/**
* Signals update on new nano contract status to loading.
*/
export const setNewNanoContractStatusLoading = () => ({
type: types.WALLETCONNECT_NEW_NANOCONTRACT_STATUS,
payload: WALLETCONNECT_NEW_NANOCONTRACT_TX_STATUS.LOADING,
});

/**
* Signals update on new nano contract status to failed.
*/
export const setNewNanoContractStatusFailure = () => ({
type: types.WALLETCONNECT_NEW_NANOCONTRACT_STATUS,
payload: WALLETCONNECT_NEW_NANOCONTRACT_TX_STATUS.FAILED,
});

/**
* Signals update on new nano contract status to successful.
*/
export const setNewNanoContractStatusSuccess = () => ({
type: types.WALLETCONNECT_NEW_NANOCONTRACT_STATUS,
payload: WALLETCONNECT_NEW_NANOCONTRACT_TX_STATUS.SUCCESSFUL,
});

/**
* Blueprint Info request in the context of a Nano Contract.
* @param {string} id Blueprint ID.
*/
export const nanoContractBlueprintInfoRequest = (id) => ({
type: types.NANOCONTRACT_BLUEPRINTINFO_REQUEST,
payload: { id },
});

/**
* Signals the bluprint info request has failed.
* @param {string} id Blueprint ID.
* @param {string} error Request failure reason.
*/
export const nanoContractBlueprintInfoFailure = (id, error) => ({
type: types.NANOCONTRACT_BLUEPRINTINFO_FAILURE,
payload: { id, error },
});

/**
* Signals the blueprint info was fetched with success.
* @param {string} id Blueprint ID.
* @param {{
* id: string;
* name: string;
* public_methods: {
* [methodName: string]: {
* args: {
* type: string;
* name: string;
* }[];
* };
* };
* }} blueprintInfo Raw data response from fullnode.
*/
export const nanoContractBlueprintInfoSuccess = (id, blueprintInfo) => ({
type: types.NANOCONTRACT_BLUEPRINTINFO_SUCCESS,
payload: { id, data: { ...blueprintInfo } },
});

/**
* Signals the blueprint info state is ready.
* @param {string} id Blueprint ID.
*/
export const nanoContractBlueprintInfoReady = (id) => ({
type: types.NANOCONTRACT_BLUEPRINTINFO_READY,
payload: { id },
});
28 changes: 25 additions & 3 deletions src/components/FeedbackContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { COLORS } from '../styles/themes';
* @param {Object?} props.action A react component or react element containing a call to action,
* if provided, it renders underneath the content
* @param {boolean} props.offcard Renders a feedback without card style
* @param {boolean} props.offmargin Renders a feedback without margins
*
* @example
* <FeedbackContent
Expand All @@ -34,8 +35,22 @@ import { COLORS } from '../styles/themes';
* action={<TryAgain ncId={ncId} />}
* />
*/
export const FeedbackContent = ({ title, message, icon, action, offcard }) => (
<View style={[styles.container, !offcard && styles.card]}>
export const FeedbackContent = ({
title,
message,
icon,
action,
offcard,
offmargin,
offbackground
}) => (
<View style={[
styles.container,
!offcard && styles.card,
offmargin && styles.offMargin,
offbackground && styles.offBackground
]}
>
<View style={styles.wrapper}>
<View style={styles.content}>
{icon
Expand All @@ -55,8 +70,8 @@ const styles = StyleSheet.create({
alignSelf: 'stretch',
marginTop: 16,
marginBottom: 45,
backgroundColor: COLORS.backgroundColor,
marginHorizontal: 16,
backgroundColor: COLORS.backgroundColor,
},
card: {
borderRadius: 16,
Expand All @@ -65,6 +80,13 @@ const styles = StyleSheet.create({
shadowColor: COLORS.textColor,
shadowOpacity: 0.08,
},
offMargin: {
marginHorizontal: 0,
marginVertical: 0,
},
offBackground: {
backgroundColor: COLORS.lowContrastDetail,
},
wrapper: {
overflow: 'scroll',
},
Expand Down
13 changes: 13 additions & 0 deletions src/components/FeedbackModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ import { Text, View } from 'react-native';
import PropTypes from 'prop-types';
import HathorModal from './HathorModal';

/**
* It renders a modal with some feedback to user.
*
* @param {Object} props
*
* @example
* <FeedbackModal
* icon={(<Image source={errorIcon} resizeMode='contain' />)}
* text={t`Error while sending transaction.`}
* onDismiss={handleFeedbackModalDismiss}
* action={(<NewHathorButton discrete title={t`Ok, close`} onPress={handleErrorModalAction} />)}
* />
*/
const FeedbackModal = (props) => (
<HathorModal
onDismiss={props.onDismiss}
Expand Down
30 changes: 30 additions & 0 deletions src/components/FrozenTextValue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Copyright (c) Hathor Labs and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import React from 'react';
import { TextValue } from './TextValue';

/**
* @param {Object} props
* @param {boolean} props.title It sets font weight to bold and a larger font size
* @param {boolean} props.bold It sets font weight to bold
* @param {boolean} props.oneline It sets numberOfLines to 1
* @param {boolean} props.shrink It sets flexShrink to 1
* @param {boolean} props.pb4 It sets padding bottom to 4
*/
export const FrozenTextValue = ({ title, bold, oneline, shrink, pb4, children }) => (
pedroferreira1 marked this conversation as resolved.
Show resolved Hide resolved
<TextValue
color='hsla(0, 0%, 38%, 1)'
title={title}
bold={bold}
oneline={oneline}
shrink={shrink}
pb4={pb4}
>
{children}
</TextValue>
);
2 changes: 1 addition & 1 deletion src/components/HathorFlatList.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { COLORS } from '../styles/themes';
* param {FlatListProps} props
*/
export const HathorFlatList = (props) => (
<View style={styles.wrapper}>
<View style={[styles.wrapper, props.wrapperStyle]}>
andreabadesso marked this conversation as resolved.
Show resolved Hide resolved
<FlatList
ItemSeparatorComponent={ItemSeparator}
// Introduced last to allow overwrite
Expand Down
2 changes: 1 addition & 1 deletion src/components/Icons/CircleInfo.icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const CircleInfoIcon = ({ size = 20, color = COLORS.white }) => (
>
<G clipPath='url(#a)'>
<Path
fill='#004F7E'
fill={color}
d='M9.167 5.833h1.666V7.5H9.167V5.833Zm0 3.334h1.666v5H9.167v-5Zm.833-7.5A8.336 8.336 0 0 0 1.667 10c0 4.6 3.733 8.333 8.333 8.333S18.333 14.6 18.333 10 14.6 1.667 10 1.667Zm0 15A6.675 6.675 0 0 1 3.333 10 6.676 6.676 0 0 1 10 3.333 6.676 6.676 0 0 1 16.667 10 6.675 6.675 0 0 1 10 16.667Z'
/>
</G>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import { combineURLs, getShortContent, getShortHash, getTimestampFormat } from '../../utils';
import SimpleButton from '../SimpleButton';
import { ArrowDownIcon } from '../Icons/ArrowDown.icon';
import { ArrowUpIcon } from '../Icons/ArrowUp.icon';

Check warning on line 23 in src/components/NanoContract/NanoContractTransactionHeader.js

View workflow job for this annotation

GitHub Actions / test (14.x)

'ArrowUpIcon' is defined but never used

Check warning on line 23 in src/components/NanoContract/NanoContractTransactionHeader.js

View workflow job for this annotation

GitHub Actions / test (16.x)

'ArrowUpIcon' is defined but never used
andreabadesso marked this conversation as resolved.
Show resolved Hide resolved
import { TextValue } from '../TextValue';
import { TextLabel } from '../TextLabel';
import { TransactionStatusLabel } from '../TransactionStatusLabel';
Expand Down
11 changes: 10 additions & 1 deletion src/components/TextValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,28 @@ import {
StyleSheet,
Text,
} from 'react-native';
import { commonStyles } from './WalletConnect/theme';

/**
* @param {Object} props
* @param {boolean} props.title It sets font weight to bold and a larger font size
* @param {boolean} props.label It sets font weight to bold and a bottom margin
* @param {boolean} props.bold It sets font weight to bold
* @param {boolean} props.oneline It sets numberOfLines to 1
* @param {boolean} props.shrink It sets flexShrink to 1
* @param {boolean} props.pb4 It sets padding bottom to 4
* @param {string} props.color It sets text color
*/
export const TextValue = ({ title, bold, oneline, shrink, pb4, children }) => (
export const TextValue = ({ title, label, bold, oneline, shrink, pb4, color, children }) => (
<Text style={[
styles.textValue,
title && styles.title,
label && styles.label,
oneline && styles.oneline,
shrink && styles.shrink,
bold && styles.bold,
pb4 && styles.pb4,
color && { color },
]}
>{children}</Text>
);
Expand All @@ -41,6 +46,10 @@ const styles = StyleSheet.create({
fontSize: 18,
fontWeight: 'bold',
},
label: [
commonStyles.bold,
commonStyles.mb4,
],
pb4: {
paddingBottom: 4,
},
Expand Down
Loading
Loading