Skip to content

Commit 6a61474

Browse files
committed
fix demo so it uses transaction analysis
1 parent fe77b82 commit 6a61474

26 files changed

Lines changed: 460 additions & 1107 deletions

File tree

packages/wallet-sdk/examples/demo-app/src/app/demos/counter/transactions.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
import { Transaction } from '@mysten/sui/transactions';
5-
import { autoApproval } from '@mysten/wallet-sdk';
5+
import { operationType } from '@mysten/wallet-sdk';
66
import * as counterContract from '../../contracts/counter/counter.js';
77

88
interface CounterTransactionParams {
@@ -25,7 +25,7 @@ export function createCounterTransaction({ senderAddress }: CounterTransactionPa
2525
const tx = new Transaction();
2626

2727
// Add auto-approval intent for rule set selection
28-
tx.add(autoApproval('counter-operations'));
28+
tx.add(operationType('counter-operations'));
2929

3030
tx.setSenderIfNotSet(senderAddress);
3131

@@ -45,7 +45,7 @@ export function incrementCounterTransaction({
4545
const tx = new Transaction();
4646

4747
// Add auto-approval intent for rule set selection
48-
tx.add(autoApproval('counter-operations'));
48+
tx.add(operationType('counter-operations'));
4949

5050
tx.setSenderIfNotSet(senderAddress);
5151

@@ -72,7 +72,7 @@ export function resetCounterTransaction({
7272
const tx = new Transaction();
7373

7474
// Add auto-approval intent for rule set selection
75-
tx.add(autoApproval('counter-operations'));
75+
tx.add(operationType('counter-operations'));
7676

7777
tx.setSenderIfNotSet(senderAddress);
7878

packages/wallet-sdk/examples/demo-app/src/app/demos/nft/transactions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
import { Transaction } from '@mysten/sui/transactions';
5-
import { autoApproval } from '@mysten/wallet-sdk';
5+
import { operationType } from '@mysten/wallet-sdk';
66
import * as demoNftContract from '../../contracts/demo_nft/demo_nft.js';
77

88
/**
@@ -17,7 +17,7 @@ export function createMintNFTTransaction(params: {
1717
const tx = new Transaction();
1818

1919
// Add auto-approval intent for rule set selection
20-
tx.add(autoApproval('nft-creation'));
20+
tx.add(operationType('nft-creation'));
2121

2222
// Set sender
2323
tx.setSenderIfNotSet(params.senderAddress);

packages/wallet-sdk/examples/demo-app/src/app/demos/transfer/transactions.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
import { Transaction } from '@mysten/sui/transactions';
5-
import { autoApproval } from '@mysten/wallet-sdk';
5+
import { operationType } from '@mysten/wallet-sdk';
66
import type { SuiClient } from '@mysten/sui/client';
77

88
interface TransferTransactionParams {
@@ -28,7 +28,7 @@ export function createTransferAllSuiTransaction({
2828
const tx = new Transaction();
2929

3030
// Add auto-approval intent for rule set selection
31-
tx.add(autoApproval('basic-transfers'));
31+
tx.add(operationType('basic-transfers'));
3232

3333
tx.setSenderIfNotSet(senderAddress);
3434

@@ -49,7 +49,7 @@ export function createTransferSuiAmountTransaction({
4949
const tx = new Transaction();
5050

5151
// Add auto-approval intent for rule set selection
52-
tx.add(autoApproval('basic-transfers'));
52+
tx.add(operationType('basic-transfers'));
5353

5454
tx.setSenderIfNotSet(senderAddress);
5555

@@ -72,7 +72,7 @@ export async function createTransferAllCoinsTransaction(
7272
const tx = new Transaction();
7373

7474
// Add auto-approval intent for rule set selection
75-
tx.add(autoApproval('basic-transfers'));
75+
tx.add(operationType('basic-transfers'));
7676

7777
tx.setSenderIfNotSet(senderAddress);
7878

@@ -107,7 +107,7 @@ export async function createTransferCoinAmountTransaction(
107107
const tx = new Transaction();
108108

109109
// Add auto-approval intent for rule set selection
110-
tx.add(autoApproval('basic-transfers'));
110+
tx.add(operationType('basic-transfers'));
111111

112112
tx.setSenderIfNotSet(senderAddress);
113113

packages/wallet-sdk/examples/demo-app/src/app/demos/walrus/transactions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import { Transaction, coinWithBalance } from '@mysten/sui/transactions';
55
import { parseStructTag } from '@mysten/sui/utils';
6-
import { autoApproval } from '@mysten/wallet-sdk';
6+
import { operationType } from '@mysten/wallet-sdk';
77
import { TESTNET_WALRUS_PACKAGE_CONFIG } from '@mysten/walrus';
88
import type { SuiClient } from '@mysten/sui/client';
99

@@ -26,7 +26,7 @@ export async function createSwapSuiForWalTransaction(
2626
const tx = new Transaction();
2727

2828
// Add auto-approval intent for rule set selection
29-
tx.add(autoApproval('walrus-uploads'));
29+
tx.add(operationType('walrus-uploads'));
3030

3131
tx.setSenderIfNotSet(senderAddress);
3232

packages/wallet-sdk/examples/demo-app/src/wallet/components/core/DemoWalletUI.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export function DemoWalletUI() {
9191
</div>
9292

9393
{/* Transaction Approval Modal */}
94-
{walletRequest && typeof walletRequest.data !== 'string' && (
94+
{walletRequest && (
9595
<TransactionApprovalModal
9696
isOpen={!!walletRequest}
9797
walletRequest={walletRequest}

packages/wallet-sdk/examples/demo-app/src/wallet/components/signing/SigningModal.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
// Copyright (c) Mysten Labs, Inc.
22
// SPDX-License-Identifier: Apache-2.0
3-
import type { Transaction } from '@mysten/sui/transactions';
43
import type { ReadonlyWalletAccount } from '@mysten/wallet-standard';
54
import { SigningHeader } from './SigningHeader.js';
65
import { AccountDisplay } from './AccountDisplay.js';
76
import { PolicyStatusMessage } from './PolicyStatusMessage.js';
87
import { TransactionContent } from './TransactionContent.js';
98
import { AutoApprovalCountdown } from './AutoApprovalCountdown.js';
109
import { SigningActions } from './SigningActions.js';
11-
import type { TransactionAnalysis } from '@mysten/wallet-sdk';
10+
import type { AutoApprovalAnalysis } from '@mysten/wallet-sdk';
1211

1312
interface SigningModalProps {
1413
isOpen: boolean;
1514
account: ReadonlyWalletAccount;
1615
requestType: 'personalMessage' | 'transaction' | 'signAndExecute';
17-
transaction: Transaction | null;
1816
onApprove: () => void;
1917
onReject: () => void;
20-
analysis?: TransactionAnalysis | null; // null = still analyzing
18+
analysis?: AutoApprovalAnalysis | null; // null = still analyzing
2119
autoApprove?: {
2220
enabled: boolean;
2321
reason?: string;
@@ -48,7 +46,6 @@ export function SigningModal({
4846
isOpen,
4947
account,
5048
requestType,
51-
transaction,
5249
onApprove,
5350
onReject,
5451
analysis,
@@ -112,11 +109,7 @@ export function SigningModal({
112109
</div>
113110
</div>
114111
) : (
115-
<TransactionContent
116-
transaction={transaction}
117-
analysis={analysis}
118-
autoApprovalState={autoApprovalState}
119-
/>
112+
<TransactionContent analysis={analysis} autoApprovalState={autoApprovalState} />
120113
)}
121114
</div>
122115
)}

packages/wallet-sdk/examples/demo-app/src/wallet/components/signing/TransactionApprovalModal.tsx

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
// Copyright (c) Mysten Labs, Inc.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
import type { Transaction } from '@mysten/sui/transactions';
54
import { useAutoApproval } from '../../hooks/useAutoApproval.js';
65
import { SigningModal } from './SigningModal.js';
76
import { PolicyApprovalScreen } from '../policy/PolicyApprovalScreen.js';
87
import { getClientForNetwork } from '../../utils/suiClients.js';
98
import { useCallback, useState } from 'react';
10-
import type { WalletRequest } from '../../core/DemoWalletImpl.js';
9+
import type { WalletRequest } from '../../core/DemoWallet.js';
10+
import { useAnalysis } from '../../hooks/useAnalysis.js';
1111

1212
interface TransactionApprovalModalProps {
1313
walletRequest: WalletRequest;
14-
onApprove: (transaction: Transaction) => Promise<void>;
14+
onApprove: (txBytes: Uint8Array) => Promise<void>;
1515
onReject: (error: string) => void;
1616
onClose: () => void;
1717
isOpen: boolean;
@@ -24,39 +24,29 @@ export function TransactionApprovalModal({
2424
onClose: _onClose,
2525
isOpen,
2626
}: TransactionApprovalModalProps) {
27-
// Extract data from walletRequest
28-
29-
// walletRequest.data is now always a proper Transaction instance (converted in wallet impl)
30-
const transaction =
31-
typeof walletRequest.data === 'string'
32-
? null // Personal message case
33-
: (walletRequest.data as Transaction);
3427
const suiClient = getClientForNetwork(walletRequest.chain);
3528
const origin = walletRequest.origin;
3629

3730
// UI state - which modal to show
3831
const [showPolicyApproval, setShowPolicyApproval] = useState(false);
3932

33+
const analysis = useAnalysis(suiClient, walletRequest);
34+
4035
// Transaction auto-approval state - this drives the signing modal
41-
const [autoApprovalState, autoApprovalActions] = useAutoApproval(
42-
isOpen ? transaction : null,
43-
suiClient,
44-
origin,
45-
undefined, // ruleSetId is now extracted by AutoApprovalManager
46-
);
36+
const [autoApprovalState, autoApprovalActions] = useAutoApproval(analysis, suiClient, origin);
4737

4838
const handleSignAndApprove = useCallback(async () => {
4939
try {
50-
if (autoApprovalState.transaction) {
51-
await onApprove(autoApprovalState.transaction);
40+
if (analysis) {
41+
await onApprove(analysis.results.bytes);
5242
} else {
5343
throw new Error('No transaction to approve');
5444
}
5545
} catch (error) {
5646
console.error('❌ Failed to approve transaction:', error);
5747
onReject(`Transaction failed: ${error}`);
5848
}
59-
}, [autoApprovalState.transaction, onApprove, onReject]);
49+
}, [analysis, onApprove, onReject]);
6050

6151
const handleReject = () => {
6252
autoApprovalActions.rejectTransaction();
@@ -76,7 +66,7 @@ export function TransactionApprovalModal({
7666
// Remove the separate analyzing state rendering
7767

7868
// Show analysis error - don't allow approval when transaction analysis fails
79-
if (autoApprovalState.analysisError) {
69+
if (analysis?.issues.length) {
8070
return (
8171
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4">
8272
<div className="bg-white rounded-xl shadow-2xl max-w-md w-full p-6">
@@ -106,7 +96,7 @@ export function TransactionApprovalModal({
10696

10797
<div className="bg-red-50 border border-red-200 rounded-lg p-4 mb-4">
10898
<p className="text-sm text-red-800 font-medium">Error Details:</p>
109-
<p className="text-sm text-red-700 mt-1">{autoApprovalState.analysisError}</p>
99+
<p className="text-sm text-red-700 mt-1">{analysis.issues.join(', ')}</p>
110100
</div>
111101

112102
<div className="flex justify-end space-x-3">
@@ -133,7 +123,7 @@ export function TransactionApprovalModal({
133123
// Do NOT show when: policy is disabled, OR transaction is cancelled, OR already showing "Auto-Approval Cancelled" message
134124
const hasAvailablePolicy =
135125
autoApprovalState.policy &&
136-
(autoApprovalState.analysis as any)?.autoApproved && // Transaction matches policy rules
126+
autoApprovalState.canAutoApprove && // Transaction matches policy rules
137127
!autoApprovalState.cancelled && // Not cancelled
138128
(!autoApprovalState.hasExistingPolicy || // No policy exists yet, OR
139129
(autoApprovalState.hasExistingPolicy &&
@@ -190,8 +180,7 @@ export function TransactionApprovalModal({
190180
isOpen={isOpen}
191181
account={walletRequest.account}
192182
requestType="signAndExecute"
193-
transaction={autoApprovalState.transaction ?? null}
194-
analysis={autoApprovalState.isAnalyzing ? null : autoApprovalState.analysis}
183+
analysis={analysis}
195184
onApprove={handleSignAndApprove}
196185
onReject={handleReject}
197186
autoApprove={

packages/wallet-sdk/examples/demo-app/src/wallet/components/signing/TransactionContent.tsx

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
// Copyright (c) Mysten Labs, Inc.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
import type { Transaction } from '@mysten/sui/transactions';
54
import { TransactionDetails } from './transaction/TransactionDetails.js';
6-
import type { TransactionAnalysis } from '@mysten/wallet-sdk';
5+
import type { AutoApprovalAnalysis } from '@mysten/wallet-sdk';
76

87
interface TransactionContentProps {
9-
transaction: Transaction | null;
10-
analysis?: TransactionAnalysis;
8+
analysis?: AutoApprovalAnalysis;
119
autoApprovalState?: any;
1210
}
1311

14-
export function TransactionContent({
15-
transaction,
16-
analysis,
17-
autoApprovalState,
18-
}: TransactionContentProps) {
19-
if (!transaction) {
12+
export function TransactionContent({ analysis, autoApprovalState }: TransactionContentProps) {
13+
if (!analysis) {
2014
return null;
2115
}
2216

@@ -29,11 +23,7 @@ export function TransactionContent({
2923

3024
<div className="bg-gray-50 rounded-xl border border-gray-200 overflow-hidden shadow-sm">
3125
<div className="p-5">
32-
<TransactionDetails
33-
transaction={transaction}
34-
analysis={analysis}
35-
autoApprovalState={autoApprovalState}
36-
/>
26+
<TransactionDetails analysis={analysis} autoApprovalState={autoApprovalState} />
3727
</div>
3828
</div>
3929
</div>

packages/wallet-sdk/examples/demo-app/src/wallet/components/signing/transaction/CoinFlowEntry.tsx

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,26 @@
33

44
export interface CoinFlowEntryProps {
55
coinType: string;
6-
amount: string;
76
decimals: number;
8-
symbol: string;
9-
isRecognized: boolean;
7+
price: number;
8+
amount: bigint;
9+
convertedAmount: number;
1010
}
1111

12-
export function CoinFlowEntry({
13-
coinType,
14-
amount,
15-
decimals,
16-
symbol,
17-
isRecognized,
18-
}: CoinFlowEntryProps) {
12+
export function CoinFlowEntry({ coinType, amount, decimals }: CoinFlowEntryProps) {
1913
// Safely determine if amount is positive
2014
let isPositive = false;
2115
try {
22-
if (amount && amount !== 'NaN' && amount !== 'undefined' && amount !== 'null') {
23-
isPositive = BigInt(amount) > 0n;
16+
if (amount) {
17+
isPositive = amount > 0n;
2418
}
2519
} catch (error) {
2620
// If BigInt conversion fails, default to false
2721
isPositive = false;
2822
}
2923

3024
// Format the amount for display using actual decimals
31-
const formatAmount = (amount: string, decimals: number) => {
25+
const formatAmount = (amount: string | bigint, decimals: number) => {
3226
// Validate input
3327
if (!amount || amount === 'NaN' || amount === 'undefined' || amount === 'null') {
3428
return '0';
@@ -98,6 +92,7 @@ export function CoinFlowEntry({
9892

9993
return coinType;
10094
};
95+
const symbol = coinType.split('::')[2] || '??';
10196

10297
return (
10398
<div className="flex items-center justify-between py-2 px-3 bg-gray-50 rounded-lg">
@@ -109,20 +104,12 @@ export function CoinFlowEntry({
109104

110105
<div className="flex-1">
111106
<div className="flex items-center space-x-2">
112-
<span className="font-medium text-sm text-gray-900">
113-
{isRecognized ? symbol : symbol}
114-
</span>
115-
{!isRecognized && (
116-
<span className="text-xs text-orange-700 bg-orange-100 px-2 py-0.5 rounded-full font-medium">
117-
UNRECOGNIZED
118-
</span>
119-
)}
107+
<span className="font-medium text-sm text-gray-900">{symbol}</span>
108+
</div>
109+
110+
<div className="text-xs text-gray-500 mt-0.5 font-mono" title={coinType}>
111+
{formatCoinType(coinType)}
120112
</div>
121-
{!isRecognized && (
122-
<div className="text-xs text-gray-500 mt-0.5 font-mono" title={coinType}>
123-
{formatCoinType(coinType)}
124-
</div>
125-
)}
126113
</div>
127114
</div>
128115

0 commit comments

Comments
 (0)