-
-
Notifications
You must be signed in to change notification settings - Fork 650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix RSK EIP1191 checksum issues #4151
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ import isEmpty from 'lodash/isEmpty'; | |
import mergeDeepWith from 'ramda/src/mergeDeepWith'; | ||
import styled from 'styled-components'; | ||
import { ValuesType } from 'utility-types'; | ||
import { number, object, string } from 'yup'; | ||
import { number, object, ObjectSchema, string } from 'yup'; | ||
|
||
import { | ||
AccountSelector, | ||
|
@@ -41,6 +41,7 @@ import { useGasForm } from '@hooks'; | |
import { getNonce, useRates } from '@services'; | ||
import { | ||
isBurnAddress, | ||
isValidAddress, | ||
isValidETHAddress, | ||
isValidPositiveNumber | ||
} from '@services/EthService/validators'; | ||
|
@@ -279,9 +280,13 @@ export const SendAssetsForm = ({ txConfig, onComplete, protectTxButton }: ISendF | |
account: object().required(translateRaw('REQUIRED')), | ||
address: object() | ||
.required(translateRaw('REQUIRED')) | ||
.test('valid', translateRaw('TO_FIELD_ERROR'), function (value) { | ||
return value && value.value && isValidETHAddress(value.value); | ||
}) | ||
.when('network', (network: Network, schema: ObjectSchema) => | ||
schema.test('valid', translateRaw('TO_FIELD_ERROR', { $network: network.name }), function ( | ||
value | ||
) { | ||
return value && value.value && isValidAddress(value.value, network.chainId); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks to work, but I am not sure it will be possible to send without fixing the issues in Ethers. Balance scanning etc seems to be failing on RSK right now. Have you talked to ricmoo or is there an open issue? |
||
}) | ||
) | ||
// @ts-expect-error Hack as Formik doesn't officially support warnings | ||
// tslint:disable-next-line | ||
.test('check-sending-to-burn', translateRaw('SENDING_TO_BURN_ADDRESS'), function (value) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import { Network } from '@ethersproject/networks'; | ||
import { ALL_DERIVATION_PATHS } from '@mycrypto/wallets'; | ||
import { ResolutionError } from '@unstoppabledomains/resolution'; | ||
import BigNumber from 'bignumber.js'; | ||
|
@@ -12,6 +13,7 @@ import { | |
GAS_PRICE_GWEI_LOWER_BOUND, | ||
GAS_PRICE_GWEI_UPPER_BOUND | ||
} from '@config'; | ||
import { NETWORKS_CONFIG } from '@database/data'; | ||
import translate, { translateRaw } from '@translations'; | ||
import { InlineMessageType } from '@types'; | ||
import { | ||
|
@@ -81,17 +83,29 @@ export function isValidETHLikeAddress(address: string, isChecksumValid: boolean) | |
return true; | ||
} | ||
|
||
export const isValidETHRecipientAddress = ( | ||
export const isValidRecipientAddress = ( | ||
address: string, | ||
resolutionErr: ResolutionError | undefined | ||
resolutionErr: ResolutionError | undefined, | ||
network: Network = NETWORKS_CONFIG.Ethereum | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would prefer having |
||
) => { | ||
if (isValidENSName(address) && resolutionErr) { | ||
if (network.chainId === 30 || network.chainId === 31) { | ||
// TODO: Consider checking RSN name if it will be supported by unstoppabledomains | ||
// Is a invalid EIP-1191 checksum when trying to send through RSK network | ||
return isValidRSKAddress(address, network.chainId) | ||
? { success: true } | ||
: { | ||
success: false, | ||
name: 'ValidationError', | ||
type: InlineMessageType.ERROR, | ||
message: translate('CHECKSUM_RSK_ERROR', { $network: network.name }) | ||
}; | ||
} else if (isValidENSName(address) && resolutionErr) { | ||
// Is a valid ENS name, but it couldn't be resolved or there is some other issue. | ||
return { | ||
success: false, | ||
name: 'ValidationError', | ||
type: InlineMessageType.ERROR, | ||
message: translateRaw('TO_FIELD_ERROR') | ||
message: translateRaw('TO_FIELD_ERROR', { $network: network.name }) | ||
}; | ||
} else if (isValidENSName(address) && !resolutionErr) { | ||
// Is a valid ENS name, and it can be resolved! | ||
|
@@ -132,7 +146,7 @@ export const isValidETHRecipientAddress = ( | |
success: false, | ||
name: 'ValidationError', | ||
type: InlineMessageType.ERROR, | ||
message: translateRaw('TO_FIELD_ERROR') | ||
message: translateRaw('TO_FIELD_ERROR', { $network: network.name }) | ||
}; | ||
} | ||
return { success: true }; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I provided
network
to avoid it to be displayed asEnter a valid $network address, ENS name, or blockchain domain
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't you move the schema inside the component so it can access the
network
prop and use that instead?