Skip to content

Commit

Permalink
Sats connect RPC support (#141)
Browse files Browse the repository at this point in the history
* release: v0.31.0

* RPC Wallet Api & BTC handlers (#85)

* WIP: Inject Xverse Webbtc_provider and add request method

* refactor dom event names

* fix send back wallet response

* Start adding stacks request types

* Add placeholders for stx rpc calls

* Sort methods alphabetically

* Reword key RPC methods and types

* Revert "Start adding stacks request types"

This reverts commit 6afcacd.

* update sats-connect version and init rpc handlers

* rebase fixes

* fix duplicate type

* Move helper function out of legacy code

* BTC RPC handlers (#92)

* handle getAddresses request

* WIP Add Support for BTC RPC Methods

* added error request component and refactor psbt request

* separate stx and btc signMessage screens

* update hooks file structure

* return errors as resolved promises instead of rejecting

* update btcAddressRequest hook

* update request handling hooks

* add ledger ui for btc signMessage screen

* chore: bump core to 11.2.0

* chore: remove unnecessary type default

* fix: type errors

---------

Co-authored-by: Eduard Bardají Puig <[email protected]>
Co-authored-by: Tim Man <[email protected]>

* [ENG-3844][ENG-3845][ENG-3850][ENG-3851] stx_callContract, stx_transferStx, stx_getAccounts, stx_getAddresses (#112)

* Add placeholders for stx rpc handlers

* Move helpers to own file

* Remove unused

* Add various changes related to request handling

* Add rpc method param for transaction request type differentiation

* Add response message

* Add rpc method to request params

* Provide rpc response based on rpc call method

* Handle missing function args

* Move error messages to constants

* Add missing rpc method

* Remove unnecessary type

* Refine variable name

* Prevent unknown errors from blocking navigation

* Add rpc props

* Remove unnecessary conditional

* Send rpc response after broadcast

* Start updating ContractCall to RPC request

* Handle contract deploy request

* Update rpc response type

* Add rpc props

* Remove sign message work from this branch

* Simplify request handling

* Rename file

* Add handler and helpers for contractCall

* Rename handler file

* Update hook to handle callContract

* Perform minor tweaks for callContract

* fix: updated sats connect version and stacks methods names

* feat: handle stx_transferStx method

* Use Zod union

* Fix minor issues

* Add stx_getAccounts and stx_getAddresses method handlers

* Update the handleGetStxAccounts method

* Update types

* Remove unimplemented methods

* Refactor send message helpers

* Update params type

* Remove unused prop

* Move messages to translation file

* Add useMemo and useCallback to accounts and address fetching hooks

* Refactor the getAppIconFromWebManifest fetching

* Refactor the getAppIconFromWebManifest fetching useEffect

* Use existing payload format

* Move hook close to component using it

* Replace the ternary return with if statement

---------

Co-authored-by: Abdul Haseeb <[email protected]>
Co-authored-by: Denys Hriaznov <[email protected]>

* fix amount conversion

* close sendTransfer popup after tx_broadcasted

* [ENG-3860] chore: remove name palindrome support (#104)

* chore: use beta core version for testing

* chore: be more strict with typing as in mobile repo

* chore: bump to xverse-core 11.2.0

* Stacks RPC method: `stx_signTransaction` (#100)

* Handle stx token transfer sign tx reqs

* Hande tx signing for deploy contract

* Use payload type checker

* Update params stx_getAccounts (#121)

* Update params stx_getAccounts

* Add user cancellation handling

* Update params stx_getAddresses (#122)

* Eng 3846 stx signmessage (#119)

* WIP: Update Stacks Message signing and refactor signature screen

* added rpc response handling

* disable structured message signing for rpc

* update signature hook dependency params

* Update to sats-connect v2 (#123)

* Chore/return supported methods (#120)

* return supported methods for getInfo

* Add keys transformer to prod loaders

---------

Co-authored-by: Eduard Bardají Puig <[email protected]>

* Support stx_deployContract

* Update sats-connect version

* [ENG-3847] Update stx_signStructuredMessage handling (#131)

* Update stx_signStructuredMessage handling

* Rename file

* Update renamed file path

* added support for get accounts request

* ui improvements

* remove methods automatic generation

* Squashed commit of the following:

commit 66fafe6
Author: Den <[email protected]>
Date:   Mon Mar 25 06:52:07 2024 +0100

    [ENG-3340] feat: Add UI warning about the Non default sighash Ledger alert (#97)

    * [ENG-3340] feat: Add UI warning about the Non default sighash Ledger alert

    * Fix tooltip hiding

    * Update the info message copy

    * Create a separate LedgerStepView component

    * Remove the unused imports

    * Remove the Steps enum duplicate

commit 59ae427
Author: Victor Kirov <[email protected]>
Date:   Mon Mar 25 06:56:11 2024 +0200

    Add sighash none warning (#152)

    * Add sighash none warning

    * Fix spacing

    ---------

    Co-authored-by: Den <[email protected]>

commit 5759028
Author: Den <[email protected]>
Date:   Mon Mar 25 05:36:10 2024 +0100

    [ENG-3972] fix: Issue with balance sip-10 tokens fiat value does not add up to the total balance (#151)

commit a62315f
Author: fede erbes <[email protected]>
Date:   Mon Mar 25 05:02:46 2024 +0100

    fix: qr config, avoid hiding dots covered by image (#154)

commit 3980cae
Author: fede erbes <[email protected]>
Date:   Mon Mar 25 04:50:16 2024 +0100

    fix: remove satributes component from receive section in payment address (#133)

    * fix: remove satributes component from receive section in payment address

    * chore: fix logic

    * chore: fix logic for all cases

commit 6c08ff9
Author: Den <[email protected]>
Date:   Mon Mar 25 04:49:04 2024 +0100

    [ENG-3937] Replace the old STX logo leftovers on the web-extension (#143)

    * [ENG-3937] Replace the old STX logo leftovers on the web-extension

    * Update the styled components names

commit 10653d1
Author: Den <[email protected]>
Date:   Thu Mar 21 11:10:40 2024 +0100

    [ENG-3477] feat: Open the onboarding screen right after user installs the extension (#86)

    * [ENG-3477] feat: Open the onboarding screen right after user installs the extension

    * Use the ui-library/button component instead of the ActionButton

    * Remove the tabs permission from the manifest config

    * Remove the custom old button styles

    * Fix the onboarding animation container

    * Improve the account restore/creation flow accessibility

commit 45cf27e
Merge: 5454e94 4054f22
Author: Tim Man <[email protected]>
Date:   Tue Mar 19 16:07:15 2024 +0800

    Merge pull request #148 from secretkeylabs/release/v0.32.3

    release: v0.32.3 to develop

commit 4054f22
Merge: edd60ed 2db9d91
Author: fede erbes <[email protected]>
Date:   Mon Mar 18 18:21:31 2024 +0100

    Merge branch 'main' into release/v0.32.3

commit edd60ed
Author: GitHub Actions Bot <>
Date:   Mon Mar 18 17:20:22 2024 +0000

    release: v0.32.3

commit 5454e94
Author: fede erbes <[email protected]>
Date:   Mon Mar 18 18:19:35 2024 +0100

    chore: restore max button in send btc flow (#146)

    * chore: restore max button in send btc flow

    * chore: use release core v13.0.0

commit e07287f
Merge: 895c89a dfe4fd2
Author: fede erbes <[email protected]>
Date:   Mon Mar 18 11:51:59 2024 +0100

    Merge pull request #144 from secretkeylabs/release/v0.32.2-mirror

    Hotfix: v0.32.2

commit dfe4fd2
Merge: 9371643 895c89a
Author: Tim Man <[email protected]>
Date:   Mon Mar 18 12:16:08 2024 +0800

    Merge branch 'develop' into release/v0.32.2-mirror

commit 2db9d91
Merge: da0c803 9371643
Author: Tim Man <[email protected]>
Date:   Mon Mar 18 12:15:40 2024 +0800

    Merge pull request #145 from secretkeylabs/release/v0.32.2-mirror

    Hotfix: v0.32.2

commit 895c89a
Merge: 0782b5c ea9a07f
Author: Tim Man <[email protected]>
Date:   Mon Mar 18 12:12:53 2024 +0800

    Merge pull request #140 from secretkeylabs/release/v0.32.1

    release: v0.32.1 to develop

commit da0c803
Merge: 166ada9 ea9a07f
Author: Tim Man <[email protected]>
Date:   Mon Mar 18 12:12:38 2024 +0800

    Merge pull request #139 from secretkeylabs/release/v0.32.1

    release: v0.32.1 to main

commit 9371643
Author: fede erbes <[email protected]>
Date:   Fri Mar 15 18:47:23 2024 -0300

    chore: disable max button and bump version

commit ea9a07f
Merge: 723aec8 166ada9
Author: Tim Man <[email protected]>
Date:   Fri Mar 15 12:09:27 2024 +0800

    Merge branch 'main' into release/v0.32.1

commit 723aec8
Author: GitHub Actions Bot <>
Date:   Fri Mar 15 04:08:50 2024 +0000

    release: v0.32.1

commit 166ada9
Merge: 6a8671f d7c9170
Author: Tim Man <[email protected]>
Date:   Thu Mar 14 23:56:42 2024 +0800

    Merge pull request #125 from secretkeylabs/release/v0.32.0

    release: v0.32.0 to main

* Revert "Squashed commit of the following:"

This reverts commit 6da6efe.

* use wallet methods for btc_providers entry

* hardcode supported methods

* display a dapp provided message for getAccounts request

* update getAccounts to require a purpose passed

* update sats-connect version

* chore: bump to [email protected]

---------

Co-authored-by: GitHub Actions Bot <>
Co-authored-by: Tim Man <[email protected]>
Co-authored-by: Eduard Bardají Puig <[email protected]>
Co-authored-by: Abdul Haseeb <[email protected]>
Co-authored-by: Denys Hriaznov <[email protected]>
  • Loading branch information
5 people authored Mar 27, 2024
1 parent 9e3ba2b commit b0f8c32
Show file tree
Hide file tree
Showing 81 changed files with 4,190 additions and 1,758 deletions.
787 changes: 66 additions & 721 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,16 @@
"redux": "^4.0.5",
"redux-persist": "^6.0.0",
"redux-state-sync": "^3.1.4",
"sats-connect": "1.4.0",
"sats-connect": "2.1.0",
"stream-browserify": "^3.0.0",
"string-to-color": "^2.2.2",
"styled-components": "^5.3.5",
"superjson": "2.2.1",
"swiper": "11.0.6",
"ts-transformer-keys": "0.4.4",
"valid-url": "^1.0.9",
"webextension-polyfill": "^0.10.0",
"zod": "3.22.4",
"zxcvbn": "^4.4.2"
},
"scripts": {
Expand Down
7 changes: 4 additions & 3 deletions src/app/components/rareSatIcon/rareSatIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ interface Props {
}

function RareSatIcon({ type, size }: Props) {
const src = {
const sourceByType: Record<RareSatsType, string> = {
EPIC: Epic,
LEGENDARY: Legendary,
MYTHIC: Mythic,
Expand All @@ -61,7 +61,7 @@ function RareSatIcon({ type, size }: Props) {
PERFECT_PALINCEPTION: Palinception,
PALIBLOCK_PALINDROME: BlockPali,
PALINDROME: Palindrome,
NAME_PALINDROME: Palindrome,
// NAME_PALINDROME: Palindrome,
ALPHA: Alpha,
OMEGA: Omega,
FIRST_TRANSACTION: FirstTx,
Expand All @@ -73,7 +73,8 @@ function RareSatIcon({ type, size }: Props) {
JPEG: Jpeg,
HITMAN: Hitman,
SILK_ROAD: SilkRoad,
}[type];
};
const src = sourceByType[type];
if (!src) {
return null;
}
Expand Down
73 changes: 73 additions & 0 deletions src/app/components/requests/requestError.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import Failure from '@assets/img/send/x_circle.svg';
import Button from '@ui-library/button';
import { useTranslation } from 'react-i18next';
import styled from 'styled-components';
/**
* A component that displays an error message when a request fails. due to an error in the request payload
*/

const Container = styled.div((props) => ({
background: props.theme.colors.elevation0,
display: 'flex',
flexDirection: 'column',
height: '100%',
paddingLeft: props.theme.spacing(8),
paddingRight: props.theme.spacing(8),
paddingTop: props.theme.spacing(60),
}));

const Image = styled.img({
alignSelf: 'center',
width: 88,
height: 88,
});

const HeadingText = styled.h1((props) => ({
...props.theme.typography.headline_xs,
color: props.theme.colors.white_0,
textAlign: 'center',
marginTop: props.theme.spacing(8),
}));

const BodyText = styled.h1((props) => ({
...props.theme.typography.body_l,
color: props.theme.colors.white_200,
marginTop: props.theme.spacing(8),
textAlign: 'center',
overflowWrap: 'break-word',
wordWrap: 'break-word',
wordBreak: 'break-word',
marginBottom: props.theme.spacing(42),
}));

const CloseButton = styled(Button)((props) => ({
marginBottom: props.theme.spacing(42),
}));

interface RequestErrorProps {
errorTitle?: string;
error: string;
onClose?: () => void;
}

function RequestError({ error, errorTitle, onClose }: RequestErrorProps) {
const { t } = useTranslation('translation', { keyPrefix: 'REQUEST_ERRORS' });

const handleClose = () => {
if (onClose) {
onClose();
} else {
window.close();
}
};
return (
<Container>
<Image src={Failure} />
<HeadingText>{errorTitle || t('INVALID_REQUEST')}</HeadingText>
<BodyText>{error}</BodyText>
<CloseButton onClick={handleClose} title="Close" variant="secondary" />
</Container>
);
}

export default RequestError;
154 changes: 116 additions & 38 deletions src/app/components/transactionsRequests/ContractCallRequest.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import {
sendCallContractSuccessResponseMessage,
sendInternalErrorMessage,
sendSignTransactionSuccessResponseMessage,
sendUserRejectionMessage,
} from '@common/utils/rpc/stx/rpcResponseMessages';
import AccountHeaderComponent from '@components/accountHeader';
import ConfirmStxTransactionComponent from '@components/confirmStxTransactionComponent';
import InfoContainer from '@components/infoContainer';
Expand All @@ -8,24 +14,24 @@ import TransactionDetailComponent from '@components/transactionDetailComponent';
import useNetworkSelector from '@hooks/useNetwork';
import useOnOriginTabClose from '@hooks/useOnTabClosed';
import {
addressToString,
Args,
broadcastSignedTransaction,
buf2hex,
Coin,
ContractFunction,
addressToString,
broadcastSignedTransaction,
buf2hex,
extractFromPayload,
isMultiSig,
} from '@secretkeylabs/xverse-core';
import { ContractCallPayload } from '@stacks/connect';
import {
ClarityType,
cvToJSON,
cvToString,
MultiSigSpendingCondition,
PostConditionType,
SomeCV,
StacksTransaction,
cvToJSON,
cvToString,
} from '@stacks/transactions';
import { createContext, useState } from 'react';
import { useTranslation } from 'react-i18next';
Expand Down Expand Up @@ -75,15 +81,26 @@ interface ContractCallRequestProps {
funcMetaData: ContractFunction | undefined;
coinsMetaData: Coin[] | null;
tabId: number;
messageId: string | null;
rpcMethod: string | null;
requestToken: string;
attachment: Buffer | undefined;
}

export const ShowMoreContext = createContext({ showMore: false });

export default function ContractCallRequest(props: ContractCallRequestProps) {
const { request, unsignedTx, funcMetaData, coinsMetaData, tabId, requestToken, attachment } =
props;
const {
request,
unsignedTx,
funcMetaData,
coinsMetaData,
tabId,
requestToken,
attachment,
messageId,
rpcMethod,
} = props;
const selectedNetwork = useNetworkSelector();
const [hasTabClosed, setHasTabClosed] = useState(false);
const { t } = useTranslation('translation');
Expand Down Expand Up @@ -175,61 +192,122 @@ export default function ContractCallRequest(props: ContractCallRequestProps) {
txAttachment: Buffer | undefined = undefined,
) => {
try {
const broadcastResult: string = await broadcastSignedTransaction(
tx[0],
selectedNetwork,
txAttachment,
);
if (broadcastResult) {
const txId = await broadcastSignedTransaction(tx[0], selectedNetwork, txAttachment);
if (tabId && messageId && rpcMethod) {
switch (rpcMethod) {
case 'stx_signTransaction': {
sendSignTransactionSuccessResponseMessage({
tabId,
messageId,
result: { transaction: buf2hex(tx[0].serialize()) },
});
break;
}
case 'stx_callContract': {
sendCallContractSuccessResponseMessage({
tabId,
messageId,
result: {
transaction: buf2hex(tx[0].serialize()),
txid: txId,
},
});
break;
}
default: {
sendInternalErrorMessage({ tabId, messageId });
}
}
} else {
finalizeTxSignature({
requestPayload: requestToken,
tabId,
data: { txId: broadcastResult, txRaw: buf2hex(tx[0].serialize()) },
});
navigate('/tx-status', {
state: {
txid: broadcastResult,
currency: 'STX',
error: '',
browserTx: true,
},
data: { txId, txRaw: buf2hex(tx[0].serialize()) },
});
}
navigate('/tx-status', {
state: {
txid: txId,
currency: 'STX',
error: '',
browserTx: true,
tabId,
messageId,
rpcMethod,
},
});
} catch (e) {
if (e instanceof Error) {
navigate('/tx-status', {
state: {
txid: '',
currency: 'STX',
error: e.message,
browserTx: true,
},
});
}
sendInternalErrorMessage({ tabId, messageId });
navigate('/tx-status', {
state: {
txid: '',
currency: 'STX',
error: e instanceof Error ? e.message : 'An error occurred',
browserTx: true,
tabId,
messageId,
rpcMethod,
},
});
}
};

const confirmCallback = (transactions: StacksTransaction[]) => {
if (request?.sponsored) {
if (rpcMethod && tabId && messageId) {
switch (rpcMethod) {
case 'stx_signTransaction': {
sendSignTransactionSuccessResponseMessage({
tabId,
messageId,
result: { transaction: buf2hex(unsignedTx.serialize()) },
});
break;
}
default: {
sendInternalErrorMessage({ tabId, messageId });
}
}
}
navigate('/tx-status', {
state: {
sponsored: true,
browserTx: true,
},
});
} else if (isMultiSigTx) {
finalizeTxSignature({
requestPayload: requestToken,
tabId,
data: { txId: '', txRaw: buf2hex(unsignedTx.serialize()) },
});
if (rpcMethod && tabId && messageId) {
switch (rpcMethod) {
case 'stx_signTransaction': {
sendSignTransactionSuccessResponseMessage({
tabId,
messageId,
result: { transaction: buf2hex(unsignedTx.serialize()) },
});
break;
}
default: {
sendInternalErrorMessage({ tabId, messageId });
}
}
} else {
finalizeTxSignature({
requestPayload: requestToken,
tabId,
data: { txId: '', txRaw: buf2hex(unsignedTx.serialize()) },
});
}
window.close();
} else {
broadcastTx(transactions, attachment);
}
};
const cancelCallback = () => {
finalizeTxSignature({ requestPayload: requestToken, tabId, data: 'cancel' });
if (tabId && messageId) {
sendUserRejectionMessage({ tabId, messageId });
} else {
finalizeTxSignature({ requestPayload: requestToken, tabId, data: 'cancel' });
}
window.close();
};

Expand Down
Loading

0 comments on commit b0f8c32

Please sign in to comment.