Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
fix tracking, deposit
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Jul 6, 2024
1 parent 0eb3178 commit f5d81ac
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 73 deletions.
29 changes: 12 additions & 17 deletions components/Swap/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -76,23 +68,17 @@ const SwapLayout: React.FC<SwapLayoutProps> = ({
sendType,
sourceAmount,
setSourceAmount,
sourceTokenOpen,
setSourceTokenOpen,
sourceTokenSelected,
balancesLoading,
sourceBalances,
setSourceToken,
destinationAmount,
destinationAmountIsLoading,
destinationTokenOpen,
setDestinationTokenOpen,
destinationTokenSelected,
destinationBalances,
setDestinationToken,
computeSendType,
addressSelected,
customAddressOpen,
setCustomAddressOpen,
canChangeAddress,
isAddressSelectedValid,
formatAddress,
Expand All @@ -101,8 +87,6 @@ const SwapLayout: React.FC<SwapLayoutProps> = ({
isCustomAddressValid,
saveCustomAddress,
crossChainFee,
isFeeOpen,
setIsFeeOpen,
isRightChain,
handleSend,
sendDisabled,
Expand All @@ -112,11 +96,22 @@ const SwapLayout: React.FC<SwapLayoutProps> = ({
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 (
<div className="shadow-none md:shadow-xl p-0 md:px-5 md:py-7 rounded-2xl md:shadow-gray-100 mb-10">
<h1 className="text-2xl font-bold leading-tight tracking-tight mt-6 mb-4 ml-2">
{sendTypeDetails[sendType as any]?.title || "Swap"}
</h1>
{JSON.stringify(sendType)}
<form
onSubmit={(e) => {
e.preventDefault()
Expand Down Expand Up @@ -318,7 +313,7 @@ const SwapLayout: React.FC<SwapLayoutProps> = ({
disabled={!isCustomAddressValid}
size="icon"
variant="outline"
onClick={saveCustomAddress}
onClick={confirmCustomAddress}
>
<Check className="h-4 w-4" strokeWidth={3} />
</Button>
Expand Down
4 changes: 0 additions & 4 deletions components/Swap/hooks/useDestinationAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const useDestinationAddress = (
const [customAddressSelected, setCustomAddressSelected] = useState<
string | null
>(null)
const [customAddressOpen, setCustomAddressOpen] = useState(false)
const [isCustomAddressValid, setIsCustomAddressValid] = useState(false)

useEffect(() => {
Expand Down Expand Up @@ -64,7 +63,6 @@ const useDestinationAddress = (
if (isCustomAddressValid) {
setCustomAddressSelected(customAddress)
setCustomAddress(customAddress)
setCustomAddressOpen(false)
}
}

Expand Down Expand Up @@ -94,8 +92,6 @@ const useDestinationAddress = (
return {
addressSelected,
isAddressSelectedValid,
customAddressOpen,
setCustomAddressOpen,
canChangeAddress: true,
customAddress,
setCustomAddress,
Expand Down
47 changes: 19 additions & 28 deletions components/Swap/hooks/useSendTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 0 additions & 13 deletions components/Swap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ const Swap = () => {
const { address } = useAccount()

const [sourceAmount, setSourceAmount] = useState<string>("")
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 {
Expand Down Expand Up @@ -85,8 +82,6 @@ const Swap = () => {
const {
addressSelected,
isAddressSelectedValid,
customAddressOpen,
setCustomAddressOpen,
canChangeAddress,
customAddress,
setCustomAddress,
Expand Down Expand Up @@ -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}
Expand All @@ -176,8 +165,6 @@ const Swap = () => {
isCustomAddressValid={isCustomAddressValid}
saveCustomAddress={saveCustomAddress}
crossChainFee={crossChainFee}
isFeeOpen={isFeeOpen}
setIsFeeOpen={setIsFeeOpen}
isRightChain={isRightChain}
handleSend={handleSend}
sendDisabled={sendDisabled}
Expand Down
2 changes: 1 addition & 1 deletion context/CCTXsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 }])
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -3676,18 +3676,18 @@
resolved "https://registry.yarnpkg.com/@zetachain/protocol-contracts/-/protocol-contracts-7.0.0.tgz#20eb6c62d805d7470408ccdff0e3614684bca174"
integrity sha512-8JTNFZxVZYmDtAXJIEr+tkakuML12X42Fya4bJ1NkfWiVMkcSej92BSTl/35qYtHdjY7vXy9uMrfXEqfw5rsPw==

"@zetachain/[email protected]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/[email protected]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"
"@nomiclabs/hardhat-ethers" "^2.2.3"
"@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"
Expand Down

0 comments on commit f5d81ac

Please sign in to comment.