diff --git a/components/Swap/Layout.tsx b/components/Swap/Layout.tsx index ce9c860..1420118 100644 --- a/components/Swap/Layout.tsx +++ b/components/Swap/Layout.tsx @@ -29,23 +29,17 @@ interface SwapLayoutProps { sendType: string | null sourceAmount: any setSourceAmount: (value: any) => any - sourceTokenOpen: boolean - setSourceTokenOpen: (open: boolean) => void sourceTokenSelected: any balancesLoading: boolean sourceBalances: any[] setSourceToken: (token: any) => void destinationAmount: string destinationAmountIsLoading: boolean - destinationTokenOpen: boolean - setDestinationTokenOpen: (open: boolean) => void destinationTokenSelected: any destinationBalances: any[] setDestinationToken: (token: any) => void computeSendType: (sourceToken: any, destinationToken: any) => string | null addressSelected: any - customAddressOpen: boolean - setCustomAddressOpen: (open: boolean) => void canChangeAddress: boolean isAddressSelectedValid: boolean formatAddress: (address: string) => string @@ -59,8 +53,6 @@ interface SwapLayoutProps { symbol: string formatted: string } | null - isFeeOpen: boolean - setIsFeeOpen: (open: boolean) => void isRightChain: boolean handleSend: (sendType: any) => void sendDisabled: boolean @@ -76,23 +68,17 @@ const SwapLayout: React.FC = ({ sendType, sourceAmount, setSourceAmount, - sourceTokenOpen, - setSourceTokenOpen, sourceTokenSelected, balancesLoading, sourceBalances, setSourceToken, destinationAmount, destinationAmountIsLoading, - destinationTokenOpen, - setDestinationTokenOpen, destinationTokenSelected, destinationBalances, setDestinationToken, computeSendType, addressSelected, - customAddressOpen, - setCustomAddressOpen, canChangeAddress, isAddressSelectedValid, formatAddress, @@ -101,8 +87,6 @@ const SwapLayout: React.FC = ({ isCustomAddressValid, saveCustomAddress, crossChainFee, - isFeeOpen, - setIsFeeOpen, isRightChain, handleSend, sendDisabled, @@ -112,11 +96,22 @@ const SwapLayout: React.FC = ({ isLoading, pendingChainId, }) => { + const [sourceTokenOpen, setSourceTokenOpen] = useState(false) + const [destinationTokenOpen, setDestinationTokenOpen] = useState(false) + const [isFeeOpen, setIsFeeOpen] = useState(false) + const [customAddressOpen, setCustomAddressOpen] = useState(false) + + const confirmCustomAddress = () => { + saveCustomAddress() + setCustomAddressOpen(false) + } + return (

{sendTypeDetails[sendType as any]?.title || "Swap"}

+ {JSON.stringify(sendType)}
{ e.preventDefault() @@ -318,7 +313,7 @@ const SwapLayout: React.FC = ({ disabled={!isCustomAddressValid} size="icon" variant="outline" - onClick={saveCustomAddress} + onClick={confirmCustomAddress} > diff --git a/components/Swap/hooks/useDestinationAddress.ts b/components/Swap/hooks/useDestinationAddress.ts index a81f1e1..9fb09e0 100644 --- a/components/Swap/hooks/useDestinationAddress.ts +++ b/components/Swap/hooks/useDestinationAddress.ts @@ -15,7 +15,6 @@ const useDestinationAddress = ( const [customAddressSelected, setCustomAddressSelected] = useState< string | null >(null) - const [customAddressOpen, setCustomAddressOpen] = useState(false) const [isCustomAddressValid, setIsCustomAddressValid] = useState(false) useEffect(() => { @@ -64,7 +63,6 @@ const useDestinationAddress = ( if (isCustomAddressValid) { setCustomAddressSelected(customAddress) setCustomAddress(customAddress) - setCustomAddressOpen(false) } } @@ -94,8 +92,6 @@ const useDestinationAddress = ( return { addressSelected, isAddressSelectedValid, - customAddressOpen, - setCustomAddressOpen, canChangeAddress: true, customAddress, setCustomAddress, diff --git a/components/Swap/hooks/useSendTransaction.ts b/components/Swap/hooks/useSendTransaction.ts index b4cecbd..59ca5cb 100644 --- a/components/Swap/hooks/useSendTransaction.ts +++ b/components/Swap/hooks/useSendTransaction.ts @@ -410,37 +410,28 @@ const useSendTransaction = ( } const crossChainSwapHandle = async (withdraw: boolean) => { - if (!address) { - console.error("EVM address undefined.") - return - } - if (!bitcoinAddress) { - console.error("Bitcoin address undefined.") - return - } - if (!destinationTokenSelected) { - console.error("Destination token not selected.") + if (!sourceTokenSelected || !destinationTokenSelected) { return } - const a = parseFloat(sourceAmount) * 1e8 - const bitcoinTSSAddress = "tb1qy9pqmk2pd9sv63g27jt8r657wy0d9ueeh0nqur" - const contract = omnichainSwapContractAddress.replace(/^0x/, "") - const zrc20 = destinationTokenSelected.zrc20?.replace(/^0x/, "") - const dest = address.replace(/^0x/, "") - const withdrawFlag = withdraw ? "00" : "01" - const memo = `hex::${contract}${zrc20}${dest}${withdrawFlag}` - window.xfi.bitcoin.request( - bitcoinXDEFITransfer(bitcoinAddress, bitcoinTSSAddress, a, memo), - (error: any, hash: any) => { - if (!error) { - const inbound = { - inboundHash: hash, - desc: `Sent ${sourceAmount} tBTC`, - } - setInbounds([...inbounds, inbound]) - } + + const tiker = sourceTokenSelected.ticker + const from = sourceTokenSelected.chain_name + const dest = destinationTokenSelected.chain_name + + const tx = await client.deposit({ + chain: from, + amount: sourceAmount, + recipient: addressSelected, + }) + + if (tx) { + const inbound = { + inboundHash: tx.hash, + desc: `Sent ${sourceAmount} ${tiker} from ${from} to ${dest}`, } - ) + console.log(inbound) + setInbounds([...inbounds, inbound]) + } } m.crossChainSwapBTC = async () => crossChainSwapHandle(true) diff --git a/components/Swap/index.tsx b/components/Swap/index.tsx index 1bc1adf..45aa6f0 100644 --- a/components/Swap/index.tsx +++ b/components/Swap/index.tsx @@ -33,10 +33,7 @@ const Swap = () => { const { address } = useAccount() const [sourceAmount, setSourceAmount] = useState("") - const [sourceTokenOpen, setSourceTokenOpen] = useState(false) - const [destinationTokenOpen, setDestinationTokenOpen] = useState(false) const [isRightChain, setIsRightChain] = useState(true) - const [isFeeOpen, setIsFeeOpen] = useState(false) const [sendButtonText, setSendButtonText] = useState("Send tokens") const { @@ -85,8 +82,6 @@ const Swap = () => { const { addressSelected, isAddressSelectedValid, - customAddressOpen, - setCustomAddressOpen, canChangeAddress, customAddress, setCustomAddress, @@ -151,23 +146,17 @@ const Swap = () => { sendType={sendType} sourceAmount={sourceAmount} setSourceAmount={setSourceAmount} - sourceTokenOpen={sourceTokenOpen} - setSourceTokenOpen={setSourceTokenOpen} sourceTokenSelected={sourceTokenSelected} balancesLoading={balancesLoading} sourceBalances={sourceBalances} setSourceToken={setSourceToken} destinationAmount={destinationAmount} destinationAmountIsLoading={destinationAmountIsLoading} - destinationTokenOpen={destinationTokenOpen} - setDestinationTokenOpen={setDestinationTokenOpen} destinationTokenSelected={destinationTokenSelected} destinationBalances={destinationBalances} setDestinationToken={setDestinationToken} computeSendType={computeSendType} addressSelected={addressSelected} - customAddressOpen={customAddressOpen} - setCustomAddressOpen={setCustomAddressOpen} canChangeAddress={canChangeAddress} isAddressSelectedValid={isAddressSelectedValid} formatAddress={formatAddress} @@ -176,8 +165,6 @@ const Swap = () => { isCustomAddressValid={isCustomAddressValid} saveCustomAddress={saveCustomAddress} crossChainFee={crossChainFee} - isFeeOpen={isFeeOpen} - setIsFeeOpen={setIsFeeOpen} isRightChain={isRightChain} handleSend={handleSend} sendDisabled={sendDisabled} diff --git a/context/CCTXsContext.tsx b/context/CCTXsContext.tsx index 12d60fa..99f7548 100644 --- a/context/CCTXsContext.tsx +++ b/context/CCTXsContext.tsx @@ -77,7 +77,7 @@ export const CCTXsProvider = ({ children }: { children: React.ReactNode }) => { }) }) - client.trackCCTX(i.inboundHash, false, emitter) + client.trackCCTX({ hash: i.inboundHash, json: false, emitter }) setCCTXs([...cctxs, { inboundHash: i.inboundHash, desc: i.desc }]) } } diff --git a/package.json b/package.json index 9bb68e3..d9ce559 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "@uniswap/v3-core": "^1.0.1", "@uniswap/v3-sdk": "^3.10.0", "@zetachain/example-contracts": "1.0.0-rc1", - "@zetachain/toolkit": "11.0.0-rc1", + "@zetachain/toolkit": "11.0.0-rc2", "bech32": "^2.0.0", "class-variance-authority": "^0.4.0", "clsx": "^1.2.1", diff --git a/yarn.lock b/yarn.lock index aa86963..2ff7eda 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3664,10 +3664,10 @@ typescript "5.0.4" zod "3.19.1" -"@zetachain/networks@7.0.0": - version "7.0.0" - resolved "https://registry.yarnpkg.com/@zetachain/networks/-/networks-7.0.0.tgz#a5f8a188d633e2064ee7c77499351381ba891441" - integrity sha512-/amSq+KNJe+EGj0ioZS+DZJtsnbPSDotp9LsrAbaEVMAxKvBK/XkvggH73sJyRWWeMpfhHrNPlrKTLrN+mRkIg== +"@zetachain/networks@^8.0.0": + version "8.0.0" + resolved "https://registry.yarnpkg.com/@zetachain/networks/-/networks-8.0.0.tgz#3e838bb6b14e4a8d381f95b4cbc2f1172e851e4e" + integrity sha512-I0HhH5qOGW0Jkjq5o5Mi6qGls6ycHnhWjc+r+Ud8u8YW+HU4lEUn4gvulxj+ccHKj3nV/0gEsmNrWRY9ct49nQ== dependencies: dotenv "^16.1.4" @@ -3676,10 +3676,10 @@ resolved "https://registry.yarnpkg.com/@zetachain/protocol-contracts/-/protocol-contracts-7.0.0.tgz#20eb6c62d805d7470408ccdff0e3614684bca174" integrity sha512-8JTNFZxVZYmDtAXJIEr+tkakuML12X42Fya4bJ1NkfWiVMkcSej92BSTl/35qYtHdjY7vXy9uMrfXEqfw5rsPw== -"@zetachain/toolkit@11.0.0-rc1": - version "11.0.0-rc1" - resolved "https://registry.yarnpkg.com/@zetachain/toolkit/-/toolkit-11.0.0-rc1.tgz#06f1e0daf8d4ed79ca080bf07c1e1b48d987b04b" - integrity sha512-RW7PnabX4R3Qsx7i8M+CcyybgNXC94TfokjHZhLc1bzk/vZOPnQdHiOZvUs6wMLZ/simzTl1WDCnAdxTaKuLlw== +"@zetachain/toolkit@11.0.0-rc2": + version "11.0.0-rc2" + resolved "https://registry.yarnpkg.com/@zetachain/toolkit/-/toolkit-11.0.0-rc2.tgz#5be95e232a76042b805d9bffb63a5d3ca941ff37" + integrity sha512-HwgwJOJfGYcImJz228qc9L5P41sAnTOgp+cNyasJ/4RVQLrk+cCtvhV/ROfvKu1dmC98Npt6dfqaFXOfa/xJcw== dependencies: "@inquirer/prompts" "^2.1.1" "@inquirer/select" "1.1.3" @@ -3687,7 +3687,7 @@ "@openzeppelin/contracts" "^4.9.6" "@uniswap/v2-periphery" "^1.1.0-beta.0" "@zetachain/faucet-cli" "^4.0.1" - "@zetachain/networks" "7.0.0" + "@zetachain/networks" "^8.0.0" "@zetachain/protocol-contracts" "7.0.0" axios "^1.4.0" bech32 "^2.0.0"