Skip to content

feat: send tokens rpc #735

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

Merged
merged 70 commits into from
Apr 16, 2025
Merged
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
d863661
feat: added reown components, packages and modal
andreabadesso Dec 26, 2024
db57974
chore: stop using null-loader for pino
andreabadesso Dec 27, 2024
ef7e3af
chore: added lavamoat policy for walletconnect deps
andreabadesso Dec 27, 2024
f419d6d
chore: updated walletconnect deps
andreabadesso Dec 27, 2024
e0d100c
refactor: global reown module
andreabadesso Dec 30, 2024
4fa8a38
chore: better sourcemaps by providing full webpack path
andreabadesso Jan 1, 2025
e001ee2
chore: normalize walletconnect packages to include eventClient requir…
andreabadesso Jan 1, 2025
ae0e5be
feat: modals implementation
andreabadesso Jan 1, 2025
a65f58a
fix: using bigint on txData screen
andreabadesso Jan 2, 2025
3a44194
fix: using bigint on nano contract detail screen
andreabadesso Jan 2, 2025
6152bef
feat: modals implementation
andreabadesso Jan 2, 2025
ddb6833
refactor: each modal on its own component
andreabadesso Jan 2, 2025
582c6a0
feat: network changed -> clear reown sessions
andreabadesso Jan 2, 2025
288c0f3
refactor: cosmetic changes to reown
andreabadesso Jan 2, 2025
6d14d1f
refactor: using separate methods for each nc action
andreabadesso Jan 2, 2025
02fe6ea
refactor: removed pointless logs
andreabadesso Jan 2, 2025
1300e43
feat: listen for feature toggle update
andreabadesso Jan 2, 2025
729c707
refactor: added hathor header
andreabadesso Jan 2, 2025
4eb067f
refactor: removed unused helper method
andreabadesso Jan 2, 2025
399585a
chore: added comment explaining serialization check
andreabadesso Jan 2, 2025
f9fe19b
fix: added missing action types
andreabadesso Jan 2, 2025
1c55f54
fix: moved reown feature toggle
andreabadesso Jan 2, 2025
f862034
refactor: correct docstrings in reown module
andreabadesso Jan 2, 2025
4d8170d
feat: added missing handlers
andreabadesso Jan 2, 2025
f961ee3
refactor: removed useless delay
andreabadesso Jan 2, 2025
6b626c6
refactor: improved debug log
andreabadesso Jan 2, 2025
a4617c5
chore: fixed walletkit version
andreabadesso Jan 2, 2025
265efae
chore: updated lavamoat policy with new fixed versions
andreabadesso Jan 2, 2025
978e729
refactor: use constants
andreabadesso Jan 24, 2025
afa90fe
docs: added a TODO on create token modal
andreabadesso Jan 24, 2025
69004f6
refactor: removed ternary in jsx
andreabadesso Jan 29, 2025
055fa48
refactor: error when modalContext is unavailable
andreabadesso Jan 29, 2025
d7146a1
refactor: single selector for multiple states
andreabadesso Jan 29, 2025
13dbe5b
refactor: accept -> acceptCb
andreabadesso Jan 30, 2025
abb2fc6
feat: initial implementation of send tokens RPC handling
andreabadesso Feb 12, 2025
b810873
feat: added send transaction modal and reown saga
andreabadesso Feb 17, 2025
0416537
feat: better handling of transactions
andreabadesso Feb 19, 2025
80ab921
feat: automatically register unregistered tokens
andreabadesso Feb 20, 2025
bebc7f3
chore: removed test rpc lib
andreabadesso Feb 20, 2025
5f9897e
refactor: removed unused console.log
andreabadesso Feb 20, 2025
0677236
feat: data outputs being rendered properly, handling insufficient bal…
andreabadesso Feb 24, 2025
c0332a2
feat: CopyButton component
andreabadesso Feb 24, 2025
184bd0f
feat: merge with feat/reown
andreabadesso Mar 4, 2025
0154301
feat: user should be able to pick an address for the caller
andreabadesso Mar 4, 2025
775e78d
chore: updated policy and rpc lib import
andreabadesso Mar 4, 2025
31fb4cd
Merge branch 'feat/reown' into feat/send-tokens-rpc
andreabadesso Mar 6, 2025
e92e3a1
Merge branch 'feat/reown' into feat/send-tokens-rpc
andreabadesso Mar 14, 2025
db08966
refactor: review changes
andreabadesso Mar 14, 2025
801fd02
refactor: fall-through for send transaction and insufficient funds error
andreabadesso Mar 14, 2025
22ff4b9
refactor: stop requesting HTR token download
andreabadesso Mar 14, 2025
af74e59
refactor: using copy button component
andreabadesso Mar 14, 2025
a7c5cf8
refactor: use isNFT util
andreabadesso Mar 14, 2025
2573601
refactor: actually request token metadata
andreabadesso Mar 14, 2025
81857b0
refactor: stop defaulting to HTR
andreabadesso Mar 14, 2025
d88a0ee
feat: accept keyboard input
andreabadesso Mar 14, 2025
005cb4d
feat: prevent dismissal of modal by clicking outside
andreabadesso Mar 14, 2025
21d712a
refactor: stop converting to bigint explicitly in NanoContractActions
andreabadesso Mar 17, 2025
5345ac1
fix: wait for wallet to be ready and actually continue with the request
andreabadesso Mar 17, 2025
017bce7
refactor: stop importing constants directly from the constants file
andreabadesso Mar 17, 2025
332f310
Merge branch 'feat/reown' into feat/send-tokens-rpc
andreabadesso Mar 17, 2025
ee08b7b
refactor: Failure -> Failed
andreabadesso Mar 17, 2025
77661c3
Merge branch 'feat/reown' into feat/send-tokens-rpc
andreabadesso Mar 19, 2025
3ac1629
refactor: data is no longer an array
andreabadesso Mar 20, 2025
2552dda
refactor: passing correct props to SendTransactionModal
andreabadesso Mar 20, 2025
3971f79
refactor: stop using question mark as fallback
andreabadesso Mar 20, 2025
fab75c6
refactor: using the generic FeedbackModal in TransactionFeedbackModal
andreabadesso Mar 20, 2025
975d99f
refactor: use decimalPlaces in SendTransactionModal
andreabadesso Mar 20, 2025
2234f9d
refactor: using JSONBigInt for stringifying create token data
andreabadesso Mar 20, 2025
8b73e24
fix: stop crashing when invalid arguments are received (#756)
andreabadesso Apr 9, 2025
fc59efc
chore: using @hathor/hathor-rpc-handler
andreabadesso Apr 16, 2025
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
4 changes: 2 additions & 2 deletions config-overrides.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ module.exports = function override(config, env) {
process: stdLibBrowser.process,
stream: stdLibBrowser.stream,
os: stdLibBrowser.os,
vm: false,
events: stdLibBrowser.events,
util: stdLibBrowser.util
util: stdLibBrowser.util,
vm: false,
},
mainFields: ['browser', 'module', 'main'],
conditionNames: ['import', 'require', 'node', 'default'],
Expand Down
14 changes: 7 additions & 7 deletions lavamoat/webpack/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"setTimeout": true
},
"packages": {
"@hathor/hathor-rpc-handler>@hathor/wallet-lib>long": true,
"@hathor/wallet-lib>bitcore-lib": true,
"@hathor/wallet-lib>bitcore-mnemonic": true,
"@hathor/wallet-lib>crypto-js": true,
Expand All @@ -28,18 +27,13 @@
"axios": true,
"buffer": true,
"cypress>lodash": true,
"hathor-rpc-handler-test>@hathor/wallet-lib>long": true,
"node-stdlib-browser>assert": true,
"node-stdlib-browser>crypto-browserify": true,
"node-stdlib-browser>path-browserify": true,
"react-redux>@babel/runtime": true
}
},
"@hathor/hathor-rpc-handler>@hathor/wallet-lib>long": {
"globals": {
"WebAssembly.Instance": true,
"WebAssembly.Module": true
}
},
"@hathor/wallet-lib": {
"globals": {
"AbortController": true,
Expand Down Expand Up @@ -1115,6 +1109,12 @@
"npm-run-all>string.prototype.padend>es-abstract>object-inspect": true
}
},
"hathor-rpc-handler-test>@hathor/wallet-lib>long": {
"globals": {
"WebAssembly.Instance": true,
"WebAssembly.Module": true
}
},
"jquery": {
"globals": {
"define": true
Expand Down
23 changes: 23 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@
"resolutions": {
"axios": "1.7.7",
"@hathor/wallet-lib/axios": "1.7.7",
"@hathor/hathor-rpc-handler/@hathor/wallet-lib/axios": "1.7.7"
"@hathor/hathor-rpc-handler/@hathor/wallet-lib/axios": "1.7.7",
"bitcore-lib": "8.25.10",
"@hathor/wallet-lib/bitcore-lib": "8.25.10",
"@hathor/hathor-rpc-handler/@hathor/wallet-lib/bitcore-lib": "8.25.10",
"../hathor-rpc-lib/node_modules/bitcore-lib": "8.25.10",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this relative path right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not, I will change this as soon as the rpc-lib is published

"../hathor-rpc-lib/packages/hathor-rpc-handler/node_modules/@hathor/wallet-lib/node_modules/bitcore-lib": "8.25.10",
"../hathor-rpc-lib/packages/hathor-rpc-handler/node_modules/bitcore-lib": "8.25.10"
},
"dependencies": {
"@hathor/hathor-rpc-handler": "0.0.3-experimental-alpha",
Expand All @@ -48,6 +54,7 @@
"eslint-config-airbnb": "19.0.4",
"eslint-plugin-react": "7.33.2",
"font-awesome": "4.7.0",
"hathor-rpc-handler-test": "^0.0.39-experimental-alpha",
"jquery": "3.7.1",
"npm-run-all": "4.1.5",
"patch-package": "6.4.7",
Expand Down
96 changes: 95 additions & 1 deletion src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ export const types = {
REOWN_CREATE_TOKEN_STATUS_FAILED: 'REOWN_CREATE_TOKEN_STATUS_FAILED',
REOWN_CREATE_TOKEN_RETRY: 'REOWN_CREATE_TOKEN_RETRY',
REOWN_CREATE_TOKEN_RETRY_DISMISS: 'REOWN_CREATE_TOKEN_RETRY_DISMISS',
REOWN_SEND_TX_RETRY: 'REOWN_SEND_TX_RETRY',
REOWN_SEND_TX_RETRY_DISMISS: 'REOWN_SEND_TX_RETRY_DISMISS',
REOWN_SIGN_MESSAGE_RETRY: 'REOWN_SIGN_MESSAGE_RETRY',
REOWN_SIGN_MESSAGE_RETRY_DISMISS: 'REOWN_SIGN_MESSAGE_RETRY_DISMISS',
REOWN_ACCEPT: 'REOWN_ACCEPT',
Expand All @@ -94,6 +96,7 @@ export const types = {
SHOW_CREATE_TOKEN_REQUEST_MODAL: 'SHOW_CREATE_TOKEN_REQUEST_MODAL',
SHOW_SIGN_MESSAGE_REQUEST_MODAL: 'SHOW_SIGN_MESSAGE_REQUEST_MODAL',
SHOW_NANO_CONTRACT_SEND_TX_MODAL: 'SHOW_NANO_CONTRACT_SEND_TX_MODAL',
SHOW_SEND_TRANSACTION_REQUEST_MODAL: 'SHOW_SEND_TRANSACTION_REQUEST_MODAL',
REOWN_SESSION_PROPOSAL: 'REOWN_SESSION_PROPOSAL',
REOWN_SESSION_REQUEST: 'REOWN_SESSION_REQUEST',
REOWN_SESSION_DELETE: 'REOWN_SESSION_DELETE',
Expand All @@ -102,6 +105,14 @@ export const types = {
SHOW_GLOBAL_MODAL: 'SHOW_GLOBAL_MODAL',
HIDE_GLOBAL_MODAL: 'HIDE_GLOBAL_MODAL',
SERVER_INFO_UPDATED: 'SERVER_INFO_UPDATED',
REOWN_SEND_TX_STATUS_LOADING: 'REOWN_SEND_TX_STATUS_LOADING',
REOWN_SEND_TX_STATUS_READY: 'REOWN_SEND_TX_STATUS_READY',
REOWN_SEND_TX_STATUS_SUCCESS: 'REOWN_SEND_TX_STATUS_SUCCESS',
REOWN_SEND_TX_STATUS_FAILED: 'REOWN_SEND_TX_STATUS_FAILED',
UNREGISTERED_TOKENS_DOWNLOAD_REQUESTED: 'UNREGISTERED_TOKENS_DOWNLOAD_REQUESTED',
UNREGISTERED_TOKENS_DOWNLOAD_SUCCESS: 'UNREGISTERED_TOKENS_DOWNLOAD_SUCCESS',
UNREGISTERED_TOKENS_DOWNLOAD_FAILED: 'UNREGISTERED_TOKENS_DOWNLOAD_FAILED',
UNREGISTERED_TOKENS_DOWNLOAD_END: 'UNREGISTERED_TOKENS_DOWNLOAD_END',
};

/**
Expand Down Expand Up @@ -308,6 +319,14 @@ export const tokenFetchBalanceFailed = (tokenId) => ({
tokenId,
});

/**
* tokenId: The tokenId to request metadata from
*/
export const tokenFetchMetadataRequested = (tokenId) => ({
type: types.TOKEN_FETCH_METADATA_REQUESTED,
tokenId,
});

/**
* Flag indicating if we are using the atomic swap feature
*/
Expand Down Expand Up @@ -775,7 +794,7 @@ export const setNewNanoContractStatusSuccess = () => ({
});

/**
* Set nano contract status to failed
* Set nano contract status to failure
*/
export const setNewNanoContractStatusFailure = () => ({
type: types.REOWN_NEW_NANOCONTRACT_STATUS_FAILED,
Expand Down Expand Up @@ -871,6 +890,19 @@ export const showNanoContractSendTxModal = (onAccept, onReject, data, metadata)
payload: { accept: onAccept, deny: onReject, data, dapp: metadata },
});

/**
* Show modal for sending a transaction
*
* @param {Function} onAccept Callback function when user accepts the request
* @param {Function} onReject Callback function when user rejects the request
* @param {Object} data The transaction data
* @param {Object} metadata Metadata about the dapp requesting the transaction
*/
export const showSendTransactionModal = (onAccept, onReject, data, metadata) => ({
type: types.SHOW_SEND_TRANSACTION_REQUEST_MODAL,
payload: { accept: onAccept, deny: onReject, data, dapp: metadata },
});

/**
* @param {string} modalType The type of the modal to show
* @param {Object} modalProps The props to pass to the modal
Expand All @@ -886,3 +918,65 @@ export const showGlobalModal = (modalType, modalProps = {}) => ({
export const hideGlobalModal = () => ({
type: types.HIDE_GLOBAL_MODAL
});

/**
* Set send transaction status to loading
*/
export const setSendTxStatusLoading = () => ({
type: types.REOWN_SEND_TX_STATUS_LOADING,
});

/**
* Set send transaction status to ready
*/
export const setSendTxStatusReady = () => ({
type: types.REOWN_SEND_TX_STATUS_READY,
});

/**
* Set send transaction status to success
*/
export const setSendTxStatusSuccess = () => ({
type: types.REOWN_SEND_TX_STATUS_SUCCESS,
});

/**
* Set send transaction status to failed
*/
export const setSendTxStatusFailed = () => ({
type: types.REOWN_SEND_TX_STATUS_FAILED,
});

/**
* Request download of unregistered tokens details
* @param {string[]} uids Array of token UIDs to fetch details for
*/
export const unregisteredTokensDownloadRequested = (uids) => ({
type: types.UNREGISTERED_TOKENS_DOWNLOAD_REQUESTED,
payload: { uids },
});

/**
* Success downloading unregistered tokens details
* @param {Object} tokens Object with token details
*/
export const unregisteredTokensDownloadSuccess = (tokens) => ({
type: types.UNREGISTERED_TOKENS_DOWNLOAD_SUCCESS,
payload: { tokens },
});

/**
* Failure downloading unregistered tokens details
* @param {string} error Error message
*/
export const unregisteredTokensDownloadFailed = (error) => ({
type: types.UNREGISTERED_TOKENS_DOWNLOAD_FAILED,
payload: { error },
});

/**
* End of unregistered tokens download process
*/
export const unregisteredTokensDownloadEnd = () => ({
type: types.UNREGISTERED_TOKENS_DOWNLOAD_END,
});
27 changes: 27 additions & 0 deletions src/components/CopyButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* 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';

/**
* A reusable button component that copies text to clipboard
* @param {Object} props Component props
* @param {string} props.text Text to be copied
* @param {string} [props.className] Additional CSS classes
*/
export const CopyButton = ({ text, className = '' }) => {
if (!text) return null;

return (
<button
className={`btn btn-link btn-sm p-0 ml-2 ${className}`}
onClick={() => navigator.clipboard.writeText(text)}
>
<i className="fa fa-copy"></i>
</button>
);
};
3 changes: 3 additions & 0 deletions src/components/GlobalModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { PinPad } from './PinPad';
import { NanoContractFeedbackModal } from './Reown/NanoContractFeedbackModal';
import { TokenCreationFeedbackModal } from './Reown/TokenCreationFeedbackModal';
import { MessageSigningFeedbackModal } from './Reown/MessageSigningFeedbackModal';
import { TransactionFeedbackModal } from './Reown/TransactionFeedbackModal';
import ModalError from './ModalError';

const initialState = {
Expand Down Expand Up @@ -71,6 +72,7 @@ export const MODAL_TYPES = {
'REOWN': 'REOWN',
'PIN_PAD': 'PIN_PAD',
'NANO_CONTRACT_FEEDBACK': 'NANO_CONTRACT_FEEDBACK',
'TRANSACTION_FEEDBACK': 'TRANSACTION_FEEDBACK',
'TOKEN_CREATION_FEEDBACK': 'TOKEN_CREATION_FEEDBACK',
'MESSAGE_SIGNING_FEEDBACK': 'MESSAGE_SIGNING_FEEDBACK',
'ERROR_MODAL': 'ERROR_MODAL',
Expand Down Expand Up @@ -103,6 +105,7 @@ export const MODAL_COMPONENTS = {
[MODAL_TYPES.REOWN]: ReownModal,
[MODAL_TYPES.PIN_PAD]: PinPad,
[MODAL_TYPES.NANO_CONTRACT_FEEDBACK]: NanoContractFeedbackModal,
[MODAL_TYPES.TRANSACTION_FEEDBACK]: TransactionFeedbackModal,
[MODAL_TYPES.TOKEN_CREATION_FEEDBACK]: TokenCreationFeedbackModal,
[MODAL_TYPES.MESSAGE_SIGNING_FEEDBACK]: MessageSigningFeedbackModal,
[MODAL_TYPES.ERROR_MODAL]: ModalError,
Expand Down
13 changes: 13 additions & 0 deletions src/components/Reown/ReownModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ import { ConnectModal } from './modals/ConnectModal';
import { SignMessageModal } from './modals/SignMessageModal';
import { SignOracleDataModal } from './modals/SignOracleDataModal';
import { SendNanoContractTxModal } from './modals/SendNanoContractTxModal';
import { SendTransactionModal } from './modals/SendTransactionModal';
import { CreateTokenModal } from './modals/CreateTokenModal';

export const ReownModalTypes = {
CONNECT: 'CONNECT',
SIGN_MESSAGE: 'SIGN_MESSAGE',
SIGN_ORACLE_DATA: 'SIGN_ORACLE_DATA',
SEND_NANO_CONTRACT_TX: 'SEND_NANO_CONTRACT_TX',
SEND_TRANSACTION: 'SEND_TRANSACTION',
CREATE_TOKEN: 'CREATE_TOKEN',
};

Expand Down Expand Up @@ -54,6 +56,7 @@ export function ReownModal({ manageDomLifecycle, data, type, onAcceptAction, onR

const handleAccept = () => {
if (type === ReownModalTypes.SEND_NANO_CONTRACT_TX) {
// For nano contract transactions, we need to include the caller address
// Process the nano contract transaction
// Create a new object with the same properties
const ncData = {
Expand Down Expand Up @@ -94,6 +97,16 @@ export function ReownModal({ manageDomLifecycle, data, type, onAcceptAction, onR
/>
);

case ReownModalTypes.SEND_TRANSACTION:
return (
<SendTransactionModal
data={data}
firstAddress={firstAddress}
onAccept={handleAccept}
onReject={handleReject}
/>
);

case ReownModalTypes.CREATE_TOKEN:
return <CreateTokenModal data={data} onAccept={handleAccept} onReject={handleReject} />;

Expand Down
Loading