Closed dnischeta closed 1 month ago
Hey @dnischeta, thanks for your insightful review and suggestions! 👍 We've addressed the issues in the updated version here #10 . Could you please take a look and let us know if it's ready to be merged?
@sansx , hello! I'll take a look today.
One other thing I was thinking about is adding a plugin. That solution replaces need of <TonConnectUIProvider>
with installing that plugin, user will do:
import { createApp } from 'vue'
const app = createApp({})
app.use(tonConnectUI, {
manifestURL: '...'
})
tonConnectUI
plugin may register a global property or use provide.
@sansx , hi! As I see, PR is pending, so if you wish, I can contribute to unblock that PR. I'll have some time next few days.
Hey @dnischeta ! Thanks so much for your interest in this. The feature is now complete https://github.com/TownSquareXYZ/tonconnect-ui-vue/pull/10/commits/af7c4d24f825d36c453ccb694ba0dbddacb755f1, can't wait for your feedback, and it would be great if we could test it together. Also it will be fantastic to discuss any potential optimizations or improvements together as well.
@sansx , hello! I've created https://github.com/TownSquareXYZ/tonconnect-ui-vue/pull/12 which includes some important fixes (removing useless code from provider and plugin discussion). So we can discuss changes there.
@sansx , hello again. Looks like I've figured it out how to implement plugin. So I did it, you may see it in the PR. Also, I've updated my demos repo with plugin usage branch.
It means, that we can drop <TonConnectUIProvider>
at all (also injection-keys).
Introduction
@alexgton asked me to review that project from a developer familiar with Vue perspective. So that issue contains review summary.
Issues are grouped using next strategy:
How review was done
Critical issues
[Critical] usage
<TonConnectButton>
propsstyles
andclassName
should be removed. Vue bindsstyle
andclass
props to the root element by default, see docs. So it's better to remove redundant props before public release.README.md
should be updated and synchronized with final public interface. I've found a few inconsistent examples:TonConnectButton
hasstyle
andclass
props, but actually it has onlystyles
andclassName
props. (in that cade, actually, README is correct, see Usage - TonConnectButton).useTonConnectUI
examples. Examples say, that user should useconst tonConnectUI = useTonConnectUI();
but actually user should doconst { tonConnectUI } = useTonConnectUI();
eitherconst [tonConnectUI] = useTonConnectUI();
depending on final implementation.[Critical] implementation
TonConnectUI
DI issue. Now,<TonConnectUiProvider>
won't recreateTonConnectUi
instance onoptions
prop change, React implementation will. Probably, that should be fixed in<TonConnectUiProvider>
. Next step is providing reactive object instead of raw:provide('ton-connect-ui', tonConnectUI);
// Injection consumer, for example
useTonWallet
const tonConnectUi = inject('ton-connect-ui'); // That line of code should be insideuseTonConnectUI
, put it here for simplification const unsub = shallowRef<() => void>(() => {}); const wallet = shallowRef<...>(null);onMounted(() => { watch(tonConnectUI, (actualTonConnectUI) => { unsub(); // Unsubscribe on watcher trigger <-> when tonConnectUI instance is updated (as done in React)
}); });
onUnmounted(() => { unsub.value(); });
Minor issues
[Minor] Usage
useTonConnectUI
returns tuple[ui, setOptions]
similar to react implementation. But developer familiar with Vue would expect that interfaceconst { tonConnectUI, setOptions } = useTonConnectUI()
. It's not a common practice in Vue to return tuples but that issue only affects code style.[Minor] implementation
ShallowRefs
ShallowRef may be used to wrap
TonConnectUI
orWallet
instances to escape redundant calculations.computed
instead ofwatchEffect
In
useTonAddress
computed
should be used instead ofwatchEffect
.watchEffect
should be used in case some side-effect is required. For derivative state (as address of the wallet)computed
should be used.Props:
required: false
should be omittedIn
TonConnectButton
optional props are marked withrequired: false
. This is redundant, props is optional by default.Native elements attrs
In
TonConnectButton
.No need to bind id as attr, it's enough to bind it explicitly. So binding:
attrs: { id: props.buttonRootId || "" }
should be removed.Configure formatting/linting in CI. Now there are a couple of places with inconsistent formatting.
/scripts/
directory should be checked, postinstall script does nothing.Conclusion and recommendation
I've checked that library in vue@2.7 and vue@3 project. Looks like it works fine in common scenarios. But I would recommend to fix or discuss and decline all issues mentioned in critical and moderate groups before public release.