Skip to content

Commit

Permalink
feat: auth功能拓展
Browse files Browse the repository at this point in the history
1. github release 脚本
2. getOtac & openPage拓展 & auth示例完善 & doc 更新
3. remove sensitive info
  • Loading branch information
chenweigh committed Oct 23, 2024
1 parent aac9359 commit 7ae3d69
Show file tree
Hide file tree
Showing 19 changed files with 1,068 additions and 239 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@ dist*

.turbo

sensitive.txt
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@
"eslint.format.enable": true,
"eslint.codeActionsOnSave.rules": null,
"eslint.codeActionsOnSave.mode": "all",
"vs-code-prettier-eslint.prettierLast": true
"vs-code-prettier-eslint.prettierLast": true,
// //关闭js/ts默认format,统一用eslint
// "javascript.format.enable": false,
// "typescript.format.enable": false
// 禁用 VSCode 默认的 HTML 格式化
"html.format.enable": false,
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
7 changes: 7 additions & 0 deletions examples/example-auth-react/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@
.card {
padding: 2em;
}
.row{
display: flex;
flex-direction: row;
}
.justify-center{
justify-content: center;
}

.read-the-docs {
color: #888;
Expand Down
162 changes: 158 additions & 4 deletions examples/example-auth-react/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,24 @@ import {
IUserInfo,
LoginType,
OpenPageMode,
PageOptionParam,
PageType,
XterEventEmiter,
XTERIO_EVENTS,
XterioAuth
} from '@xterio-sdk/auth'

const isChecked = (cls: string) => {
const ele = document.getElementsByClassName(cls)?.[0]
// console.log('ele', ele)
const input = ele?.getElementsByTagName('input')?.[0]
return input?.checked
}
const getRadioValue = (name: string) => {
const tab: HTMLInputElement | null = document.querySelector(`input[name="${name}"]:checked`)
return tab?.value
}

function App() {
const [userinfo, setUserinfo] = useState<string>('')
//这种形式记录不够准确,比如登录态中途变更时,该页面无法及时获悉。所以对于需要判断登录的操作,直接调用XterioAuth.isLogin即可
Expand Down Expand Up @@ -47,7 +59,7 @@ function App() {
XterioAuth.logout()
}
const openPage = async (_t: OpenPageMode) => {
const res = await XterioAuth.openPage(currentPage, _t)
const res = await XterioAuth.openPage(currentPage, _t, getPageParam())
if (_t === OpenPageMode.iframeDom) {
console.log('dom=', res)
alert(res)
Expand All @@ -56,6 +68,64 @@ function App() {
alert(res)
}
}
const getPageParam = () => {
let dic: PageOptionParam = {}
const curPage = currentPage

if (curPage === PageType.asset) {
const value = (getRadioValue('asset_active_tab_option') || 'ingame') as PageOptionParam['active']
dic = { ...dic, active: value }
}
if (curPage === PageType.setting) {
const value = (getRadioValue('setting_active_tab_option') || 'account') as PageOptionParam['tab']
dic = { ...dic, tab: value }
}
if (curPage === PageType.nft_collection) {
dic = { ...dic, collection: '65e04d9b65fca97f09ff8f42' }
}
// debugger

if (isChecked('hide_wallet_entrance')) {
dic = { ...dic, hide_wallet_entrance: true }
}
if (isChecked('hide_account_entrance')) {
dic = { ...dic, hide_account_entrance: true }
}
if (isChecked('hide_menu_entrance')) {
dic = { ...dic, hide_menu_entrance: true }
}
if (isChecked('hide_sign_out')) {
dic = { ...dic, hide_sign_out: true }
}
if (isChecked('hide_footer')) {
dic = { ...dic, hide_footer: true }
}
if (isChecked('disable_logo_click')) {
dic = { ...dic, disable_logo_click: true }
}
if (isChecked('hide_game_select') && curPage === PageType.asset) {
dic = { ...dic, hide_game_select: true }
}
if (isChecked('hide_game_tokens') && curPage === PageType.asset) {
dic = { ...dic, hide_game_tokens: true }
}
if (isChecked('hide_game_filter') && curPage === PageType.nft_market) {
dic = { ...dic, hide_game_filter: true }
}

console.log('dic=', dic)
return dic
}
const getOtac = async () => {
const _otac = await XterioAuth.getOtac()
console.log('_otac=', _otac)
alert(_otac)
}
const getIdToken = async () => {
const _idToken = await XterioAuth.getIdToken()
console.log('_idToken=', _idToken)
alert(_idToken)
}

return (
<>
Expand All @@ -76,13 +146,97 @@ function App() {
<button onClick={() => login(LoginType.Email)}>邮箱登录</button>
<button onClick={() => login(LoginType.Mini)}>TG 登录</button>
<button onClick={logout}>退出登录</button>
<button onClick={getIdToken}>IdToken</button>
<button onClick={getOtac}>OTAC</button>
</div>
<div className="card">
<p>当前要打开的页面: {currentPage}</p>
<button onClick={() => setCurrentPage(PageType.asset)}>资产页</button>
<button onClick={() => setCurrentPage(PageType.account)}>账户页</button>
<button onClick={() => setCurrentPage(PageType.wallet)}>钱包页</button>
<button onClick={() => setCurrentPage(PageType.nft)}>nft页</button>
<button onClick={() => setCurrentPage(PageType.setting)}>账户钱包管理页</button>
<button onClick={() => setCurrentPage(PageType.nft_market)}>nft市场页</button>
<button onClick={() => setCurrentPage(PageType.nft_collection)}>nft落地页</button>
</div>
<div className="card">
<p>全局控制参数:</p>
<div className="list">
<div className="hide_wallet_entrance">
<input type="checkbox" />
<span>隐藏钱包入口</span>
</div>
<div className="hide_account_entrance">
<input type="checkbox" />
<span>隐藏账号入口</span>
</div>
<div className="hide_menu_entrance">
<input type="checkbox" />
<span>隐藏顶部导航栏(仅H5生效)</span>
</div>
<div className="hide_sign_out">
<input type="checkbox" />
<span>隐藏登出按钮</span>
</div>
<div className="hide_footer">
<input type="checkbox" />
<span>隐藏页脚</span>
</div>
<div className="disable_logo_click">
<input type="checkbox" />
<span>禁用左上角logo点击跳转首页</span>
</div>
</div>
</div>
<div className="card">
<p>页面独有参数:</p>
{currentPage === PageType.asset && (
<div className="config-asset row justify-center">
<div>定位到对应nft tab :</div>
<div>
<input type="radio" name="asset_active_tab_option" value="ingame" />
<label>ingame</label>
<input type="radio" name="asset_active_tab_option" value="onchain" />
<label>onchain</label>
</div>
</div>
)}
{currentPage === PageType.asset && (
<div className="config-asset hide_game_select">
<input type="checkbox" />
<span>隐藏游戏选择(资产页)</span>
</div>
)}
{currentPage === PageType.asset && (
<div className="config-asset hide_game_tokens">
<input type="checkbox" />
<span>隐藏token部分(资产页)</span>
</div>
)}
{currentPage === PageType.nft_market && (
<div className="config-nft-market hide_game_filter nft">
<input type="checkbox" />
<span>隐藏游戏filter(nft市场页)</span>
</div>
)}
{currentPage === PageType.setting && (
<div className="config-setting row justify-center">
<div>定位到对应tab页 :</div>
<div>
<input type="radio" name="setting_active_tab_option" value="profile" />
<label>profile</label>
<input type="radio" name="setting_active_tab_option" value="account" />
<label>account</label>
<input type="radio" name="setting_active_tab_option" value="wallet" />
<label>wallet</label>
<input type="radio" name="setting_active_tab_option" value="security" />
<label>security</label>
</div>
</div>
)}
{currentPage === PageType.nft_market && (
<div className="config-nft-market">tip: keyword & features 参考文档</div>
)}
{currentPage === PageType.nft_collection && (
<div className="config-nft-collection">tip: features 参考文档,collection必传(示例为写死的值)</div>
)}
</div>
<div className="card">
<p>打开页面的方式如下:</p>
Expand Down
Loading

0 comments on commit 7ae3d69

Please sign in to comment.