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

fix: issue14 and add changlog.md #20

Closed
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Changelog

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## 2.1.0 (2024-11-04)


### Features

* add TonConnectUIPlugin ([af7c4d2](https://github.com/TownSquareXYZ/tonconnect-ui-vue/commit/af7c4d24f825d36c453ccb694ba0dbddacb755f1))
* add TypeScript type definitions ([4cd5796](https://github.com/TownSquareXYZ/tonconnect-ui-vue/commit/4cd5796829a1e44d5266f0161c4853d792de1ecb))
* use Symble key in provide / inject ([e3f5115](https://github.com/TownSquareXYZ/tonconnect-ui-vue/commit/e3f51155999d2699170a416909ed01db6c7b0dc2))


### Bug Fixes

* add vue-demi to external dependencies ([e83b1bd](https://github.com/TownSquareXYZ/tonconnect-ui-vue/commit/e83b1bd91e1f9aa404098de90d394548f6821bdf))
* resolve issues with Vue 2.7 integration ([263dd91](https://github.com/TownSquareXYZ/tonconnect-ui-vue/commit/263dd917c77c3007c878eaef4882ea159b501619))
* update injections components & watch options change ([e1f8be8](https://github.com/TownSquareXYZ/tonconnect-ui-vue/commit/e1f8be88dffabaa7c0a81ffe961b3c56ce66cc96))
* useTonConnectUI().tonConnectUI is not typed ([2449bd8](https://github.com/TownSquareXYZ/tonconnect-ui-vue/commit/2449bd8027c235818f085bdce608edc9ba5ee3d6))

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"lint-fix": "eslint --fix --ext .ts,.vue src",
"lint": "eslint",
"prepare": "husky",
"security-audit": "npm audit && npm outdated"
"security-audit": "npm audit && npm outdated",
"release": "standard-version"
},
"publishConfig": {
"access": "public"
Expand Down Expand Up @@ -90,7 +91,8 @@
"vue": "^2.7.16",
"vue-demi": "^0.14.10",
"vue-eslint-parser": "^9.4.0",
"vue-tsc": "^0.39.5"
"vue-tsc": "^0.39.5",
"standard-version": "^9.5.0"
},
"lint-staged": {
"*.{vue,ts,tsx}": [
Expand Down
21 changes: 11 additions & 10 deletions src/hooks/useTonConnectUI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,26 @@ import { isServerSide } from '../utils/web';
export function useTonConnectUI() {
if (isServerSide()) {
return {
tonConnectUI: null as unknown as TonConnectUI,
tonConnectUI: null as TonConnectUI | null,
setOptions: () => {},
};
}

const globalPropertiesMap = isVue2
? getCurrentInstance()?.proxy
// @ts-expect-error
: getCurrentInstance().appContext.app.config.globalProperties;
const instance = getCurrentInstance() as any;
const globalPropertiesMap = isVue2 ? instance?.proxy: instance?.appContext?.app.config.globalProperties

const tonConnectUI = globalPropertiesMap.$tonConnectUI;
const tonConnectUI = globalPropertiesMap?.$tonConnectUI as TonConnectUI | undefined;

if (!tonConnectUI) {
throw new Error("TonConnect is not avaliable");
Copy link

Choose a reason for hiding this comment

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

Throwing an exception directly within the hooks function body will interrupt the entire setup process. Consider using an error handler or logging a console error/warning to provide a notification instead.

Copy link
Author

Choose a reason for hiding this comment

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

That’s an excellent question! I’ve carefully reconsidered this issue and have come up with a potential solution:

return {
            tonConnectUI: null,
            setOptions: () => console.warn("TonConnect is not available"),
            error: new Error("TonConnect is not available"),
        };

demo

const {tonConnectUI, setOptions, error} = useTonConnectUI();

    if (error) {
      console.warn(error.message); // 输出警告信息
      return {}; // 或者在 UI 上显示提示
    }

}

checkProvider(tonConnectUI);

const setOptions = (options: TonConnectUiOptions) => {
if (tonConnectUI && tonConnectUI) {
tonConnectUI.uiOptions = options;
}
tonConnectUI.uiOptions = options;
};

checkProvider(tonConnectUI);

return {
tonConnectUI,
Expand Down
Loading