Skip to content

Refactor checkResult() #886

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

Merged
merged 6 commits into from
Jul 22, 2024
Merged

Conversation

abdulmth
Copy link
Contributor

No description provided.

@abdulmth abdulmth requested a review from rflechtner July 18, 2024 11:26
@abdulmth abdulmth force-pushed the abd-chore-refactor-check-result branch from aaea545 to 7484bd5 Compare July 18, 2024 12:29
Comment on lines 55 to 58
let status: TransactionResult['status'] | undefined
let blockHash
let blockNumber
let error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's use returns inside of the switch instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 25 to 26
let error
txEvents.forEach(({ event }) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let error
txEvents.forEach(({ event }) => {
return txEvents.find(({ event }) => {

combine this with returns (I'll make one example below) and our function becomes simpler and faster (exits on first error)

const isSuccess = !error && eventMatch

status = isSuccess ? 'confirmed' : 'failed'
if (!isSuccess && !error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!isSuccess && !error) {
if (!isSuccess && !eventMatch) {

why not be more explicit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

} from './interfaces.js'

function mapError(err: SpRuntimeDispatchError, api: ApiPromise): Error {
export function mapError(err: SpRuntimeDispatchError, api: ApiPromise): Error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one and the next are only used in checkResult rn, so they could move there too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abdulmth abdulmth requested a review from rflechtner July 22, 2024 07:53
Copy link
Contributor

@rflechtner rflechtner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@abdulmth abdulmth merged commit 8a9d808 into rf-did-helpers Jul 22, 2024
1 check failed
@abdulmth abdulmth deleted the abd-chore-refactor-check-result branch July 22, 2024 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants