Skip to content

Commit

Permalink
Skip check object if canonical bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
pedromcunha committed Apr 4, 2024
1 parent bc4bff6 commit 441b0b7
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 47 deletions.
42 changes: 21 additions & 21 deletions demo/pages/sdk/actions/bridge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const BridgeActionPage: NextPage = () => {
const [amount, setAmount] = useState<string>("")
const [currency, setCurrency] =useState<BridgeActionParameters['currency']>('eth')
const [usePermit, setUsePermit] = useState(false)
const [canonical, setCanonical] = useState(false)
const [toChainId, setToChainId] = useState<number>(zora.id)
const [fromChainId, setFromChainId] = useState<number>(base.id)
const [depositGasLimit, setDepositGasLimit] = useState("")
Expand Down Expand Up @@ -70,26 +71,24 @@ const BridgeActionPage: NextPage = () => {

<div>
<label>Use Permit: </label>
<div>
<input
type="radio"
value="usePermit-true"
name="usePermit"
checked={usePermit === true}
onChange={(e) => setUsePermit(true)}
/>
<label>True</label>
</div>
<div>
<input
type="radio"
value="usePermit-false"
name="usePermit"
checked={usePermit === false}
onChange={(e) => setUsePermit(false)}
/>
<label>False</label>
</div>
<input
type="checkbox"
checked={usePermit}
onChange={(e) => {
setUsePermit(e.target.checked)
}}
/>
</div>

<div>
<label>Canonical: </label>
<input
type="checkbox"
checked={canonical}
onChange={(e) => {
setCanonical(e.target.checked)
}}
/>
</div>

<div>
Expand Down Expand Up @@ -132,7 +131,8 @@ const BridgeActionPage: NextPage = () => {
recipient: recipient ? recipient as Address : undefined,
depositGasLimit,
options: {
usePermit: usePermit
usePermit: usePermit,
useExternalLiquidity: canonical
},
onProgress: (steps, fees, currentStep, currentStepItem, txHashes) => {
console.log(steps, fees, currentStep, currentStepItem, txHashes)
Expand Down
48 changes: 24 additions & 24 deletions packages/sdk/src/utils/executeSteps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ export async function executeSteps(
setState: (
steps: Execute['steps'],
fees?: Execute['fees'],
breakdown?: Execute['breakdown']
breakdown?: Execute['breakdown'],
) => any,
newJson?: Execute,
stepOptions?: {
[stepId: string]: {
gasLimit?: string
}
}
},
) {
const client = getClient()

Expand Down Expand Up @@ -94,7 +94,7 @@ export async function executeSteps(
}

incompleteStepItemIndex = step.items.findIndex(
(item) => item.status == 'incomplete'
(item) => item.status == 'incomplete',
)
if (incompleteStepItemIndex !== -1) {
incompleteStepIndex = i
Expand Down Expand Up @@ -124,7 +124,7 @@ export async function executeSteps(
if (!stepItems) {
client.log(
['Execute Steps: skipping step, no items in step'],
LogLevel.Verbose
LogLevel.Verbose,
)
return
}
Expand All @@ -135,12 +135,12 @@ export async function executeSteps(
if (!stepItem.data) {
client.log(
['Execute Steps: step item data is missing, begin polling'],
LogLevel.Verbose
LogLevel.Verbose,
)
json = (await pollUntilHasData(request, (json) => {
client.log(
['Execute Steps: step item data is missing, polling', json],
LogLevel.Verbose
LogLevel.Verbose,
)
const data = json as Execute
// An item is ready if:
Expand Down Expand Up @@ -169,7 +169,7 @@ export async function executeSteps(
}
client.log(
[`Execute Steps: Begin processing step items for: ${step.action}`],
LogLevel.Verbose
LogLevel.Verbose,
)

const promises = stepItems
Expand All @@ -191,7 +191,7 @@ export async function executeSteps(
[
'Execute Steps: Begin transaction step for, sending transaction',
],
LogLevel.Verbose
LogLevel.Verbose,
)

// if chainId is present in the tx data field then you should relay the tx on that chain
Expand All @@ -212,14 +212,14 @@ export async function executeSteps(
'Execute Steps: Transaction step, got transactions',
txHashes,
],
LogLevel.Verbose
LogLevel.Verbose,
)
stepItem.txHashes = txHashes
if (json) {
setState(
[...json.steps],
{ ...json?.fees },
json?.breakdown
json?.breakdown,
)
}
},
Expand All @@ -229,13 +229,13 @@ export async function executeSteps(
setState(
[...json.steps],
{ ...json?.fees },
json?.breakdown
json?.breakdown,
)
}
},
request,
undefined,
crossChainIntentChainId
crossChainIntentChainId,
)
} catch (e) {
throw e
Expand All @@ -250,12 +250,12 @@ export async function executeSteps(
const postData = stepData['post']
client.log(
['Execute Steps: Begin signature step'],
LogLevel.Verbose
LogLevel.Verbose,
)
if (signData) {
signature = await wallet.handleSignMessageStep(
stepItem as SignatureStepItem,
step
step,
)

if (signature) {
Expand All @@ -269,7 +269,7 @@ export async function executeSteps(
if (postData) {
client.log(['Execute Steps: Posting order'], LogLevel.Verbose)
const postOrderUrl = new URL(
`${request.baseURL}${postData.endpoint}`
`${request.baseURL}${postData.endpoint}`,
)
const headers = {
'Content-Type': 'application/json',
Expand Down Expand Up @@ -298,7 +298,7 @@ export async function executeSteps(
setState(
[...json?.steps],
{ ...json?.fees },
json?.breakdown
json?.breakdown,
)

await pollUntilOk(
Expand All @@ -313,7 +313,7 @@ export async function executeSteps(
`Execute Steps: Polling execute status to check if indexed`,
res,
],
LogLevel.Verbose
LogLevel.Verbose,
)
if (
res?.data?.status === 'success' &&
Expand All @@ -328,7 +328,7 @@ export async function executeSteps(
chainId:
res.data.destinationChainId ?? chain?.id,
}
}
},
)

if (res?.data?.inTxHashes) {
Expand All @@ -341,7 +341,7 @@ export async function executeSteps(
chainId:
res.data.destinationChainId ?? chain?.id,
}
}
},
)
stepItem.internalTxHashes = chainInTxHashes
}
Expand All @@ -350,14 +350,14 @@ export async function executeSteps(
return true
} else if (res?.data?.status === 'failure') {
throw Error(
res?.data?.details || 'Transaction failed'
res?.data?.details || 'Transaction failed',
)
}
return false
},
maximumAttempts,
0,
pollingInterval
pollingInterval,
)
}

Expand All @@ -377,7 +377,7 @@ export async function executeSteps(
setState(
[...json?.steps],
{ ...json?.fees },
json?.breakdown
json?.breakdown,
)
} catch (err) {
throw err
Expand Down Expand Up @@ -424,12 +424,12 @@ export async function executeSteps(
} catch (blockError) {
client.log(
['Execute Steps: Failed to get block number', blockError],
LogLevel.Error
LogLevel.Error,
)
}
client.log(
['Execute Steps: An error occurred', err, 'Block Number:', blockNumber],
LogLevel.Error
LogLevel.Error,
)

if (json) {
Expand Down
3 changes: 1 addition & 2 deletions packages/sdk/src/utils/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ export async function sendTransactionSafely(
!transactionCancelled
) {
let res

if (item?.check?.endpoint) {
if (item?.check?.endpoint && !request.data.useExternalLiquidity) {
res = await axios.request({
url: `${request.baseURL}${item?.check?.endpoint}`,
method: item?.check?.method,
Expand Down

0 comments on commit 441b0b7

Please sign in to comment.