[React Native SDK] init package (#522)

Co-authored-by: iketw <[email protected]>
Co-authored-by: ciaranightingale <[email protected]>
Co-authored-by: Jonas Daniels <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Nacho Iacovino <[email protected]>
This commit is contained in:
iketw
2023-02-16 20:04:07 -05:00
committed by GitHub
co-authored by iketw ciaranightingale Jonas Daniels github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> github-actions[bot] <github-actions[bot]@users.noreply.github.com> Nacho Iacovino
parent 18c16101dd
commit 18ba6b381e
33 changed files with 4681 additions and 79 deletions
+7
View File
@@ -0,0 +1,7 @@
---
"@thirdweb-dev/react-native": minor
"@thirdweb-dev/react-native-compat": minor
"@thirdweb-dev/tsconfig": patch
---
[React Native SDK] init package
@@ -0,0 +1,3 @@
*.pbxproj -text
# specific for windows script files
*.bat text eol=crlf
+70
View File
@@ -0,0 +1,70 @@
# OSX
#
.DS_Store
# XDE
.expo/
# VSCode
.vscode/
jsconfig.json
# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
project.xcworkspace
# Android/IJ
#
.classpath
.cxx
.gradle
.idea
.project
.settings
local.properties
android.iml
# Cocoapods
#
example/ios/Pods
# Ruby
example/vendor/
# node.js
#
node_modules/
npm-debug.log
yarn-debug.log
yarn-error.log
# BUCK
buck-out/
\.buckd/
android/app/libs
android/keystores/debug.keystore
# Expo
.expo/
# Turborepo
.turbo/
# generated by bob
lib/
@@ -0,0 +1 @@
{}
+201
View File
@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2021 Non-Fungible Labs, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
+3
View File
@@ -0,0 +1,3 @@
# @thirdweb-dev/react-native-compat
Shims for Thirdweb in React Native Projects
@@ -0,0 +1,3 @@
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
};
+40
View File
@@ -0,0 +1,40 @@
{
"name": "@thirdweb-dev/react-native-compat",
"description": "Shims for Thirdweb in React Native Projects",
"version": "0.0.0",
"author": "thirdweb eng <[email protected]>",
"repository": "https://github.com/thirdweb-dev/js",
"license": "Apache-2.0",
"main": "dist/index.js",
"files": [
"dist/*"
],
"keywords": [
"thirdweb",
"dapp",
"react",
"react-native"
],
"scripts": {
"prettier": "prettier --check './**/*.{js,ts,jsx,tsx}'",
"build": "tsc",
"push": "yalc push"
},
"dependencies": {
"@ethersproject/shims": "^5.7.0",
"@walletconnect/react-native-compat": "^2.3.3",
"events": "3.3.0",
"react-native-get-random-values": "^1.8.0",
"base-64": "^1.0.0",
"big-integer": "^1.6.51"
},
"peerDependencies": {
"ethers": ">=5.5.1",
"react": ">=18.0.0",
"react-native": ">=0.70.0",
"wagmi": ">=0.7.0"
},
"devDependencies": {
"babel-plugin-module-resolver": "^5.0.0"
}
}
@@ -0,0 +1 @@
import './shims';
+12
View File
@@ -0,0 +1,12 @@
import 'react-native-get-random-values';
import '@ethersproject/shims';
import '@walletconnect/react-native-compat';
if (typeof BigInt === 'undefined') {
global.BigInt = require('big-integer');
}
if (typeof Buffer === 'undefined') {
global.Buffer = require('buffer').Buffer;
}
global.btoa = global.btoa || require('base-64').encode;
global.atob = global.atob || require('base-64').decode;
@@ -0,0 +1,11 @@
{
"extends": "@thirdweb-dev/tsconfig/react-native-library.json",
"compilerOptions": {
"outDir": "./dist",
"baseUrl": "./src",
"rootDir": "./src"
},
"typeRoots": ["../node_modules/@types"],
"include": ["./src/**/*.ts", "./src/**/*.tsx"],
"exclude": ["node_modules", "**/*.test.ts", "**/*.test.tsx"]
}
+5
View File
@@ -0,0 +1,5 @@
{
"presets": [
"module:metro-react-native-babel-preset"
]
}
+5
View File
@@ -0,0 +1,5 @@
# folders
dist/
node_modules/
# files
+4
View File
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: ["thirdweb"],
};
+13
View File
@@ -0,0 +1,13 @@
# XDE
.expo/
# VSCode
.vscode/
jsconfig.json
# node.js
#
node_modules/
npm-debug.log
yarn-debug.log
yarn-error.log
+1
View File
@@ -0,0 +1 @@
{}
+201
View File
@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2021 Non-Fungible Labs, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
+22
View File
@@ -0,0 +1,22 @@
<p align="center">
<br />
<a href="https://thirdweb.com"><img src="https://github.com/thirdweb-dev/js/blob/main/packages/sdk/logo.svg?raw=true" width="200" alt=""/></a>
<br />
</p>
<h1 align="center">thirdweb React Native SDK</h1>
<p align="center">
<a href="https://www.npmjs.com/package/@thirdweb-dev/react-native"><img src="https://img.shields.io/npm/v/@thirdweb-dev/react?color=red&label=npm&logo=npm" alt="npm version"/></a>
<a href="https://github.com/thirdweb-dev/js/actions/workflows/CI.yml"><img alt="Build Status" src="https://github.com/thirdweb-dev/js/actions/workflows/CI.yml/badge.svg"/></a>
<a href="https://discord.gg/thirdweb"><img alt="Join our Discord!" src="https://img.shields.io/discord/834227967404146718.svg?color=7289da&label=discord&logo=discord&style=flat"/></a>
</p>
<p align="center"><strong>Powering react-native dapps.</strong></p>
<br />
## 👷🚧 Alpha 🚧👷
<br />
## Getting Started
Head over to the [documentation](https://portal.thirdweb.com/react-native) to learn more
+68
View File
@@ -0,0 +1,68 @@
{
"name": "@thirdweb-dev/react-native",
"version": "0.0.0",
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/react-native",
"author": "thirdweb eng <[email protected]>",
"license": "Apache-2.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"sideEffects": false,
"files": [
"dist/*"
],
"scripts": {
"typecheck": "tsc --noEmit",
"lint": "eslint \"**/*.{js,ts,tsx}\"",
"fix": "eslint src/ --fix",
"clean": "rm -rf dist/",
"build": "tsc",
"push": "yalc push"
},
"keywords": [
"react-native",
"ios",
"android"
],
"dependencies": {
"@tanstack/react-query": "^4.0.10",
"@thirdweb-dev/chains": "*",
"@thirdweb-dev/react-core": "*",
"@thirdweb-dev/sdk": "*",
"@thirdweb-dev/storage": "*",
"tiny-invariant": "^1.2.0",
"wagmi": "^0.11.0"
},
"sideEffects:": false,
"devDependencies": {
"@babel/core": "^7.12.9",
"@react-native-community/eslint-config": "^3.0.2",
"@types/jest": "^29.2.1",
"@types/react": "^18.0.24",
"@types/react-native": "^0.71.0",
"@types/react-test-renderer": "^18.0.0",
"@typescript-eslint/eslint-plugin": "^5.33.0",
"@typescript-eslint/parser": "^5.33.0",
"babel-jest": "^29.2.1",
"eslint": "^8.32.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-inclusive-language": "^2.2.0",
"eslint-plugin-prettier": "^4.2.1",
"jest": "^29.2.1",
"prettier": "^2.4.1",
"react": "^18.2.0",
"react-native": "^0.71.0",
"react-native-test-app": "^2.3.1",
"react-test-renderer": "^18.2.0",
"typescript": "^4.8.4"
},
"peerDependencies": {
"@react-native-async-storage/async-storage": "*",
"ethers": ">=5.5.1 <6",
"react": ">=18.0.0",
"react-native": ">=0.70.0"
},
"engines": {
"node": ">= 16.0.0"
}
}
+17
View File
@@ -0,0 +1,17 @@
const warnSet = new Set<`${string}:${string}`>();
export function showDeprecationWarning(
deprecated: string,
replacement: string,
) {
// deprecation warnings only in dev only in dev
if (__DEV__) {
if (warnSet.has(`${deprecated}:${replacement}`)) {
return;
}
warnSet.add(`${deprecated}:${replacement}`);
console.warn(
`\`${deprecated}\` is deprecated and will be removed in a future major version. Please use \`${replacement}\` instead.`,
);
}
}
@@ -0,0 +1,2 @@
export const TW_WC_PROJECT_ID = '145769e410f16970a79ff77b2d89a1e0'
export const WC_RELAY_URL = 'wss://relay.walletconnect.com'
@@ -0,0 +1,113 @@
import { useEffect, useState } from "react";
import invariant from "tiny-invariant";
import { useClient, useConnect, useDisconnect } from "wagmi";
import { WalletConnectConnector } from "wagmi/dist/connectors/walletConnect";
import { Linking } from "react-native";
import UniversalProvider from "@walletconnect/universal-provider/dist/types/UniversalProvider";
/**
* Hook for connecting to a mobile wallet with Wallet Connect
*
* ```javascript
* import { useWalletConnect } from "@thirdweb-dev/react-native"
* ```
*
*
* @example
* We can allows user to connect their mobile wallets as follows:
* ```javascript
* import { useWalletConnect } from "@thirdweb-dev/react-native"
*
* const App = () => {
* const {connect} = useWalletConnect()
*
* return (
* <Button onClick={connect} title={'Connect Wallet'} />
* )
* }
* ```
*
* Android: `connect` will trigger a modal with a list of available wallets to connect to on their device.
* iOS: `connect` will try to open the first app available to handle `wc://` links on the device.
*
* @public
*/
export function useWalletConnect() {
const client = useClient();
invariant(
client,
`useWalletConnect() can only be used inside <ThirdwebProvider />. If you are using <ThirdwebSDKProvider /> you will have to use your own wallet-connection logic.`,
);
const [displayUri, setDisplayUri] = useState<string | undefined>();
const [connectError, setConnectError] = useState<Error | null>();
const { connect, connectors, error: wagmiConnectError, isLoading, isSuccess } =
useConnect();
const walletConnector = connectors.find(
(c) => c.id === "walletConnect",
) as WalletConnectConnector;
invariant(
walletConnector,
"WalletConnectConnector not found, please make sure it is provided to your <ThirdwebProvider />",
);
const { disconnect } = useDisconnect();
useEffect(() => {
setConnectError(wagmiConnectError);
}, [wagmiConnectError]);
useEffect(() => {
// wagmi storage doesn't support async storage on mobile so we need to manually connect
// https://github.com/wagmi-dev/wagmi/discussions/1630
const getProvider = async () => {
const provider = await walletConnector.getProvider();
const univProvider = provider as unknown as UniversalProvider;
// waiting on wagmi to update to latest universal provider (tag 2.4.2)
// univProvider.client.on('session_request_sent', ({ topic, request, chainId }) => {
// // redirect to wallet
// Linking.openURL(displayUri);
// });
if (univProvider.client.session.length > 0) {
// wc client does not report a successful initialization
// so we need to wait for it to initialize before connecting
setTimeout(() => {
connect({ connector: walletConnector });
}, 100);
}
}
getProvider();
// eslint-disable-next-line react-hooks/exhaustive-deps -- we only want to run this once
}, [])
useEffect(() => {
walletConnector.addListener('message', async ({ type, data }) => {
switch (type) {
case 'display_uri':
invariant(typeof data === 'string', 'display_uri message data must be a string')
// store first part of the uri to trigger wallet connect
setDisplayUri(data);
Linking.openURL(data);
break;
}
})
walletConnector.addListener('connect', () => {
console.log('walletConnector connect')
});
walletConnector.addListener('disconnect', () => {
// we need to disconnect wagmi when the connector disconnects
disconnect();
})
return () => {
walletConnector.removeAllListeners();
}
}, [disconnect, walletConnector]);
return { connector: walletConnector, connect: () => { connect({ connector: walletConnector }) }, isLoading: isLoading, isSuccess: isSuccess, connectError, displayUri }
}
@@ -0,0 +1,17 @@
import invariant from "tiny-invariant";
import {
useAccount as useWagmiAccount,
useClient
} from "wagmi";
/**
* @internal
*/
export function useAccount() {
const wagmiContext = useClient();
invariant(
wagmiContext,
`useAccount() can only be used inside <ThirdwebProvider />. If you are using <ThirdwebSDKProvider /> you will have to use your own account logic.`,
);
return useWagmiAccount();
}
@@ -0,0 +1,46 @@
import { useCallback } from "react";
import invariant from "tiny-invariant";
import { useClient, useDisconnect as useWagmiDisconnect } from "wagmi";
/**
* Hook for disconnecting the currently connected wallet
*
* ```javascript
* import { useDisconnect } from "@thirdweb-dev/react"
* ```
*
*
* @example
* The following will enable users to disconnect their wallet from the page.
* ```javascript
* import { useDisconnect } from "@thirdweb-dev/react-native"
*
* const App = () => {
* const disconnect = useDisconnect()
*
* return (
* <Button onClick={disconnect} title={'Disconnect'} />
* )
* }
* ```
*
* Once users disconnect their wallet, the `useAddress`, `useChainId`, `useAccount`, and `useNetwork` hooks will no longer return values until a user connects their wallet again.
*
* @public
*/
export function useDisconnect() {
const wagmiClient = useClient();
invariant(
wagmiClient,
`useDisconnect() can only be used inside <ThirdwebProvider />. If you are using <ThirdwebSDKProvider /> you will have to use your own connection logic.`,
);
const { disconnect } = useWagmiDisconnect();
const disconnectInternal = useCallback(() => {
disconnect();
wagmiClient.queryClient.clear();
}, [disconnect, wagmiClient.queryClient]);
return disconnectInternal;
}
@@ -0,0 +1,38 @@
import invariant from "tiny-invariant";
import {
useNetwork as useWagmiNetwork,
useClient
} from "wagmi";
/**
* Hook for getting metadata about the network the current wallet is connected to and switching networks
*
* @example
* ```javascript
* import { useNetwork, ChainId } from "@thirdweb-dev/react";
*
* const App = () => {
* const [, switchNetwork] = useNetwork();
*
* return (
* <button onClick={() => switchNetwork(ChainId.Polygon)}>
* Switch Network
* </button>
* );
* };
```
*
* It's important to note that some wallet apps do not support programmatic network switching and switchNetwork will be undefined.
* For those situations, you can typically switch networks in the wallet app this hook will still work.
*
* @public
*/
export function useNetwork() {
const wagmiContext = useClient();
invariant(
wagmiContext,
`useNetwork() can only be used inside <ThirdwebProvider />. If you are using <ThirdwebSDKProvider /> you will have to use your own network logic.`,
);
return useWagmiNetwork();
}
+11
View File
@@ -0,0 +1,11 @@
// providers
export * from "./providers/full";
// require to be inside `<ThirdwebProvider />`
export * from "./hooks/wagmi-required/useAccount";
export * from "./hooks/wagmi-required/useNetwork";
export * from "./hooks/connectors/useWalletConnect";
export * from "./hooks/wagmi-required/useDisconnect";
// re-export everything from react-core
export * from "@thirdweb-dev/react-core/evm";
@@ -0,0 +1,303 @@
import { QueryClient } from "@tanstack/react-query";
import { Chain, defaultChains } from "@thirdweb-dev/chains";
import {
ThirdwebAuthConfig,
ThirdwebConfigProvider,
ThirdwebSDKProvider,
ThirdwebSDKProviderProps,
} from "@thirdweb-dev/react-core/evm";
import type { SDKOptions } from "@thirdweb-dev/sdk";
import type { ThirdwebStorage } from "@thirdweb-dev/storage";
import { getDefaultProvider } from "ethers";
import { transformChainToMinimalWagmiChain } from "../utils/chains";
import React, { useMemo } from "react";
import invariant from "tiny-invariant";
import {
Connector, createClient, useSigner, WagmiConfig,
} from "wagmi";
import { WalletConnectConnector } from "wagmi/connectors/walletConnect";
import { TW_WC_PROJECT_ID, WC_RELAY_URL } from "../constants/walletConnect";
import { showDeprecationWarning } from "../../core/utils";
/**
* @internal
*/
export type WalletConnectConnectorType =
| WalletConnectConnector
| 'walletConnect'
| { name: 'walletConnect'; options: Omit<WalletConnectConnector['options'], 'version' | 'qrcode' | 'metadata'> };
/**
* @internal
*/
export type WalletConnector = WalletConnectConnectorType;
/**
* the metadata to pass to wallet connection dialog (may show up during the wallet-connection process)
* @remarks this is only used for wallet connect and wallet link, metamask does not support it
* @public
*/
export interface DAppMetaData {
/**
* the name of your app
*/
name: string;
/**
* optional - a description of your app
*/
description: string;
/**
* optional - a url that points to a logo (or favicon) of your app
*/
logoUrl: string;
/**
* optional - the url where your app is hosted
*/
url: string;
/**
* optional - whether to show the connect dialog in darkmode or not
*/
isDarkMode?: boolean;
}
/**
* The possible props for the ThirdwebProvider.
*/
export interface ThirdwebProviderProps<
TChains extends Chain[] = typeof defaultChains,
> {
/**
* The network to use for the SDK.
*/
activeChain?: TChains[number]["chainId"] | TChains[number]["slug"] | Chain;
/**
* Chains to support. If not provided, will default to the chains supported by the SDK.
*/
supportedChains?: Readonly<TChains>;
/**
* The {@link SDKOptions | Thirdweb SDK Options} to pass to the thirdweb SDK
* comes with sensible defaults
*/
sdkOptions?: SDKOptions;
/**
* An array of connector types (strings) or wallet connector objects that the dApp supports
* If not provided, will default to metamask (injected), wallet connect and walletlink (coinbase wallet) with sensible defaults
*/
walletConnectors?: WalletConnector[];
/**
* Metadata to pass to wallet connect and walletlink wallet connect. (Used to show *which* dApp is being connected to in mobile wallets that support it)
* Defaults to just the name being passed as `thirdweb powered dApp`.
*/
dAppMeta?: DAppMetaData;
/**
* The configuration used for thirdweb auth usage. Enables users to login
* to backends with their wallet.
*/
authConfig?: ThirdwebAuthConfig;
/**
* The storage interface to use with the sdk.
*/
storageInterface?: ThirdwebStorage;
/**
* The react-query client to use. (Defaults to a default client.)
*/
queryClient?: QueryClient;
/**
* The chainId that your dApp is running on.
* @deprecated - use `network` instead
*/
desiredChainId?: number | undefined;
/**
* A partial map of chainIds to rpc urls to use for certain chains
* If not provided, will default to the rpcUrls of the chain objects for the supported chains
* @deprecated - use `chains` instead
*/
chainRpc?: Record<number, string>;
}
// SDK handles this under the hood for us
const defaultdAppMeta: DAppMetaData = {
name: 'thirdweb powered dApp',
url: 'https://thirdweb.com',
logoUrl: 'https://thirdweb.com/favicon.ico',
description: 'thirdweb powered dApp',
};
const defaultWalletConnectors: Required<
ThirdwebProviderProps['walletConnectors']
> = ['walletConnect'];
/**
*
* The `<ThirdwebProvider />` component lets you control what networks you want users to connect to, what types of wallets can connect to your app, and the settings for the [Typescript SDK](https://docs.thirdweb.com/typescript).
*
* @example
* You can wrap your application with the provider as follows:
*
* ```jsx title="App.jsx"
* import { ThirdwebProvider, ChainId } from "@thirdweb-dev/react";
*
* const App = () => {
* return (
* <ThirdwebProvider desiredChainId={ChainId.Mainnet}>
* <YourApp />
* </ThirdwebProvider>
* );
* };
* ```
*
* @public
*
*/
export const ThirdwebProvider = <
TChains extends Chain[] = typeof defaultChains,
>({
sdkOptions,
// @ts-expect-error - different subtype of Chain[] but this works fine
supportedChains = defaultChains,
activeChain,
walletConnectors = defaultWalletConnectors,
dAppMeta = defaultdAppMeta,
authConfig,
storageInterface,
queryClient,
children,
// deprecated
desiredChainId,
chainRpc,
}: React.PropsWithChildren<ThirdwebProviderProps<TChains>>) => {
if (chainRpc) {
showDeprecationWarning("chainRpc", "supportedChains");
}
if (desiredChainId) {
showDeprecationWarning("desiredChainId", "activeChain");
}
const mergedChains = useMemo(() => {
if (
!activeChain ||
typeof activeChain === "string" ||
typeof activeChain === "number"
) {
return supportedChains as Readonly<Chain[]>;
}
return [...supportedChains, activeChain] as Readonly<Chain[]>;
}, [supportedChains, activeChain]);
const _client = useMemo(() => {
const walletConnectClientMeta = {
name: dAppMeta.name,
url: dAppMeta.url,
icons: [dAppMeta.logoUrl],
description: dAppMeta.description,
};
const wagmiChains = mergedChains.map(transformChainToMinimalWagmiChain);
const client = createClient({
connectors: () => {
return walletConnectors
.map((connector) => {
if (connector instanceof Connector) {
return connector;
}
// wallet connect
if (
(typeof connector === 'string' &&
connector === 'walletConnect') ||
(typeof connector === 'object' &&
connector.name === 'walletConnect')
) {
const mainnet = wagmiChains.find((chain) => chain.id === 1);
invariant(mainnet, 'Mainnet chain not found');
return new WalletConnectConnector({
chains: [mainnet],
options: typeof connector === "string"
? {
metadata: walletConnectClientMeta,
qrcode: false,
version: '2',
projectId: TW_WC_PROJECT_ID,
relayUrl: WC_RELAY_URL,
logger: 'info',
}
: {
metadata: walletConnectClientMeta,
qrcode: false,
version: '2',
projectId: TW_WC_PROJECT_ID,
relayUrl: WC_RELAY_URL,
logger: 'info',
... connector.options
},
});
}
throw new Error(`Wallet connector not recognised: ${connector}`);
})
.filter((c) => c !== null);
},
provider: getDefaultProvider(),
});
return client;
}, [dAppMeta.description, dAppMeta.logoUrl, dAppMeta.name, dAppMeta.url, mergedChains, walletConnectors]);
const activeChainId = useMemo(() => {
if (!activeChain) {
return undefined;
}
if (typeof activeChain === "string" || typeof activeChain === "number") {
return activeChain;
}
return activeChain.chainId;
}, [activeChain]);
return (
<ThirdwebConfigProvider
value={{
chains: supportedChains,
}}
>
<WagmiConfig client={_client}>
<ThirdwebSDKProviderWagmiWrapper
queryClient={queryClient}
sdkOptions={sdkOptions}
supportedChains={supportedChains}
// desiredChainId is deprecated, we will remove it in the future but still need to pass it here for now
activeChain={activeChainId || desiredChainId}
storageInterface={storageInterface}
authConfig={authConfig}
>
{children}
</ThirdwebSDKProviderWagmiWrapper>
</WagmiConfig>
</ThirdwebConfigProvider>
);
};
const ThirdwebSDKProviderWagmiWrapper = <TChains extends Chain[]>({
children,
...props
}: React.PropsWithChildren<
Omit<ThirdwebSDKProviderProps<TChains>, "signer" | "provider">
>) => {
const {data} = useSigner();
return (
<ThirdwebSDKProvider signer={data || undefined} {...props}>
{children}
</ThirdwebSDKProvider>
);
};
@@ -0,0 +1,37 @@
import { Chain as WagmiChain } from "wagmi";
import { Chain } from "@thirdweb-dev/chains";
export function transformChainToMinimalWagmiChain(chain: Chain): WagmiChain {
return {
id: chain.chainId,
name: chain.name,
network: chain.slug,
nativeCurrency: {
name: chain.nativeCurrency.name,
symbol: chain.nativeCurrency.symbol,
decimals: chain.nativeCurrency.decimals as 18,
},
testnet: chain.testnet,
rpcUrls: {
default: {
http: chain.rpc as string[],
},
public: {
http: chain.rpc as string[],
},
},
blockExplorers: chain.explorers?.reduce((prev, explorer: {
name: string;
url: string;
standard: string;
}) => {
return {
...prev,
[explorer.name]: {
name: explorer.name,
url: explorer.url,
},
};
}, { default: { name: chain.explorers[0].name, url: chain.explorers[0].url } })
};
}
+1
View File
@@ -0,0 +1 @@
export * from "./evm";
+11
View File
@@ -0,0 +1,11 @@
{
"extends": "@thirdweb-dev/tsconfig/react-native-library.json",
"compilerOptions": {
"outDir": "./dist",
"baseUrl": "./src",
"rootDir": "./src"
},
"typeRoots": ["../node_modules/@types"],
"include": ["./src/**/*.ts", "./src/**/*.tsx"],
"exclude": ["node_modules", "**/*.test.ts", "**/*.test.tsx"]
}
@@ -0,0 +1,20 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "React Native Library",
"compilerOptions": {
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"isolatedModules": false,
"jsx": "react",
"lib": ["es6", "es2015", "es2016", "es2017", "es2018"],
"noUnusedParameters": true,
"declaration": true,
"noUnusedLocals": true,
"moduleResolution": "node",
"strict": true,
"target": "es5",
"skipLibCheck": true
}
}
+8
View File
@@ -36,6 +36,14 @@
"outputs": ["dist/**", "evm/**", "solana/**"],
"dependsOn": ["^build"]
},
"@thirdweb-dev/react-native#build": {
"outputs": ["dist/**"],
"dependsOn": ["^build"]
},
"@thirdweb-dev/react-native-compat#build": {
"outputs": ["src/**"],
"dependsOn": ["^build"]
},
"@thirdweb-dev/auth#build": {
"outputs": [
"dist/**",
+3386 -79
View File
File diff suppressed because it is too large Load Diff