Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 31 additions & 9 deletions lib/use-get-xrp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,16 @@ export const useGetXrp = (network: Network) => {

const amount = json.amount - reserve - transferFee;

const tx = prepareBridgeTransaction(wallet.address, network, destination, amount);

const client = new Client(networks[network].wsUrl);
const tx = prepareBridgeTransaction(
wallet.address,
network,
destination,
amount
);

const client = new Client(networks[network].wsUrl, {
connectionTimeout: 30000,
});
await client.connect();

const prepared = await client.autofill(tx);
Expand All @@ -51,24 +58,39 @@ export const useGetXrp = (network: Network) => {
};
};

const prepareBridgeTransaction = (originAddress: string, destinationNetwork: Network, destinationAddress: string, amount: number) => {
const prepareBridgeTransaction = (
originAddress: string,
destinationNetwork: Network,
destinationAddress: string,
amount: number
) => {
const memos = [
{
Memo: {
MemoData: Buffer.from("interchain_transfer").toString("hex").toUpperCase(),
MemoData: Buffer.from("interchain_transfer")
.toString("hex")
.toUpperCase(),
MemoType: Buffer.from("type").toString("hex").toUpperCase(),
},
},
{
Memo: {
MemoData: Buffer.from(destinationAddress.slice(2)).toString("hex").toUpperCase(),
MemoType: Buffer.from("destination_address").toString("hex").toUpperCase(),
MemoData: Buffer.from(destinationAddress.slice(2))
.toString("hex")
.toUpperCase(),
MemoType: Buffer.from("destination_address")
.toString("hex")
.toUpperCase(),
},
},
{
Memo: {
MemoData: Buffer.from(networks[destinationNetwork].bridgeNetwork).toString("hex").toUpperCase(),
MemoType: Buffer.from("destination_chain").toString("hex").toUpperCase(),
MemoData: Buffer.from(networks[destinationNetwork].bridgeNetwork)
.toString("hex")
.toUpperCase(),
MemoType: Buffer.from("destination_chain")
.toString("hex")
.toUpperCase(),
},
},
{
Expand Down