Skip to content

Commit

Permalink
Merge pull request #239 from luxfi/dev/newProd
Browse files Browse the repository at this point in the history
fixed: tx timestamp issue
  • Loading branch information
venuswhispers authored Nov 26, 2024
2 parents 6dca6c6 + 2054f81 commit 1334caa
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import SwapItems from "./SwapItems";
import { useAtom } from "jotai";
import { useEthersSigner } from "@/lib/ethersToViem/ethers";
import { useServerAPI } from "@/hooks/useServerAPI";
import { swap } from "formik";

interface IProps {
className?: string
Expand Down Expand Up @@ -125,6 +124,10 @@ const UserTokenDepositor: React.FC<IProps> = ({
</div>
</div>
</div>

{

}

<ManualTransfer
sourceNetwork={sourceNetwork}
Expand Down
36 changes: 19 additions & 17 deletions app/bridge/src/store/utila.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import { atom } from "jotai";
import type { Network, Token } from "@/types/teleport";
import { atom } from 'jotai'
import type { Network, Token } from '@/types/teleport'
import type { DepositAction } from '@/types/utila'

export const sourceNetworkAtom = atom<Network | undefined>(undefined);
export const timeToExpireAtom = atom<number>(0);
export const sourceAssetAtom = atom<Token | undefined>(undefined);
export const destinationNetworkAtom = atom<Network | undefined>(undefined);
export const destinationAssetAtom = atom<Token | undefined>(undefined);
export const destinationAddressAtom = atom<string>("");
export const sourceAmountAtom = atom<string>("");
export const ethPriceAtom = atom<number>(0);
export const swapStatusAtom = atom<string>("");
export const swapIdAtom = atom<string>("");
export const userTransferTransactionAtom = atom<string>("");
export const bridgeMintTransactionAtom = atom<string>("");
export const mpcSignatureAtom = atom<string>("");
export const useTelepoterAtom = atom<boolean>(true);
export const sourceNetworkAtom = atom<Network | undefined>(undefined)
export const timeToExpireAtom = atom<number>(0)
export const sourceAssetAtom = atom<Token | undefined>(undefined)
export const destinationNetworkAtom = atom<Network | undefined>(undefined)
export const destinationAssetAtom = atom<Token | undefined>(undefined)
export const destinationAddressAtom = atom<string>('')
export const sourceAmountAtom = atom<string>('')
export const ethPriceAtom = atom<number>(0)
export const swapStatusAtom = atom<string>('')
export const swapIdAtom = atom<string>('')
export const userTransferTransactionAtom = atom<string>('')
export const bridgeMintTransactionAtom = atom<string>('')
export const mpcSignatureAtom = atom<string>('')
export const useTelepoterAtom = atom<boolean>(true)
export const depositActionsAtom = atom<DepositAction[]>([])

export const depositAddressAtom = atom<undefined|string>(undefined);
export const depositAddressAtom = atom<undefined|string>(undefined)
76 changes: 45 additions & 31 deletions app/bridge/src/types/utila.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,55 @@
export type Desposit = {
address: string,
address: string
memo?: string
}

export type Network = {
display_name: string,
internal_name: string,
native_currency: string,
logo: string,
is_testnet: boolean,
is_featured: boolean,
average_completion_time: string,
chain_id: number | null,
status: string,
type: string,
deposit_address?: Desposit,
refuel_amount_in_usd: number,
transaction_explorer_template: string,
account_explorer_template: string,
node: string,
currencies: Token[],
display_name: string
internal_name: string
native_currency: string
logo: string
is_testnet: boolean
is_featured: boolean
average_completion_time: string
chain_id: number | null
status: string
type: string
deposit_address?: Desposit
refuel_amount_in_usd: number
transaction_explorer_template: string
account_explorer_template: string
node: string
currencies: Token[]
}

export type Token = {
name: string,
asset: string,
logo: string,
contract_address: string | null,
decimals: number,
status: string,
is_deposit_enabled: boolean,
is_withdrawal_enabled: boolean,
is_refuel_enabled: boolean,
max_withdrawal_amount: number,
deposit_fee: number,
withdrawal_fee: number,
source_base_fee: number,
destination_base_fee: number,
name: string
asset: string
logo: string
contract_address: string | null
decimals: number
status: string
is_deposit_enabled: boolean
is_withdrawal_enabled: boolean
is_refuel_enabled: boolean
max_withdrawal_amount: number
deposit_fee: number
withdrawal_fee: number
source_base_fee: number
destination_base_fee: number
is_native: boolean
}

export type DepositAction = {
id: number
type: string
status: string
from: string
to: string
amount: number
transaction_hash: string
max_confirmations: number
confirmations: number
created_date: Date
timestamp: Date
}
7 changes: 5 additions & 2 deletions app/server/src/lib/swaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,13 +399,14 @@ export async function handlerUpdatePayoutAction(id: string, txHash: string, amou
* @param destinationAddress
* @returns
*/
export async function handlerDepositAction(state: number, hash: string, amount: number, asset: string, sourceAddress: string, destinationAddress: string, type: string) {
export async function handlerDepositAction(state: number, hash: string, amount: number, asset: string, sourceAddress: string, destinationAddress: string, created: Date, type: string) {
console.log({
sourceAddress,
destinationAddress,
amount,
hash,
status: UtilaTransactionStateMapping[state],
created,
type
})
const swap = await prisma.swap.findFirst({
Expand Down Expand Up @@ -439,7 +440,8 @@ export async function handlerDepositAction(state: number, hash: string, amount:
data: {
status: UtilaTransactionStateMapping[state],
confirmations: state === 13 ? 10 : 0,
max_confirmations: 10
max_confirmations: 10,
created_date: created
}
})
console.log(`>> Successfully Updated Deposit Action for Swap [${swap.id}]`)
Expand All @@ -453,6 +455,7 @@ export async function handlerDepositAction(state: number, hash: string, amount:
transaction_hash: hash,
confirmations: state === 13 ? 10 : 0,
max_confirmations: 10,
created_date: created,
swap: {
connect: {
id: swap.id
Expand Down
8 changes: 6 additions & 2 deletions app/server/src/lib/utila.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export const handleTransactionCreated = async (payload: UTILA_TRANSACTION_CREATE
const transfers = transaction.transfers || []
if (transfers.length === 0) throw "No transfers"

const { state, hash } = transaction
const { state, hash, createTime } = transaction
const { amount, asset, sourceAddress, destinationAddress } = transfers [0];

await handlerDepositAction (
Expand All @@ -219,6 +219,7 @@ export const handleTransactionCreated = async (payload: UTILA_TRANSACTION_CREATE
asset,
sourceAddress?.value as string,
destinationAddress?.value as string,
new Date(createTime ? Number(createTime.seconds) * 1000 : new Date()),
"TRANSACTION_CREATED"
)
} catch (err) {
Expand All @@ -236,7 +237,9 @@ export const handleTransactionStateUpdated = async (payload: UTILA_TRANSACTION_S
const transfers = transaction.transfers || []
if (transfers.length === 0) throw "No transfers"

const { state, hash } = transaction
console.log(transaction)

const { state, hash, createTime } = transaction
const { amount, asset, sourceAddress, destinationAddress } = transfers [0];

await handlerDepositAction (
Expand All @@ -246,6 +249,7 @@ export const handleTransactionStateUpdated = async (payload: UTILA_TRANSACTION_S
asset,
sourceAddress?.value as string,
destinationAddress?.value as string,
new Date(createTime ? Number(createTime.seconds) * 1000 : new Date()),
"TRANSACTION_STATE_UPDATED"
)
} catch (err) {
Expand Down

0 comments on commit 1334caa

Please sign in to comment.