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

Polishing. Fill out the Custom WebHook URL on initialization. #1223

Closed
creeppak opened this issue Nov 4, 2024 · 2 comments · Fixed by #1265
Closed

Polishing. Fill out the Custom WebHook URL on initialization. #1223

creeppak opened this issue Nov 4, 2024 · 2 comments · Fixed by #1265
Assignees

Comments

@creeppak
Copy link
Contributor

creeppak commented Nov 4, 2024

WebHook URL is selected in the dropdown by default (when you create a new web3.unity project config), but the text field is empty. It should be filled as user need to add his infura token.

image

@sneakzttv
Copy link
Contributor

I can fix this one!

@sneakzttv sneakzttv self-assigned this Jan 6, 2025
@sneakzttv
Copy link
Contributor

sneakzttv commented Jan 7, 2025

The websocket if it's there is already being applied via Web3SettingsEditor.ChainSettings.cs:

if (webHookOptions.Length > 0)
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.PrefixLabel("Select WebHook");
                    selectedWebHookIndex =
                        Mathf.Clamp(selectedWebHookIndex, 0, window.chainList[selectedChainIndex].rpc.Count - 1);
                    var webhookIndex = window.chainList[selectedChainIndex].rpc.IndexOf(chainConfig.Ws);
                    var selectedWebHook =
                        webhookIndex == -1 ? window.chainList[selectedChainIndex].rpc[selectedWebHookIndex] : chainConfig.Ws;
                    if (GUILayout.Button(selectedWebHook, EditorStyles.popup))
                    {
                        searchProvider = CreateInstance<StringListSearchProvider>();
                        searchProvider.Initialize(webHookOptions,
                            x =>
                            {
                                var str = x.Replace("\u2215", "/");

                                selectedWebHookIndex = window.chainList[selectedChainIndex].rpc.IndexOf(str);
                                chainConfig.Ws = str;
                                changedRpcOrWs = true;
                                UpdateServerMenuInfo();
                            });
                        SearchWindow.Open(
                            new SearchWindowContext(GUIUtility.GUIToScreenPoint(Event.current.mousePosition)),
                            searchProvider);
                    }

                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.HelpBox("If you set your custom WebHook URI it will override the selection above.", MessageType.Info);
                }

                chainConfig.Ws = EditorGUILayout.TextField("Custom WebHook", chainConfig.Ws);

I've also altered the ternary operator with an extra safety check though just to be sure.

var selectedWebHook = (webhookIndex == -1 || string.IsNullOrEmpty(chainConfig.Ws))  ? window.chainList[selectedChainIndex].rpc[selectedWebHookIndex] : chainConfig.Ws;

https://gyazo.com/05c96ad8c83dc489d9358c70d9bdd44a

@sneakzttv sneakzttv linked a pull request Jan 7, 2025 that will close this issue
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 a pull request may close this issue.

2 participants