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

NEO Unified dApi (NUDApi) #1

Open
MorganDream opened this issue Nov 8, 2019 · 7 comments
Open

NEO Unified dApi (NUDApi) #1

MorganDream opened this issue Nov 8, 2019 · 7 comments

Comments

@MorganDream
Copy link
Owner

MorganDream commented Nov 8, 2019

NEO Unified dApi (NUDApi)

Although neo now have a dApp Platform Provider Interface standard, A dApp that uses one dApi wallet cannot invoke another dApi wallet, which is not so convinient for dApp developers.

Purpose

Neo Unified dApi(NUDApi) is to enable dApp to use one unified interface to invoke all wallets that aggrees to the dApi standard.

  • PERFECT: As long as it's a dApi standard wallet, it can be invoked by NUDApi.
    • This is difficult because if all web plugin wallets injects into web same object, they will contradict with each other.
  • CONFIGURE: A dApi wallet need to add its configuration in this project to be involved.
    • This is what we should try to accomplish, currently O3, NEOLine and Teemo top level interfaces are not similar.
  • CODE-SPECIFIED: If top level interfaces are not similar, we need to specify the difference in code.

What need to be done

Now this project is CODE-SPECIFIED, but we should aim at CONFIGURE.
To accomplish that, we should unify top level interfaces and events.

  • dApi instance should be got by:
    ${PROVIDER}.NEO
  • Events
    ${PROVIDER}.NEO.EVENT.READY

Suggestions

Any suggestions would be welcomed.

@vincentOpenSource
Copy link

Is it better to add .neo in front of .event

@MorganDream
Copy link
Owner Author

@vincentOpenSource Changed, thanks.

@MorganDream
Copy link
Owner Author

MorganDream commented Nov 13, 2019

I tried to add event listeners.

case 'Teemo':
window.addEventListener(`Teemo.NEO.${event}`, callback as any);

@vincentOpenSource Teemo better have native event listeners, too.

@MorganDream
Copy link
Owner Author

MorganDream commented Nov 21, 2019

根据以下原则各个钱包进行统一修改:

  • dApi instance should be got by:
    • ${PROVIDER}.NEO
  • Events
    • ${PROVIDER}.NEO.EVENT.READY

O3:

  • 增加NEO dapi实例接口: neoDapi.NEO
  • 事件由neoDapi.Constants.EventName.READY改变为neoDapi.NEO.EVENT.READY

NEOLine:

  • 增加NEO dapi实例接口: NEOLine.NEO
  • 事件由 NEOLine.EVENT.READY改为NEOLine.NEO.EVENT.READY

Teemo:

  • 对api实例Teemo.NEO增加监听和去监听事件方法
  • 事件名称常量化: Teemo.NEO.EVENT.READY

为了尽量保持钱包dApi的兼容性,保证已经使用各个钱包的Dapp的正常运行,原来的接口尽量保留,改动以增加接口的形式来做。

@hactrox
Copy link

hactrox commented Nov 21, 2019

We will make the corresponding changes.
CC:
@hkhv
@haiwulei

@vincentOpenSource
Copy link

Teemo的DAPI是通过chrome注入来实现的,在页面未注入完成DAPI的时候是无法调用Teemo.NEO 下的方法的,否则会报错。所以基于Teemo开发的DAPP 通常做法,是使用window原生的addEventListener方法监听Teemo.NEO.EVENT.READY 事件。当 READY之后再去调用Teemo相关DAPI 。所以最好还是使用原生window.addEventListener。或者单独对 READY做window.addEventListener,其他的 event 提供addEventListener,removeEventListener 方法

@MorganDream
Copy link
Owner Author

MorganDream commented Dec 16, 2019

@vincentOpenSource
明白了你的问题。这应该是浏览器插件钱包的共性问题。

所以最好还是使用原生window.addEventListener。或者单独对 READY做window.addEventListener,其他的 event 提供addEventListener,removeEventListener 方法

我觉得后者的处理方法更好。NEOLine目前也是这么做的。
READY时间确实不得不由window来监听。

补充:更好的解决方案可能是将add/removeEventListener定义成静态方法。
同时方法常量也定义为静态。这样就不用担心注入等待的问题了。
${PROVIDER}.addEventListender(${PROVIDER}.EVENTS.READY, () => {})

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

No branches or pull requests

3 participants