Skip to content

Commit

Permalink
WIP: Tron <> EVM Example
Browse files Browse the repository at this point in the history
  • Loading branch information
heyOnuoha committed Sep 9, 2024
1 parent 6c571b1 commit 4f52430
Show file tree
Hide file tree
Showing 58 changed files with 4,345 additions and 60 deletions.
44 changes: 23 additions & 21 deletions examples/swaps-api-nextjs-bitcoin/src/components/Swap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ const Swap = () => {
}, [recipientAddress]);

useEffect(() => {
if(!xDefiConfig?.isInstalled!()) {
console.log('not installed')
if (!xDefiConfig?.isInstalled!()) {
console.log("not installed");
toast({
variant: "destructive",
title: "xDefi Wallet not installed",
description: "Please install xDefi wallet in your browser",
});
}
}, [])
}, []);

async function connectWallet(chainId?: number) {
try {
Expand All @@ -147,20 +147,21 @@ const Swap = () => {
}
}

async function getTransStatus(transId: string, txHash: string): Promise<TransactionStatusAPIResponse> {
async function getTransStatus(
transId: string,
txHash: string,
): Promise<TransactionStatusAPIResponse> {
try {

const transactionStatus = await getTransationStatus({
id: transId,
txHash,
});

setTransStatus(transactionStatus);

return transactionStatus!;
} catch(e) {

return { status: 'Submitted' }
return transactionStatus!;
} catch (e) {
return { status: "Submitted" };
}
}

Expand Down Expand Up @@ -214,7 +215,6 @@ const Swap = () => {
try {
// Get a quote from the Swing API
const quotes = await getQuoteRequest({

fromChain: transferParams.fromChain,
fromTokenAddress: transferParams.fromTokenAddress,
fromUserAddress: transferParams.fromUserAddress,
Expand Down Expand Up @@ -312,13 +312,13 @@ const Swap = () => {

let txResponse;

if (transfer?.tx.meta) {
if (transfer?.tx.meta) {
// For Bitcoin to ETH, the send endpoint will return an object called `meta`

const { from, recipient, amount, memo } = transfer.tx.meta;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
(window.xfi as any)?.bitcoin.request(
(window.xfi as any)?.bitcoin.request(
// Here, we're prompting a users wallet using xDEFI injected SDK
{
method: "transfer",
Expand All @@ -335,20 +335,20 @@ const Swap = () => {
(error: any, result: any) => {
console.log(error, result);

if(error) {
if (error) {
toast({
variant: "destructive",
title: "Something went wrong!",
description:
"Swap error, please check your balance or swap config",
});

setIsLoading(false);
setTransStatus(null)
setTransStatus(null);
}
txResponse = result
txResponse = result;
pollTransactionStatus(transfer.id.toString(), txResponse);
console.log(txResponse)
console.log(txResponse);
},
);
} else {
Expand All @@ -357,7 +357,6 @@ const Swap = () => {
const receipt = await txResponse?.wait();
console.log("Transaction receipt:", receipt);
}


// Wait for the transaction to be mined
} catch (error) {
Expand Down Expand Up @@ -418,7 +417,10 @@ const Swap = () => {
</div>
</div>
<div className="p-1 bg-zinc-200 rounded-2xl">
<LiaExchangeAltSolid className="rounded-2xl w-8 h-8 font-bold text-zinc-400 cursor-pointer hover:text-zinc-950 transition-colors ease-in-out" onClick={() => switchTransferParams()} />
<LiaExchangeAltSolid
className="rounded-2xl w-8 h-8 font-bold text-zinc-400 cursor-pointer hover:text-zinc-950 transition-colors ease-in-out"
onClick={() => switchTransferParams()}
/>
</div>
<div className="flex w-full">
<div className="lg:w-auto w-full border-8 border-cyan-500 space-y-1 rounded-xl bg-zinc-900 p-3">
Expand Down
2 changes: 1 addition & 1 deletion examples/swaps-api-nextjs-solana/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@radix-ui/react-popover": "^1.0.7",
"@radix-ui/react-toast": "^1.1.5",
"@solana/web3.js": "^1.91.8",
"@swing.xyz/sdk": "^0.54.0",
"@swing.xyz/sdk": "^0.57.5",
"@tailwindcss/forms": "^0.5.7",
"@thirdweb-dev/react": "^4.4.17",
"@thirdweb-dev/sdk": "^4.0.44",
Expand Down
8 changes: 8 additions & 0 deletions examples/swaps-api-nextjs-tron/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import("eslint").Linter.Config} */
module.exports = {
extends: ["eslint-config-examples/index.js"],
parser: "@typescript-eslint/parser",
parserOptions: {
project: true,
},
};
32 changes: 32 additions & 0 deletions examples/swaps-api-nextjs-tron/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# local env files
.env*.local

# vercel
.vercel
Loading

0 comments on commit 4f52430

Please sign in to comment.