Skip to content
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

feat: notify upon incoming UTXOs #33

Merged
merged 8 commits into from
Feb 13, 2025
Merged

feat: notify upon incoming UTXOs #33

merged 8 commits into from
Feb 13, 2025

Conversation

0x7u
Copy link
Contributor

@0x7u 0x7u commented Feb 12, 2025

Pull Request Checklist

Before Submission


Description

Notify the user upon incoming UTXOs


Additional Notes


By submitting this pull request, I confirm that:

  • My contribution is made under the Business Source License
  • I grant Forbole Technology Limited a perpetual, worldwide, non-exclusive license to use my contribution under the
    project's
    license terms
  • I have the authority to make this contribution and license it appropriately

@0x7u 0x7u requested a review from dadamu February 12, 2025 06:47
@0x7u 0x7u self-assigned this Feb 12, 2025
txId,
);
}

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 (!addresses) return

I remember you said there is a bug about it will listen all addresses's utxos if it is empty.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it is guarded here

if (!rpcClient || isWalletSettingsLoading || addresses.length === 0) {

The function is getting hard to read because you have a couple of nested function I will try to keep them at the top of the function.

return;
}

const txId = event.added[0].outpoint.transactionId;
Copy link
Contributor

Choose a reason for hiding this comment

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

Are all added utxos are from the same transaction? I believe it is not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe UTXOs can come from different addresses by they will be in the same transaction.

Copy link
Contributor

@dadamu dadamu left a comment

Choose a reason for hiding this comment

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

Overall it is good to me. Just have a question about added utxos in the event.

}

const txId = event.added[0].outpoint.transactionId;
const network = settings?.networkId ?? NetworkType.Mainnet;
Copy link
Contributor

Choose a reason for hiding this comment

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

We can use networkId from useRpcClientStateful instead of settings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I refactored the code to keep it consistent 782cd77

@@ -587,7 +595,7 @@ export function WalletManagerProvider({ children }: { children: ReactNode }) {
}

await saveWalletSettings(walletSettings);
};
}, []);
Copy link
Contributor

@dadamu dadamu Feb 12, 2025

Choose a reason for hiding this comment

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

Why using callback here? In addition, I think here are missing some dependencies, say, networkId, walletSettings and etc.

Copy link
Contributor

Choose a reason for hiding this comment

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

image
It becomes an issue, that switching network would not change the addresses. The image is in mainnet now but still have test prefix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I introduce the useCallback to break the dependency chain and then the rerenders.
But it was more than a hack than the correct solution.

Thanks for removing it ;)

rpcClient.subscribeUtxosChanged(addresses);
return () => {
rpcClient.unsubscribeUtxosChanged(addresses);

rpcClient.removeEventListener("utxos-changed", fetchBalance);
Copy link
Contributor

@dadamu dadamu Feb 12, 2025

Choose a reason for hiding this comment

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

The removeEventListener is not updated. Fixed infinitely re-render by updating this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please check this commit:
a788456

Copy link
Contributor Author

@0x7u 0x7u Feb 13, 2025

Choose a reason for hiding this comment

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

Thanks for catching that bug !!!

Also, I have removed the safeQueue because it created more renders than without. I think it was solving the issues of not accounting for the settings loading.
Let me know if I am missing anything. I tested a bit it seems to work fine.

3e1b117

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I agree with it. Javascript event loop have already queued the operations. No need to have this.

@0x7u 0x7u force-pushed the feat/notify-incoming-utxos branch from 797ad22 to 3e1b117 Compare February 13, 2025 03:08
@0x7u 0x7u merged commit 97e6344 into main Feb 13, 2025
1 check passed
@0x7u 0x7u mentioned this pull request Feb 13, 2025
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