Skip to content

Commit

Permalink
Fix Darwinia and Crab native token address mutation (#576)
Browse files Browse the repository at this point in the history
* Reset transferValue after closing Transfer Summary

* Fix RING and CRAB address mutation
  • Loading branch information
JayJay1024 authored Nov 17, 2023
1 parent 96700c1 commit 7d877dc
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 20 deletions.
4 changes: 2 additions & 2 deletions packages/apps/src/bridges/helix-lpbridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export class HelixLpBridge extends BaseBridge {
sourceToken?: Token;
targetToken?: Token;
}) {
const sourceToken = args.sourceToken;
const targetToken = args.targetToken;
const sourceToken = args.sourceToken ? { ...args.sourceToken } : undefined; // DON'T USE `const sourceToken = args.sourceToken`
const targetToken = args.targetToken ? { ...args.targetToken } : undefined;
if (args.sourceChain?.network === "darwinia-dvm" && sourceToken?.symbol === "RING") {
sourceToken.address = "0xE7578598Aac020abFB918f33A20faD5B71d670b4";
} else if (args.targetChain?.network === "darwinia-dvm" && targetToken?.symbol === "RING") {
Expand Down
4 changes: 2 additions & 2 deletions packages/apps/src/bridges/helixbridge-dvmdvm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export class HelixBridgeDVMDVM extends BaseBridge {
sourceToken?: Token;
targetToken?: Token;
}) {
const sourceToken = args.sourceToken;
const targetToken = args.targetToken;
const sourceToken = args.sourceToken ? { ...args.sourceToken } : undefined; // DON'T USE `const sourceToken = args.sourceToken`
const targetToken = args.targetToken ? { ...args.targetToken } : undefined;
if (args.sourceChain?.network === "darwinia-dvm" && sourceToken?.symbol === "RING") {
sourceToken.address = "0xE7578598Aac020abFB918f33A20faD5B71d670b4";
} else if (args.targetChain?.network === "darwinia-dvm" && targetToken?.symbol === "RING") {
Expand Down
4 changes: 2 additions & 2 deletions packages/apps/src/bridges/helixbridge-dvmevm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export class HelixBridgeDVMEVM extends BaseBridge {
sourceToken?: Token;
targetToken?: Token;
}) {
const sourceToken = args.sourceToken;
const targetToken = args.targetToken;
const sourceToken = args.sourceToken ? { ...args.sourceToken } : undefined; // DON'T USE `const sourceToken = args.sourceToken`
const targetToken = args.targetToken ? { ...args.targetToken } : undefined;
if (args.sourceChain?.network === "darwinia-dvm" && sourceToken?.symbol === "RING") {
sourceToken.address = "0xE7578598Aac020abFB918f33A20faD5B71d670b4";
} else if (args.targetChain?.network === "darwinia-dvm" && targetToken?.symbol === "RING") {
Expand Down
14 changes: 2 additions & 12 deletions packages/apps/src/components/transfer-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,10 @@ interface Props {
transferValue: TransferValue;
isOpen: boolean;
onClose: () => void;
onSuccess: () => void;
refetchRelayers: () => Promise<ApolloQueryResult<RelayersResponseData>>;
}

export default function TransferModal({
sender,
recipient,
transferValue,
isOpen,
onClose,
onSuccess,
refetchRelayers,
}: Props) {
export default function TransferModal({ sender, recipient, transferValue, isOpen, onClose, refetchRelayers }: Props) {
const { bridgeClient, sourceValue, targetValue, fee, transfer } = useTransfer();
const [txHash, setTxHash] = useState("");
const [busy, setBusy] = useState(false);
Expand Down Expand Up @@ -72,7 +63,6 @@ export default function TransferModal({
if (receipt?.status === "success") {
setTxHash(receipt.transactionHash);
setDisabled(true);
onSuccess();
}
} catch (err) {
console.error(err);
Expand All @@ -81,7 +71,7 @@ export default function TransferModal({
setBusy(false);
}
}
}, [bridgeClient, onSuccess, recipient, refetchRelayers, sender, transfer, transferValue]);
}, [bridgeClient, recipient, refetchRelayers, sender, transfer, transferValue]);

// Reset state
useEffect(() => {
Expand Down
4 changes: 2 additions & 2 deletions packages/apps/src/components/transfer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@ export default function Transfer() {
recipient={recipient || address}
transferValue={deferredTransferValue}
isOpen={isOpen}
onClose={setIsOpenFalse}
onSuccess={() => {
onClose={() => {
setIsOpenFalse();
setTransferValue({ value: "", formatted: 0n });
}}
refetchRelayers={refetchRelayers}
Expand Down

0 comments on commit 7d877dc

Please sign in to comment.