Skip to content

Commit 4d003e1

Browse files
fix: getDelegations
1 parent a2bbacd commit 4d003e1

File tree

2 files changed

+12
-28
lines changed

2 files changed

+12
-28
lines changed

src/navigation/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ type RouteParams = {
712712
[Routes.REVOKE_DELEGATION_PANEL]: {
713713
delegationsToRevoke: Array<{
714714
chainId: number;
715-
contractAddress: string;
715+
contractAddress: Address;
716716
}>;
717717
onSuccess?: () => void;
718718
revokeReason?: import('@/screens/delegation/RevokeDelegationPanel').RevokeReason;

src/screens/SettingsSheet/components/DevSection.tsx

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import Restart from 'react-native-restart';
2525
import Menu from './Menu';
2626
import MenuContainer from './MenuContainer';
2727
import MenuItem from './MenuItem';
28+
import type { Address } from 'viem';
2829

2930
import { addDefaultNotificationGroupSettings } from '@/notifications/settings/initialization';
3031
import { unsubscribeAllNotifications } from '@/notifications/settings/settings';
@@ -37,7 +38,7 @@ import FastImage from 'react-native-fast-image';
3738
import { analyzeUserAssets } from '@/state/debug/analyzeUserAssets';
3839
import { getAllInternetCredentials, resetInternetCredentials } from 'react-native-keychain';
3940
import { ChainId } from '@/state/backendNetworks/types';
40-
import { executeDelegation, executeRevokeDelegation } from '@rainbow-me/delegation';
41+
import { executeDelegation, executeRevokeDelegation, getDelegations } from '@rainbow-me/delegation';
4142
import { loadWallet } from '@/model/wallet';
4243
import { getProvider } from '@/handlers/web3';
4344
import { Wallet } from '@ethersproject/wallet';
@@ -167,12 +168,12 @@ const DevSection = () => {
167168
const maxFeePerGas = feeData.maxFeePerGas?.toBigInt();
168169
const maxPriorityFeePerGas = feeData.maxPriorityFeePerGas?.toBigInt();
169170

170-
const nonce = await getNextNonce({ address: accountAddress, chainId });
171-
172171
if (!maxFeePerGas || !maxPriorityFeePerGas) {
173172
throw new Error('Failed to fetch gas prices from provider');
174173
}
175174

175+
const nonce = await getNextNonce({ address: accountAddress, chainId });
176+
176177
// Use null for gasLimit to let the SDK estimate it automatically
177178
const tx = await executeDelegation({
178179
signer: wallet as Wallet,
@@ -219,12 +220,12 @@ const DevSection = () => {
219220
const maxFeePerGas = feeData.maxFeePerGas?.toBigInt();
220221
const maxPriorityFeePerGas = feeData.maxPriorityFeePerGas?.toBigInt();
221222

222-
const nonce = await getNextNonce({ address: accountAddress, chainId });
223-
224223
if (!maxFeePerGas || !maxPriorityFeePerGas) {
225224
throw new Error('Failed to fetch gas prices from provider');
226225
}
227226

227+
const nonce = await getNextNonce({ address: accountAddress, chainId });
228+
228229
// Use null for gasLimit to let the SDK estimate it automatically
229230
const result = await executeRevokeDelegation({
230231
signer: wallet as Wallet,
@@ -255,32 +256,15 @@ const DevSection = () => {
255256
}
256257

257258
try {
258-
// Check for delegations on mainnet and base
259-
const chainsToCheck = [ChainId.mainnet, ChainId.base];
260-
const delegationsToRevoke: Array<{ chainId: number; contractAddress: string }> = [];
261-
262-
/*
263-
for (const chainId of chainsToCheck) {
264-
const isDelegated = await getIsDelegated({
265-
address: accountAddress,
266-
chainId,
267-
});
268-
269-
if (isDelegated) {
270-
// For this demo, we'll use a placeholder contract address
271-
delegationsToRevoke.push({
272-
chainId,
273-
contractAddress: '0x0000000000000000000000000000000000000000',
274-
});
275-
logger.info('Found active delegation', { chainId, accountAddress });
276-
}
277-
}
278-
*/
259+
const delegationsToRevoke = await getDelegations({ address: accountAddress });
279260

280261
if (delegationsToRevoke.length > 0) {
281262
logger.info('Delegation status required', { delegationsToRevoke });
282263
Navigation.handleAction(Routes.REVOKE_DELEGATION_PANEL, {
283-
delegationsToRevoke,
264+
delegationsToRevoke: delegationsToRevoke.map(delegation => ({
265+
chainId: delegation.chainId,
266+
contractAddress: delegation.currentContract as Address,
267+
})),
284268
});
285269
} else {
286270
Alert.alert(

0 commit comments

Comments
 (0)