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 Intl and Blockie errors #31

Open
wants to merge 7 commits into
base: boilerplate-reactnative-cli-version
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MIT License

Copyright (c) 2021 Moralis Web3 Technology AB, 559307-5988

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
116 changes: 116 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

> React Native components and hooks for fast building dApps without running own backend

[![Discord](https://img.shields.io/badge/discord-join%20chat-blue.svg?style=for-the-badge&logo=discord)](https://discord.com/invite/wV7nkDYGyZ)
[![Discourse topics](https://img.shields.io/discourse/topics?label=Forum%20Support&logo=Moralis&server=https%3A%2F%2Fforum.moralis.io&style=for-the-badge)](https://forum.moralis.io/t/ethereum-react-native-boilerplate-questions/4511)
[![GitHub last commit](https://img.shields.io/github/last-commit/ethereum-boilerplate/ethereum-react-native-boilerplate?color=informational&style=for-the-badge)](https://github.com/ethereum-boilerplate/ethereum-react-native-boilerplate/commits/main)



![GitHub Repo stars](https://img.shields.io/github/stars/ethereum-boilerplate/ethereum-react-native-boilerplate?style=social)
[![Twitter URL](https://img.shields.io/twitter/url?style=social&url=https%3A%2F%2Ftwitter.com%2FMoralisWeb3)](https://twitter.com/MoralisWeb3)

This project is using:

- [create-react-native-dapp](https://github.com/cawfree/create-react-native-dapp) to bootstrap the project.
Expand Down Expand Up @@ -89,12 +98,14 @@ yarn install
- [`<Blockie />`](#blockie-)
- [🧰 Ethereum Hooks](#-ethereum-hooks)
- [`useERC20balance()`](#useerc20balance)
- [`useNativeBalance()`](#usenativebalance)
- [`useERC20Transfers()`](#useerc20transfers)
- [`useNativeTransactions()`](#usenativetransactions)
- [`useTokenPrice()`](#usetokenprice)
- [`useNFTTransfers()`](#usenfttransfers)
- [`useNFTBalance()`](#usenftbalance)


# 🏗 Ethereum Components

🛠 The ready for use react-native-components are located in `frontend/Components`. They are designed to be used anywhere in your dApp.
Expand Down Expand Up @@ -162,6 +173,32 @@ Displays The user address that is copyable
const { fetchERC20Balance, assets } = useERC20Balance({ chain: "eth" });
```

### `useNativeBalance()`

💰 Gets native balance for a current user or specified address.

**Options**:
- `chain` (optional): The blockchain to get data from. Default value: current chain.

**Example**:
```jsx
import useNativeBalance from "./hooks/useNativeBalance";

function NativeBalance() {
const { nativeBalance } = useNativeBalance(chain);

return (
<View style={styles.itemView}>
<Text style={styles.name}> {nativeBalance} </Text>
</View>
);
}
```
**Example return of nativeBalance** (string)
```jsx
'0.1581 BNB'
```

### `useERC20Transfers()`

🧾 Gets ERC20 token transfers of a current user or specified address.
Expand Down Expand Up @@ -198,6 +235,85 @@ const { fetchERC20Balance, assets } = useERC20Balance({ chain: "eth" });

### `useTokenPrice()`

💰 Gets the price nominated in the native token and usd for a given token contract address

**Options**:
- `chain` (optional): The blockchain to get data from. Valid values are listed on the intro page in the Transactions and Balances section. Default value: current chain (if the chain is not supported it will use the Eth chain).
- `address` (optional): A user address (i.e. 0x1a2b3x...). If specified, the user attached to the query is ignored and the address will be used instead.
- `exchange` (optional): The factory name or address of the token exchange. Possible exchanges, for different chains are: ETH mainnet: `uniswap-v3`, `sushiswap`, `uniswap-v2`, BSC mainnet: `pancakeswap-v2`, `pancakeswap-v1`. Polygon mainnet: `quickswap`. *If no exchange is specified, all exchanges are checked (in the order as listed above) until a valid pool has been found. Note that this request can take more time. So specifying the exchange will result in faster responses most of the time.*
- `to_block` (optional): Returns the price for a given blocknumber (historical price-data).

**Example**
```jsx
import { useTokenPrice } from "./hooks/useTokenPrice";

const TokenPrice = () => {

const { tokenPrice } = useTokenPrice({chain, tokenAddress});

return (
<View>
<Text>{tokenPrice.usdPrice}</Text>
</View>
);
}
```

**Example return** (Object)
```json

{
"exchangeAddress": "0x5757371414417b8C6CAad45bAeF941aBc7d3Ab32",
"exchangeName": "Quickswap",
"nativePrice": "0.0003 MATIC",
"usdPrice": "$1.08"
}
```
```json
{
"exchangeAddress": "0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73",
"exchangeName": "PancakeSwap v2",
"nativePrice": "0.0005 BNB",
"usdPrice": "$0.28"
}
```

### `useNFTTransfers()`

### `useNFTBalance()`
🎨 Gets all NFTs from the current user or address. Supports both ERC721 and ERC1155. Returns an object with the number of NFT objects and the array of NFT objects.

**Options**:
- `chain` (optional): The blockchain to get data from. Valid values are listed on the intro page in the Transactions and Balances section. Default value: current chain (if the chain is not supported it will use the Eth chain).
- `address` (optional): A user address (i.e. 0x1a2b3x...). If specified, the user attached to the query is ignored and the address will be used instead.


**Example return** (Object)
```json


[{
"amount": "1",
"block_number": "9449788",
"block_number_minted": "9449091",
"contract_type": "ERC1155",
"frozen": 0,
"image": "https://nyc-feb-19-2020.s3.amazonaws.com/skin-slip-animation.gif",
"is_valid": 1,
"metadata":
{
"description": "On February 19th, we will introduce the future of b̶l̶o̶c̶k̶c̶h̶a̶i̶n̶ gaming. And you’ll see why Kitties were just the start.",
"external_url": "https://www.nycfeb192020.com/",
"image": "https://nyc-feb-19-2020.s3.amazonaws.com/skin-slip-animation.gif",
"name": "NYC Feb 19th 2020"
},
"name": "NYC February 19th 2020",
"owner_of": "0x71a11bc477048cca56d645ffc66ca762f62d1c3c",
"symbol": "NYCFEB192020",
"synced_at": "2021-12-06T19:02:12.378Z",
"syncing": 2,
"token_address": "0xd193a22224795c43d837a3f3d7394b4d0cc15f60",
"token_id": "1",
"token_uri": "https://nyc-feb-19-2020.s3.amazonaws.com/metadata.json"
}]
```
48 changes: 29 additions & 19 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,10 @@ import com.android.build.OutputFile
*/

project.ext.react = [
enableHermes: (findProperty('expo.jsEngine') ?: "jsc") == "hermes",
enableHermes: false, // clean and rebuild if changing
]

apply from: '../../node_modules/react-native-unimodules/gradle.groovy'
apply from: "../../node_modules/react-native/react.gradle"
apply from: "../../node_modules/expo-constants/scripts/get-app-config-android.gradle"
apply from: "../../node_modules/expo-updates/scripts/create-manifest-android.gradle"

/**
* Set this to true to create two separate APKs instead of one:
Expand All @@ -104,15 +101,15 @@ def enableProguardInReleaseBuilds = false
/**
* The preferred build flavor of JavaScriptCore.
*
* For example, to use the international variant, you can use:*/
def jscFlavor = 'org.webkit:android-jsc-intl:+'
/**
* For example, to use the international variant, you can use:
* `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
*
* The international variant includes ICU i18n library and necessary data
* allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
* give correct results when using with locales other than en-US. Note that
* this variant is about 6MiB larger per architecture than default.
*/
// def jscFlavor = 'org.webkit:android-jsc:+'
def jscFlavor = 'org.webkit:android-jsc-intl:+'

/**
* Whether to enable the Hermes VM.
Expand All @@ -123,20 +120,22 @@ def jscFlavor = 'org.webkit:android-jsc-intl:+'
*/
def enableHermes = project.ext.react.get("enableHermes", false);

/**
* Architectures to build native code for in debug.
*/
def nativeArchitectures = project.getProperties().get("reactNativeDebugArchitectures")

android {
compileSdkVersion rootProject.ext.compileSdkVersion
ndkVersion rootProject.ext.ndkVersion

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
compileSdkVersion rootProject.ext.compileSdkVersion

defaultConfig {
applicationId 'com.myreactdapp'
applicationId "com.ethereumrnboilerplate"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0.0"
versionName "1.0"
}
splits {
abi {
Expand All @@ -157,6 +156,11 @@ android {
buildTypes {
debug {
signingConfig signingConfigs.debug
if (nativeArchitectures) {
ndk {
abiFilters nativeArchitectures.split(',')
}
}
}
release {
// Caution! In production, you need to generate your own keystore file.
Expand All @@ -172,11 +176,12 @@ android {
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// https://developer.android.com/studio/build/configure-apk-splits.html
// Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc.
def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
defaultConfig.versionCode * 1000 + versionCodes.get(abi)
}

}
Expand All @@ -187,18 +192,23 @@ dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+" // From node_modules

implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"

implementation project(':react-native-webview')

debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
exclude group:'com.facebook.fbjni'
exclude group:'com.facebook.fbjni'
}

debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
exclude group:'com.facebook.flipper'
exclude group:'com.squareup.okhttp3', module:'okhttp'
}

debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
exclude group:'com.facebook.flipper'
}
addUnimodulesDependencies()

if (enableHermes) {
def hermesPath = "../../node_modules/hermes-engine/android/";
Expand All @@ -212,7 +222,7 @@ dependencies {
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
from configurations.implementation
into 'libs'
}

Expand Down
Loading