Skip to content

Commit

Permalink
fix(widget): Fixes decimal input with no leading zeros, wallet cancel…
Browse files Browse the repository at this point in the history
… on send (#2354)

* Fixes decimal input with no leading zeros, wallet cancel on send
  • Loading branch information
abtestingalpha authored Mar 22, 2024
1 parent 198dc48 commit 8c9f382
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 39 deletions.
72 changes: 34 additions & 38 deletions packages/widget/src/state/slices/bridgeTransaction/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,50 +42,46 @@ export const executeBridgeTxn = createAsyncThunk(
signer: any
synapseSDK: any
}) => {
try {
const data = await synapseSDK.bridge(
destinationAddress,
originRouterAddress,
originChainId,
destinationChainId,
tokenAddress,
amount,
originQuery,
destQuery
)
const data = await synapseSDK.bridge(
destinationAddress,
originRouterAddress,
originChainId,
destinationChainId,
tokenAddress,
amount,
originQuery,
destQuery
)

const payload =
tokenAddress === ZeroAddress
? {
data: data.data,
to: data.to,
value: amount,
}
: {
data: data.data,
to: data.to,
}
const payload =
tokenAddress === ZeroAddress
? {
data: data.data,
to: data.to,
value: amount,
}
: {
data: data.data,
to: data.to,
}

const tx = await signer.sendTransaction(payload)
const tx = await signer.sendTransaction(payload)

const receipt = await tx.wait()
const receipt = await tx.wait()

const txHash = receipt?.hash ?? receipt?.transactionHash
const txHash = receipt?.hash ?? receipt?.transactionHash

const timestamp = getTimeMinutesFromNow(0)
const timestamp = getTimeMinutesFromNow(0)

return {
txHash,
bridgeModuleName,
parsedOriginAmount,
originTokenSymbol,
originChainId,
destinationChainId,
estimatedTime,
timestamp,
}
} catch (error) {
console.error('Error executing bridge: ', error)
return {
txHash,
bridgeModuleName,
parsedOriginAmount,
originTokenSymbol,
originChainId,
destinationChainId,
estimatedTime,
timestamp,
}
}
)
11 changes: 10 additions & 1 deletion packages/widget/src/utils/isOnlyZeroes.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/**
* This regex matches a string that either:
* 1. consists only of one or more '0' characters
* 2. consists of a single '0' followed by a '.' and zero or more '0' characters
* 3. consists solely of a '.' followed by one or more '0' characters
*/

export const isOnlyZeroes = (input: string): boolean => {
return /^(0+(\.0*)?|\.\d+)$/.test(input.trim())
const regex = /^(0+|0?\.0+)$/

return regex.test(input.trim())
}

0 comments on commit 8c9f382

Please sign in to comment.