@@ -3,10 +3,14 @@ import { BrowserProvider } from 'ethers'
3
3
import type { ChangeEvent } from 'react'
4
4
import { useState } from 'react'
5
5
6
+ import './patch'
7
+
6
8
import './App.css'
7
9
8
- import { checkNeedAllowance , getAllowances , getRoute , permit , setAllowance } from './flow'
9
- import { isValidEthereumAddress } from './helpers'
10
+ import { checkNeedAllowance , gaslessTransfer , getAllowances , getRoute , permit , setAllowance } from './flow'
11
+ import { gaslessExecute } from './flow/gaslessExecute'
12
+ import { checkTransferRoute , isValidEthereumAddress } from './helpers'
13
+ import { STEPS } from './constants'
10
14
11
15
function App ( ) {
12
16
const [ provider , setProvider ] = useState < BrowserProvider | null > ( null )
@@ -47,15 +51,17 @@ function App() {
47
51
setStep ( 3 )
48
52
const isNeedAllowance = await checkNeedAllowance ( route , allowances )
49
53
54
+ setStep ( 4 )
50
55
await signer . provider . send ( 'wallet_switchEthereumChain' , [
51
56
{
52
57
chainId : `0x${ route . fromToken . chainId . toString ( 16 ) } `
53
58
}
54
59
] )
55
60
56
- let allowanceResult : Signature | null = null
61
+ let allowanceResult : Signature | undefined
57
62
58
63
if ( isNeedAllowance ) {
64
+ setStep ( 5 )
59
65
try {
60
66
allowanceResult = await permit ( route , allowances , signer )
61
67
} catch ( e ) {
@@ -65,8 +71,18 @@ function App() {
65
71
}
66
72
}
67
73
68
- // eslint-disable-next-line no-debugger, no-restricted-syntax
69
- debugger
74
+ setStep ( 6 )
75
+ const isTransferRoute = checkTransferRoute ( route )
76
+
77
+ let resultHash : string
78
+ if ( isTransferRoute ) {
79
+ resultHash = await gaslessTransfer ( route , signer , allowances , allowanceResult )
80
+ } else {
81
+ resultHash = await gaslessExecute ( route , signer , allowances , allowanceResult )
82
+ }
83
+
84
+ // eslint-disable-next-line no-console
85
+ console . log ( 'Transaction hash:' , resultHash )
70
86
71
87
// Finish!
72
88
setStep ( 0 )
@@ -112,13 +128,10 @@ function App() {
112
128
Send
113
129
</ button >
114
130
115
- { /* Progress */ }
116
131
{ step > 0 && (
117
132
< div className = "progress" >
118
133
< p >
119
- { step === 1 && 'Get allowances from backend...' }
120
- { step === 2 && 'Fetch route...' }
121
- { step === 3 && 'Allowance check...' }
134
+ { STEPS [ step ] }
122
135
</ p >
123
136
</ div >
124
137
) }
0 commit comments