Skip to content

Commit 6d573cf

Browse files
committed
fix: display modal if pending tx
1 parent 94dc345 commit 6d573cf

8 files changed

Lines changed: 54 additions & 17 deletions

File tree

app/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export default function Home() {
3535
isProcessingTransaction,
3636
addPendingTransaction,
3737
removePendingTransaction,
38+
pendingBridgeTxFromTU,
3839
} = useTariAccount()
3940
const { signer, setSigner } = useTariSigner()
4041
const { setTariAccount } = useTariAccount()
@@ -54,14 +55,12 @@ export default function Home() {
5455
useEffect(() => {
5556
const setAccount = async () => {
5657
try {
57-
console.info('🛜 setting account')
5858
await setTariAccount()
5959
} catch (error) {
6060
console.error('Failed to set Tari Account:', error)
6161
}
6262
}
6363
if (!signer) {
64-
console.info('🛜 signer not found set signer')
6564
const signerParams: TariL1SignerParameters = {
6665
name: 'TariL1Signer',
6766
onConnection: setTariAccount,
@@ -155,6 +154,7 @@ export default function Home() {
155154
tariWalletAddress={tariAccount?.address}
156155
fromNetwork={fromNetwork}
157156
toNetwork={toNetwork}
157+
pendingBridgeTxFromTU={pendingBridgeTxFromTU}
158158
/>
159159
)}
160160
</main>

bridge-v0.1.0.zip

14.3 MB
Binary file not shown.

clients/tari-l1-signer.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import {
88
WalletBalance,
99
} from '../types/tapplet'
1010

11-
export type SendOneSidedRequest = {
11+
export interface SendOneSidedRequest {
1212
amount: string
1313
address: string
14-
message?: string
14+
paymentId: string
1515
}
1616

1717
export class TariL1Signer {
@@ -72,17 +72,17 @@ export class TariL1Signer {
7272
* @description send XTM via one-sided transaction
7373
* @param amount XTM amount (uT or T)
7474
* @param address Tari Address one-sided
75-
* @param message (optional) payment-id
75+
* @param paymentId (optional) payment-id
7676
* @returns true if tx success; otherwise false
7777
*/
7878
public async sendOneSided({
7979
amount,
8080
address,
81-
message,
81+
paymentId,
8282
}: SendOneSidedRequest): Promise<boolean> {
8383
return this.sendRequest({
8484
methodName: 'sendOneSided',
85-
args: [{ amount, address, message }],
85+
args: [{ amount, address, paymentId }],
8686
})
8787
}
8888

@@ -96,6 +96,28 @@ export class TariL1Signer {
9696
args: [],
9797
})
9898
}
99+
100+
/**
101+
* @description check if there is any processing transaction
102+
* @returns true or false
103+
*/
104+
public async isPendingTappletTx(): Promise<SendOneSidedRequest | undefined> {
105+
return this.sendRequest({
106+
methodName: 'isPendingTappletTx',
107+
args: [],
108+
})
109+
}
110+
111+
/**
112+
* @description check if there is any processing transaction
113+
* @returns true or false
114+
*/
115+
public async removePendingTappletTx(paymentId: string): Promise<boolean> {
116+
return this.sendRequest({
117+
methodName: 'removePendingTappletTx',
118+
args: [paymentId],
119+
})
120+
}
99121
}
100122

101123
function sendSignerCall<MethodName extends SignerMethodNames>(

components/modals/connection-modal/connection-modal.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ const ConnectionModal: React.FC<ConnectionModalProps> = ({ closeModal }) => {
99
const { connectors, connect } = useConnect()
1010

1111
return (
12-
<div className="w-full flex flex-col mt-9">
12+
<div className="w-full flex flex-col mt-9 relative">
1313
<button
14-
className="text-black font-bold hover:cursor-pointer
15-
absolute top-4 right-4 cursor-pointer flex text-xl rounded-full p-1 bg-black/10 hover:bg-black/20"
14+
className="text-black font-bold hover:cursor-pointer absolute top-4 right-4 cursor-pointer flex text-xl rounded-full p-1 bg-black/10 hover:bg-black/20"
1615
onClick={closeModal}
1716
>
1817
<IoCloseOutline />

components/modals/main-modal/main-modal.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,15 @@ export const MainModal: React.FC<MainModalProps> = ({
2323
ethereumAddress,
2424
fromNetwork,
2525
toNetwork,
26+
pendingBridgeTxFromTU,
2627
}) => {
2728
const { isConnected } = useAccount()
2829
const modalRef = useRef<HTMLDivElement>(null)
29-
const feesData = useBridgeToEthereumFees(amount)
30+
const feesData = useBridgeToEthereumFees(
31+
!isBridging && pendingBridgeTxFromTU
32+
? pendingBridgeTxFromTU?.amount
33+
: amount,
34+
)
3035

3136
const closeModal = () => {
3237
setModalOpen(false)
@@ -75,7 +80,11 @@ export const MainModal: React.FC<MainModalProps> = ({
7580
return (
7681
<WrapModal
7782
closeModal={closeModal}
78-
amount={amount}
83+
amount={
84+
!isBridging && pendingBridgeTxFromTU
85+
? pendingBridgeTxFromTU?.amount
86+
: amount
87+
}
7988
tariWalletAddress={tariWalletAddress}
8089
ethereumAddress={ethereumAddress}
8190
fromNetwork={fromNetwork}
@@ -86,9 +95,7 @@ export const MainModal: React.FC<MainModalProps> = ({
8695
}
8796

8897
return (
89-
<div
90-
className="fixed inset-0 z-50 flex items-center justify-center bg-black/50"
91-
>
98+
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50">
9299
<section
93100
ref={modalRef}
94101
className="w-full max-w-md mx-4 bg-white/80 shadow-[0px_4px_74px_0px_rgba(0,0,0,0.15)] backdrop-blur-[54px] rounded-3xl overflow-hidden flex flex-col justify-center items-center"

components/modals/main-modal/main-modal.types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { SendOneSidedRequest } from '@/clients/tari-l1-signer'
12
import { Network } from '@/components/network-box'
23

34
export type MainModalProps = {
@@ -13,4 +14,5 @@ export type MainModalProps = {
1314
tariWalletAddress?: string
1415
fromNetwork: Network
1516
toNetwork: Network
17+
pendingBridgeTxFromTU?: SendOneSidedRequest
1618
}

hooks/use-bridge-to-ethereum.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ export const useBridgeToEthereum = () => {
4444
console.debug('[ TAPPLET-BRIDGE ] created tx with id: ', paymentId)
4545

4646
const isSend = await signer?.sendOneSided({
47-
amount,
47+
amount: tokenAmount,
4848
address: config.TARI_BRIDGE_COLDWALLET_ADDRESS,
49-
message: paymentId,
49+
paymentId: paymentId,
5050
})
5151

5252
if (!isSend) {

store/account.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { AccountData } from '@/types/tapplet'
22
import { create } from 'zustand'
33
import useTariSigner from './signer'
4+
import { SendOneSidedRequest } from '@/clients/tari-l1-signer'
45

56
interface State {
67
tariAccount?: AccountData
78
available_balance: number
89
pendingBridgeTx: string[]
910
isProcessingTransaction: boolean
11+
pendingBridgeTxFromTU?: SendOneSidedRequest
1012
}
1113

1214
interface Actions {
@@ -26,6 +28,7 @@ const initialState: State = {
2628
available_balance: 0,
2729
pendingBridgeTx: [],
2830
isProcessingTransaction: false,
31+
pendingBridgeTxFromTU: undefined,
2932
}
3033

3134
export const useTariAccount = create<OotleWalletStoreState>()((set) => ({
@@ -40,12 +43,16 @@ export const useTariAccount = create<OotleWalletStoreState>()((set) => ({
4043
}
4144
const account = await signer.getAccount()
4245
const balance = await signer.getTariBalance()
46+
const pendingTx = await signer.isPendingTappletTx()
47+
console.info('[ TAPPLET-BRIDGE ] call TU pending tx', pendingTx)
4348
set({
4449
tariAccount: {
4550
account_id: account.account_id,
4651
address: account.address,
4752
},
4853
available_balance: balance?.available_balance ?? 0,
54+
pendingBridgeTxFromTU: pendingTx,
55+
isProcessingTransaction: !!pendingTx,
4956
})
5057
} catch (error) {
5158
console.error('Could not set the Tari account: ', error)

0 commit comments

Comments
 (0)