Skip to content

Commit 31d7692

Browse files
committed
fix: assure correct chain
1 parent b14cd26 commit 31d7692

File tree

4 files changed

+127
-42
lines changed

4 files changed

+127
-42
lines changed

app/app/components/FeeWithdrawalModal.tsx

Lines changed: 63 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useState, useEffect } from "react";
2-
import { useAccount, useWalletClient } from "wagmi";
2+
import { useAccount, useWalletClient, useChainId, useSwitchChain } from "wagmi";
33
import { BrowserProvider } from "ethers";
44
import { toast } from "react-toastify";
55
import { Button } from "./Button";
@@ -10,6 +10,7 @@ import {
1010
getClientHolding,
1111
} from "../utils/orderly";
1212
import { cleanMultisigAddress } from "../utils/multisig";
13+
import { getChainById } from "../../../config";
1314

1415
interface FeeWithdrawalModalProps {
1516
isOpen: boolean;
@@ -28,6 +29,8 @@ export function FeeWithdrawalModal({
2829
}: FeeWithdrawalModalProps) {
2930
const { address } = useAccount();
3031
const { data: walletClient } = useWalletClient();
32+
const chainId = useChainId();
33+
const { switchChain } = useSwitchChain();
3134
const [isProcessing, setIsProcessing] = useState(false);
3235
const [amount, setAmount] = useState("");
3336
const [usdcBalance, setUsdcBalance] = useState<number | null>(null);
@@ -37,6 +40,9 @@ export function FeeWithdrawalModal({
3740
const accountId = getAccountId(cleanAddress, brokerId);
3841
const [orderlyKey, setOrderlyKey] = useState<Uint8Array | null>(null);
3942

43+
const isOnCorrectChain = chainId === multisigChainId;
44+
const requiredChain = getChainById(multisigChainId);
45+
4046
useEffect(() => {
4147
if (isOpen) {
4248
const savedKey = loadOrderlyKey(accountId);
@@ -76,12 +82,28 @@ export function FeeWithdrawalModal({
7682
}
7783
};
7884

85+
const handleSwitchChain = async () => {
86+
try {
87+
await switchChain({ chainId: multisigChainId });
88+
} catch (error) {
89+
console.error("Failed to switch chain:", error);
90+
toast.error("Please switch to the required network in your wallet");
91+
}
92+
};
93+
7994
const handleWithdraw = async () => {
8095
if (!walletClient || !accountId || !orderlyKey || !address) {
8196
toast.error("Missing required data for withdrawal");
8297
return;
8398
}
8499

100+
if (!isOnCorrectChain) {
101+
toast.error(
102+
`Please switch to ${requiredChain?.name || "the correct network"} to withdraw`
103+
);
104+
return;
105+
}
106+
85107
if (!amount.trim() || parseFloat(amount) <= 0) {
86108
toast.error("Please enter valid amount");
87109
return;
@@ -212,31 +234,49 @@ export function FeeWithdrawalModal({
212234
/>
213235
</div>
214236

215-
<div className="bg-warning/10 rounded-lg p-3">
216-
<div className="flex items-start gap-2">
217-
<div className="i-mdi:shield-check text-warning w-4 h-4 mt-0.5 flex-shrink-0"></div>
218-
<div>
219-
<p className="text-xs text-warning font-medium mb-1">
220-
Multisig Approval Required
221-
</p>
222-
<p className="text-xs text-gray-400">
223-
This transaction will be submitted to your Safe wallet and
224-
requires approval from the required number of signers.
225-
</p>
237+
{!isOnCorrectChain && (
238+
<div className="bg-warning/10 border border-warning/20 rounded-lg p-3">
239+
<div className="flex items-start gap-2">
240+
<div className="i-mdi:alert text-warning w-5 h-5 mt-0.5 flex-shrink-0"></div>
241+
<div className="flex-1">
242+
<p className="text-xs text-warning font-medium mb-1">
243+
Wrong Network
244+
</p>
245+
<p className="text-xs text-gray-400">
246+
Please switch to{" "}
247+
<span className="font-semibold text-white">
248+
{requiredChain?.name || `Chain ID ${multisigChainId}`}
249+
</span>{" "}
250+
where your multisig delegate signer link was established.
251+
</p>
252+
</div>
226253
</div>
227254
</div>
228-
</div>
255+
)}
229256

230-
<Button
231-
onClick={handleFullWithdrawal}
232-
variant="primary"
233-
className="w-full"
234-
isLoading={isProcessing}
235-
loadingText="Processing..."
236-
disabled={!amount.trim() || !orderlyKey}
237-
>
238-
Withdraw Fees
239-
</Button>
257+
{isOnCorrectChain ? (
258+
<Button
259+
onClick={handleFullWithdrawal}
260+
variant="primary"
261+
className="w-full"
262+
isLoading={isProcessing}
263+
loadingText="Processing..."
264+
disabled={!amount.trim() || !orderlyKey}
265+
>
266+
Withdraw Fees
267+
</Button>
268+
) : (
269+
<Button
270+
onClick={handleSwitchChain}
271+
variant="primary"
272+
className="w-full"
273+
>
274+
<div className="flex items-center justify-center gap-2">
275+
<div className="i-mdi:swap-horizontal w-4 h-4"></div>
276+
Switch to {requiredChain?.name || "Correct Network"}
277+
</div>
278+
</Button>
279+
)}
240280
</div>
241281
</div>
242282
</div>

app/app/components/GraduationForm.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,9 +1255,6 @@ export function GraduationForm({
12551255
brokerId: graduationStatus.brokerId,
12561256
onSuccess: () => {
12571257
setMultisigHasKey(true);
1258-
toast.success(
1259-
"Orderly key created! You can now withdraw fees."
1260-
);
12611258
},
12621259
onCancel: () => {},
12631260
})

app/app/components/OrderlyKeyLoginModal.tsx

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { getCurrentEnvironment } from "../utils/config";
1313
import { get } from "../utils/apiClient";
1414
import { useAuth } from "../context/useAuth";
1515
import { cleanMultisigAddress } from "../utils/multisig";
16+
import { getChainById } from "../../../config";
1617

1718
interface OrderlyKeyLoginModalProps {
1819
isOpen: boolean;
@@ -38,6 +39,7 @@ export default function OrderlyKeyLoginModal({
3839
const { token } = useAuth();
3940
const [isCreating, setIsCreating] = useState(false);
4041
const [multisigAddress, setMultisigAddress] = useState<string | undefined>();
42+
const [multisigChainId, setMultisigChainId] = useState<number | undefined>();
4143
const [isLoadingStatus, setIsLoadingStatus] = useState(false);
4244

4345
const isMainnet = getCurrentEnvironment() === "mainnet";
@@ -60,13 +62,16 @@ export default function OrderlyKeyLoginModal({
6062
const data = await get<{
6163
isMultisig?: boolean;
6264
multisigAddress?: string;
65+
multisigChainId?: number | null;
6366
}>("/api/graduation/graduation-status", token, {
6467
showToastOnError: false,
6568
});
6669
if (data.isMultisig && data.multisigAddress) {
6770
setMultisigAddress(data.multisigAddress);
71+
setMultisigChainId(data.multisigChainId || undefined);
6872
} else {
6973
setMultisigAddress(undefined);
74+
setMultisigChainId(undefined);
7075
}
7176
} catch (error) {
7277
console.error("Failed to fetch graduation status:", error);
@@ -86,12 +91,20 @@ export default function OrderlyKeyLoginModal({
8691
accountId ||
8792
(cleanAddress && brokerId ? getAccountId(cleanAddress, brokerId) : "");
8893

94+
const requiredChainId =
95+
isMultisig && multisigChainId ? multisigChainId : null;
96+
const isOnCorrectChain = requiredChainId
97+
? chainId === requiredChainId
98+
: isSupportedChain;
99+
const requiredChain = requiredChainId ? getChainById(requiredChainId) : null;
100+
89101
const handleSwitchChain = async () => {
90102
try {
91-
await switchChain({ chainId: defaultChainId });
103+
const targetChainId = requiredChainId || defaultChainId;
104+
await switchChain({ chainId: targetChainId });
92105
} catch (error) {
93106
console.error("Failed to switch chain:", error);
94-
toast.error("Please switch to a supported network in your wallet");
107+
toast.error("Please switch to the required network in your wallet");
95108
}
96109
};
97110

@@ -101,8 +114,12 @@ export default function OrderlyKeyLoginModal({
101114
return;
102115
}
103116

104-
if (!isSupportedChain) {
105-
toast.error("Please switch to a supported network");
117+
if (!isOnCorrectChain) {
118+
toast.error(
119+
isMultisig
120+
? "Please switch to the network where your multisig delegate signer link was established"
121+
: "Please switch to a supported network"
122+
);
106123
return;
107124
}
108125

@@ -119,8 +136,6 @@ export default function OrderlyKeyLoginModal({
119136

120137
let orderlyKey: Uint8Array;
121138

122-
console.log("isMultisig", isMultisig);
123-
124139
if (isMultisig) {
125140
orderlyKey = await addDelegateOrderlyKey(
126141
signer,
@@ -201,12 +216,22 @@ export default function OrderlyKeyLoginModal({
201216
<div className="mt-3 bg-info/10 rounded-lg p-3 border border-info/20">
202217
<div className="flex items-start gap-2">
203218
<div className="i-mdi:information-outline text-info w-4 h-4 mt-0.5 flex-shrink-0"></div>
204-
<p className="text-xs text-gray-400 text-left">
205-
Creating delegate key for multisig wallet:{" "}
206-
<span className="font-mono text-primary-light">
207-
{multisigAddress}
208-
</span>
209-
</p>
219+
<div className="text-xs text-gray-400 text-left">
220+
<p className="mb-1">
221+
Creating delegate key for multisig wallet:{" "}
222+
<span className="font-mono text-primary-light">
223+
{multisigAddress}
224+
</span>
225+
</p>
226+
{requiredChain && (
227+
<p className="text-info">
228+
Required network:{" "}
229+
<span className="font-semibold">
230+
{requiredChain.name}
231+
</span>
232+
</p>
233+
)}
234+
</div>
210235
</div>
211236
</div>
212237
)}
@@ -246,14 +271,17 @@ export default function OrderlyKeyLoginModal({
246271
</p>
247272
</div>
248273

249-
{!isSupportedChain && (
274+
{!isOnCorrectChain && (
250275
<div className="bg-warning/10 border border-warning/20 rounded-lg p-3 mb-4">
251276
<div className="flex items-start gap-2">
252277
<div className="i-mdi:alert text-warning w-5 h-5 mt-0.5 flex-shrink-0"></div>
253278
<div className="flex-1">
254279
<p className="text-warning text-sm">
255-
Please switch to a supported network to create your
256-
Orderly key.
280+
{isMultisig && requiredChain
281+
? `Please switch to ${requiredChain.name} where your multisig delegate signer link was established.`
282+
: isMultisig && requiredChainId
283+
? `Please switch to the network where your multisig delegate signer link was established (Chain ID: ${requiredChainId}).`
284+
: "Please switch to a supported network to create your Orderly key."}
257285
</p>
258286
</div>
259287
</div>
@@ -268,7 +296,7 @@ export default function OrderlyKeyLoginModal({
268296
>
269297
Cancel
270298
</Button>
271-
{isSupportedChain ? (
299+
{isOnCorrectChain ? (
272300
<Button
273301
variant="primary"
274302
onClick={handleCreateKey}

app/app/components/SafeInstructions.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,26 @@ export default function SafeInstructionsModal({
207207
<div className="flex-1 overflow-y-auto px-8">
208208
{activeTab === "safe" && (
209209
<div className="space-y-4 mb-8">
210+
<div className="bg-info/10 border border-info/20 rounded-lg p-4 mb-4">
211+
<div className="flex items-start gap-3">
212+
<div className="i-mdi:information-outline text-info w-5 h-5 mt-0.5 flex-shrink-0"></div>
213+
<div>
214+
<h4 className="font-semibold text-info mb-2">
215+
Important: Match Your Safe's Network
216+
</h4>
217+
<p className="text-sm text-gray-300">
218+
Use the network selector above to choose the chain where
219+
your Safe wallet is deployed. Currently selected:{" "}
220+
<span className="font-semibold text-white">
221+
{chain?.name}
222+
</span>
223+
. If your Safe is on a different chain, switch using the
224+
network selector at the top before proceeding.
225+
</p>
226+
</div>
227+
</div>
228+
</div>
229+
210230
<p className="text-gray-300">
211231
Visit{" "}
212232
<a

0 commit comments

Comments
 (0)