First Version

This commit is contained in:
KoalaSat 2022-10-24 19:27:31 +02:00
commit 0bc073c81d
No known key found for this signature in database
GPG Key ID: 2F7F61C6146AB157
98 changed files with 12815 additions and 0 deletions

6
.buckconfig Normal file
View File

@ -0,0 +1,6 @@
[android]
target = Google Inc.:Google APIs:23
[maven_repositories]
central = https://repo1.maven.org/maven2

3
.editorconfig Normal file
View File

@ -0,0 +1,3 @@
# Windows files
[*.bat]
end_of_line = crlf

36
.eslintrc.js Normal file
View File

@ -0,0 +1,36 @@
module.exports = {
root: true,
extends: [
'eslint:recommended',
'plugin:react/recommended',
'standard-with-typescript',
'prettier',
],
parserOptions: {
ecmaVersion: 8,
ecmaFeatures: {
jsx: true,
},
sourceType: 'module',
project: './tsconfig.json',
},
plugins: ['react', 'react-hooks', '@typescript-eslint', 'prettier'],
rules: {
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'off',
'react/prop-types': 'off',
'react/react-in-jsx-scope': 'off',
'@typescript-eslint/strict-boolean-expressions': 'off',
'@typescript-eslint/no-dynamic-delete': 'off',
'@typescript-eslint/no-floating-promises': 'off',
'@typescript-eslint/no-misused-promises': 'off',
},
settings: {
'import/resolver': {
typescript: {},
},
react: {
version: 'detect',
},
},
};

3
.gitattributes vendored Normal file
View File

@ -0,0 +1,3 @@
# Windows files should use crlf line endings
# https://help.github.com/articles/dealing-with-line-endings/
*.bat text eol=crlf

59
.gitignore vendored Normal file
View File

@ -0,0 +1,59 @@
# OSX
#
.DS_Store
# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
# Android/IntelliJ
#
build/
.idea
.gradle
local.properties
*.iml
# node.js
#
node_modules/
npm-debug.log
yarn-error.log
# BUCK
buck-out/
\.buckd/
*.keystore
!debug.keystore
# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/
*/fastlane/report.xml
*/fastlane/Preview.html
*/fastlane/screenshots
# Bundle artifact
*.jsbundle
# CocoaPods
/ios/Pods/

1
.prettierignore Normal file
View File

@ -0,0 +1 @@
android/app/build/**

9
.prettierrc Normal file
View File

@ -0,0 +1,9 @@
{
"semi": true,
"tabWidth": 2,
"printWidth": 100,
"singleQuote": true,
"trailingComma": "all",
"jsxSingleQuote": true,
"bracketSpacing": true
}

7
.prettierrc.js Normal file
View File

@ -0,0 +1,7 @@
module.exports = {
bracketSpacing: false,
jsxBracketSameLine: true,
singleQuote: true,
trailingComma: 'all',
arrowParens: 'avoid',
};

1
.watchmanconfig Normal file
View File

@ -0,0 +1 @@
{}

6
App.tsx Normal file
View File

@ -0,0 +1,6 @@
import App from './frontend';
import { Buffer as SafeBuffer } from 'safe-buffer';
global.Buffer = SafeBuffer;
export default App;

55
android/app/_BUCK Normal file
View File

@ -0,0 +1,55 @@
# To learn about Buck see [Docs](https://buckbuild.com/).
# To run your application with Buck:
# - install Buck
# - `npm start` - to start the packager
# - `cd android`
# - `keytool -genkey -v -keystore keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"`
# - `./gradlew :app:copyDownloadableDepsToLibs` - make all Gradle compile dependencies available to Buck
# - `buck install -r android/app` - compile, install and run application
#
load(":build_defs.bzl", "create_aar_targets", "create_jar_targets")
lib_deps = []
create_aar_targets(glob(["libs/*.aar"]))
create_jar_targets(glob(["libs/*.jar"]))
android_library(
name = "all-libs",
exported_deps = lib_deps,
)
android_library(
name = "app-code",
srcs = glob([
"src/main/java/**/*.java",
]),
deps = [
":all-libs",
":build_config",
":res",
],
)
android_build_config(
name = "build_config",
package = "com.nostros",
)
android_resource(
name = "res",
package = "com.nostros",
res = "src/main/res",
)
android_binary(
name = "app",
keystore = "//android/keystores:debug",
manifest = "src/main/AndroidManifest.xml",
package_type = "debug",
deps = [
":app-code",
],
)

223
android/app/build.gradle Normal file
View File

@ -0,0 +1,223 @@
apply plugin: "com.android.application"
import com.android.build.OutputFile
/**
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
* and bundleReleaseJsAndAssets).
* These basically call `react-native bundle` with the correct arguments during the Android build
* cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
* bundle directly from the development server. Below you can see all the possible configurations
* and their defaults. If you decide to add a configuration block, make sure to add it before the
* `apply from: "../../node_modules/react-native/react.gradle"` line.
*
* project.ext.react = [
* // the name of the generated asset file containing your JS bundle
* bundleAssetName: "index.android.bundle",
*
* // the entry file for bundle generation. If none specified and
* // "index.android.js" exists, it will be used. Otherwise "index.js" is
* // default. Can be overridden with ENTRY_FILE environment variable.
* entryFile: "index.android.js",
*
* // https://reactnative.dev/docs/performance#enable-the-ram-format
* bundleCommand: "ram-bundle",
*
* // whether to bundle JS and assets in debug mode
* bundleInDebug: false,
*
* // whether to bundle JS and assets in release mode
* bundleInRelease: true,
*
* // whether to bundle JS and assets in another build variant (if configured).
* // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
* // The configuration property can be in the following formats
* // 'bundleIn${productFlavor}${buildType}'
* // 'bundleIn${buildType}'
* // bundleInFreeDebug: true,
* // bundleInPaidRelease: true,
* // bundleInBeta: true,
*
* // whether to disable dev mode in custom build variants (by default only disabled in release)
* // for example: to disable dev mode in the staging build type (if configured)
* devDisabledInStaging: true,
* // The configuration property can be in the following formats
* // 'devDisabledIn${productFlavor}${buildType}'
* // 'devDisabledIn${buildType}'
*
* // the root of your project, i.e. where "package.json" lives
* root: "../../",
*
* // where to put the JS bundle asset in debug mode
* jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
*
* // where to put the JS bundle asset in release mode
* jsBundleDirRelease: "$buildDir/intermediates/assets/release",
*
* // where to put drawable resources / React Native assets, e.g. the ones you use via
* // require('./image.png')), in debug mode
* resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
*
* // where to put drawable resources / React Native assets, e.g. the ones you use via
* // require('./image.png')), in release mode
* resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
*
* // by default the gradle tasks are skipped if none of the JS files or assets change; this means
* // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
* // date; if you have any other folders that you want to ignore for performance reasons (gradle
* // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
* // for example, you might want to remove it from here.
* inputExcludes: ["android/**", "ios/**"],
*
* // override which node gets called and with what additional arguments
* nodeExecutableAndArgs: ["node"],
*
* // supply additional arguments to the packager
* extraPackagerArgs: []
* ]
*/
project.ext.react = [
enableHermes: false, // clean and rebuild if changing
]
apply from: "../../node_modules/react-native/react.gradle"
apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"
/**
* Set this to true to create two separate APKs instead of one:
* - An APK that only works on ARM devices
* - An APK that only works on x86 devices
* The advantage is the size of the APK is reduced by about 4MB.
* Upload all the APKs to the Play Store and people will download
* the correct one based on the CPU architecture of their device.
*/
def enableSeparateBuildPerCPUArchitecture = false
/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
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:+'`
*
* 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:+'
/**
* Whether to enable the Hermes VM.
*
* This should be set on project.ext.react and mirrored here. If it is not set
* on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
* and the benefits of using Hermes will therefore be sharply reduced.
*/
def enableHermes = project.ext.react.get("enableHermes", false);
android {
ndkVersion rootProject.ext.ndkVersion
compileSdkVersion rootProject.ext.compileSdkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "com.nostros"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
}
}
signingConfigs {
debug {
storeFile file('debug.keystore')
storePassword 'android'
keyAlias 'androiddebugkey'
keyPassword 'android'
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
// Caution! In production, you need to generate your own keystore file.
// see https://reactnative.dev/docs/signed-apk-android.
signingConfig signingConfigs.debug
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
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 =
defaultConfig.versionCode * 1000 + versionCodes.get(abi)
}
}
}
}
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"
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
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'
}
if (enableHermes) {
def hermesPath = "../../node_modules/hermes-engine/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
implementation jscFlavor
}
}
// 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
into 'libs'
}
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

View File

@ -0,0 +1,19 @@
"""Helper definitions to glob .aar and .jar targets"""
def create_aar_targets(aarfiles):
for aarfile in aarfiles:
name = "aars__" + aarfile[aarfile.rindex("/") + 1:aarfile.rindex(".aar")]
lib_deps.append(":" + name)
android_prebuilt_aar(
name = name,
aar = aarfile,
)
def create_jar_targets(jarfiles):
for jarfile in jarfiles:
name = "jars__" + jarfile[jarfile.rindex("/") + 1:jarfile.rindex(".jar")]
lib_deps.append(":" + name)
prebuilt_jar(
name = name,
binary_jar = jarfile,
)

BIN
android/app/debug.keystore Normal file

Binary file not shown.

10
android/app/proguard-rules.pro vendored Normal file
View File

@ -0,0 +1,10 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<application
android:usesCleartextTraffic="true"
tools:targetApi="28"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
</manifest>

View File

@ -0,0 +1,72 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* <p>This source code is licensed under the MIT license found in the LICENSE file in the root
* directory of this source tree.
*/
package com.nostros;
import android.content.Context;
import com.facebook.flipper.android.AndroidFlipperClient;
import com.facebook.flipper.android.utils.FlipperUtils;
import com.facebook.flipper.core.FlipperClient;
import com.facebook.flipper.plugins.crashreporter.CrashReporterPlugin;
import com.facebook.flipper.plugins.databases.DatabasesFlipperPlugin;
import com.facebook.flipper.plugins.fresco.FrescoFlipperPlugin;
import com.facebook.flipper.plugins.inspector.DescriptorMapping;
import com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin;
import com.facebook.flipper.plugins.network.FlipperOkhttpInterceptor;
import com.facebook.flipper.plugins.network.NetworkFlipperPlugin;
import com.facebook.flipper.plugins.react.ReactFlipperPlugin;
import com.facebook.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPlugin;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.modules.network.NetworkingModule;
import okhttp3.OkHttpClient;
public class ReactNativeFlipper {
public static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) {
if (FlipperUtils.shouldEnableFlipper(context)) {
final FlipperClient client = AndroidFlipperClient.getInstance(context);
client.addPlugin(new InspectorFlipperPlugin(context, DescriptorMapping.withDefaults()));
client.addPlugin(new ReactFlipperPlugin());
client.addPlugin(new DatabasesFlipperPlugin(context));
client.addPlugin(new SharedPreferencesFlipperPlugin(context));
client.addPlugin(CrashReporterPlugin.getInstance());
NetworkFlipperPlugin networkFlipperPlugin = new NetworkFlipperPlugin();
NetworkingModule.setCustomClientBuilder(
new NetworkingModule.CustomClientBuilder() {
@Override
public void apply(OkHttpClient.Builder builder) {
builder.addNetworkInterceptor(new FlipperOkhttpInterceptor(networkFlipperPlugin));
}
});
client.addPlugin(networkFlipperPlugin);
client.start();
// Fresco Plugin needs to ensure that ImagePipelineFactory is initialized
// Hence we run if after all native modules have been initialized
ReactContext reactContext = reactInstanceManager.getCurrentReactContext();
if (reactContext == null) {
reactInstanceManager.addReactInstanceEventListener(
new ReactInstanceManager.ReactInstanceEventListener() {
@Override
public void onReactContextInitialized(ReactContext reactContext) {
reactInstanceManager.removeReactInstanceEventListener(this);
reactContext.runOnNativeModulesQueueThread(
new Runnable() {
@Override
public void run() {
client.addPlugin(new FrescoFlipperPlugin());
}
});
}
});
} else {
client.addPlugin(new FrescoFlipperPlugin());
}
}
}
}

View File

@ -0,0 +1,25 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.nostros">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@ -0,0 +1,15 @@
package com.nostros;
import com.facebook.react.ReactActivity;
public class MainActivity extends ReactActivity {
/**
* Returns the name of the main component registered from JavaScript. This is used to schedule
* rendering of the component.
*/
@Override
protected String getMainComponentName() {
return "nostros";
}
}

View File

@ -0,0 +1,80 @@
package com.nostros;
import android.app.Application;
import android.content.Context;
import com.facebook.react.PackageList;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.soloader.SoLoader;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
public class MainApplication extends Application implements ReactApplication {
private final ReactNativeHost mReactNativeHost =
new ReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
@SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> packages = new PackageList(this).getPackages();
// Packages that cannot be autolinked yet can be added manually here, for example:
// packages.add(new MyReactNativePackage());
return packages;
}
@Override
protected String getJSMainModuleName() {
return "index";
}
};
@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
@Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
}
/**
* Loads Flipper in React Native templates. Call this in the onCreate method with something like
* initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
*
* @param context
* @param reactInstanceManager
*/
private static void initializeFlipper(
Context context, ReactInstanceManager reactInstanceManager) {
if (BuildConfig.DEBUG) {
try {
/*
We use reflection here to pick up the class that initializes Flipper,
since Flipper library is not available in release mode
*/
Class<?> aClass = Class.forName("com.nostros.ReactNativeFlipper");
aClass
.getMethod("initializeFlipper", Context.class, ReactInstanceManager.class)
.invoke(null, context, reactInstanceManager);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@ -0,0 +1,3 @@
<resources>
<string name="app_name">nostros</string>
</resources>

View File

@ -0,0 +1,9 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:textColor">#000000</item>
</style>
</resources>

38
android/build.gradle Normal file
View File

@ -0,0 +1,38 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "29.0.3"
minSdkVersion = 21
compileSdkVersion = 29
targetSdkVersion = 29
ndkVersion = "20.1.5948944"
}
repositories {
google()
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle:4.1.0")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
google()
jcenter()
maven { url 'https://www.jitpack.io' }
}
}

28
android/gradle.properties Normal file
View File

@ -0,0 +1,28 @@
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app's APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
# Version of flipper SDK to use with React Native
FLIPPER_VERSION=0.75.1

Binary file not shown.

View File

@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

185
android/gradlew vendored Executable file
View File

@ -0,0 +1,185 @@
#!/usr/bin/env sh
#
# Copyright 2015 the original author or authors.
#
# 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
#
# https://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.
#
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=`expr $i + 1`
done
case $i in
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=`save "$@"`
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
exec "$JAVACMD" "$@"

89
android/gradlew.bat vendored Normal file
View File

@ -0,0 +1,89 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

3
android/settings.gradle Normal file
View File

@ -0,0 +1,3 @@
rootProject.name = 'nostros'
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':app'

4
app.json Normal file
View File

@ -0,0 +1,4 @@
{
"name": "nostros",
"displayName": "nostros"
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

3
babel.config.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
};

View File

@ -0,0 +1,81 @@
import {
Button,
Layout,
TopNavigation,
TopNavigationAction,
useTheme,
} from '@ui-kitten/components';
import React, { useContext } from 'react';
import { StyleSheet } from 'react-native';
import { AppContext } from '../../Contexts/AppContext';
import Icon from 'react-native-vector-icons/FontAwesome5';
import { useTranslation } from 'react-i18next';
import EncryptedStorage from 'react-native-encrypted-storage';
import { dropTables } from '../../Functions/DatabaseFunctions';
import { RelayPoolContext } from '../../Contexts/RelayPoolContext';
export const ConfigPage: React.FC = () => {
const theme = useTheme();
const { setPage, page, database } = useContext(AppContext);
const { setPrivateKey } = useContext(RelayPoolContext);
const { t } = useTranslation('common');
const breadcrump = page.split('%');
const onPressBack: () => void = () => {
setPage(breadcrump.slice(0, -1).join('%'));
};
const onPressLogout: () => void = () => {
setPrivateKey('')
EncryptedStorage.removeItem('privateKey');
if (database) {
dropTables(database).then(() => setPage('landing'))
}
};
const renderBackAction = (): JSX.Element => (
<TopNavigationAction
icon={<Icon name='arrow-left' size={16} color={theme['text-basic-color']} />}
onPress={onPressBack}
/>
);
const styles = StyleSheet.create({
container: {
flex: 1,
},
actionContainer: {
marginTop: 30,
paddingLeft: 32,
paddingRight: 32,
},
button: {
marginTop: 30,
},
});
return (
<>
<Layout style={styles.container} level='2'>
<TopNavigation
alignment='center'
title={t('configPage.title')}
accessoryLeft={renderBackAction}
/>
<Layout style={styles.actionContainer} level='2'>
<Layout style={styles.button}>
<Button
onPress={onPressLogout}
status='danger'
accessoryLeft={<Icon name='power-off' size={16} color={theme['text-basic-color']} solid />}
>
{t('configPage.logout')}
</Button>
</Layout>
</Layout>
</Layout>
</>
);
};
export default ConfigPage;

View File

@ -0,0 +1,131 @@
import { Button, Card, Input, Layout, List, Modal, useTheme } from '@ui-kitten/components';
import React, { useContext, useEffect, useState } from 'react';
import { StyleSheet } from 'react-native';
import ActionButton from 'react-native-action-button';
import { AppContext } from '../../Contexts/AppContext';
import Icon from 'react-native-vector-icons/FontAwesome5';
import { Event, EventKind } from '../../lib/nostr/Events';
import { useTranslation } from 'react-i18next';
import { addContact, getUsers, insertUserContact, User } from '../../Functions/DatabaseFunctions/Users';
import UserCard from '../UserCard';
import { RelayPoolContext } from '../../Contexts/RelayPoolContext';
import Relay from '../../lib/nostr/Relay';
import { populatePets } from '../../Functions/RelayFunctions/Users';
export const ContactsPage: React.FC = () => {
const { database } = useContext(AppContext);
const { relayPool, publicKey, lastEventId, setLastEventId } = useContext(RelayPoolContext);
const theme = useTheme();
const [users, setUsers] = useState<User[]>([]);
const [showAddContact, setShowAddContant] = useState<boolean>(false);
const [contactInput, setContactInput] = useState<string>();
const { t } = useTranslation('common');
useEffect(() => {
if (database) {
getUsers(database, { contacts: true }).then((results) => {
if (results) {
setUsers(results);
relayPool?.subscribe('main-channel', {
kinds: [EventKind.petNames],
authors: [publicKey],
});
}
});
}
}, [lastEventId]);
useEffect(() => {
relayPool?.on('event', 'contacts', (relay: Relay, _subId?: string, event?: Event) => {
console.log('RELAYPOOL EVENT =======>', relay.url, event);
if (database && event?.id && event.kind === EventKind.petNames) {
insertUserContact(event, database).finally(() => setLastEventId(event?.id ?? ''));
}
},
);
}, [])
const onPressAddContact: () => void = () => {
if (contactInput && relayPool && database) {
addContact(contactInput, database).then(() => {
populatePets(relayPool, database, publicKey)
setShowAddContant(false)
});
}
};
const styles = StyleSheet.create({
container: {
flex: 1,
},
actionContainer: {
marginTop: 30,
paddingLeft: 32,
paddingRight: 32,
},
button: {
marginTop: 30,
},
icon: {
width: 32,
height: 32,
},
modal: {
marginTop: -120,
paddingLeft: 32,
paddingRight: 32,
},
backdrop: {
backgroundColor: 'rgba(0, 0, 0, 0.5)',
},
});
return (
<>
<Layout style={styles.container} level='3'>
<List data={users} renderItem={(item) => <UserCard user={item.item} />} />
</Layout>
<Modal
style={styles.modal}
visible={showAddContact}
backdropStyle={styles.backdrop}
onBackdropPress={() => setShowAddContant(false)}
>
<Card disabled={true}>
<Layout style={styles.actionContainer}>
<Layout>
<Input
placeholder={t('contactsPage.addContact.placeholder')}
value={contactInput}
onChangeText={setContactInput}
size='large'
/>
</Layout>
<Layout style={styles.button}>
<Button onPress={onPressAddContact}>{t('contactsPage.addContact.add')}</Button>
</Layout>
</Layout>
</Card>
</Modal>
<ActionButton
buttonColor={theme['color-primary-400']}
useNativeFeedback={true}
fixNativeFeedbackRadius={true}
>
<ActionButton.Item
buttonColor={theme['color-warning-500']}
title={t('contactsPage.add')}
onPress={() => setShowAddContant(true)}
>
<Icon name='user-plus' size={30} color={theme['text-basic-color']} solid />
</ActionButton.Item>
</ActionButton>
</>
);
};
export default ContactsPage;
function setIsContact(arg0: boolean) {
throw new Error('Function not implemented.');
}

View File

@ -0,0 +1,114 @@
import { Card, Layout, List, useTheme } from '@ui-kitten/components';
import React, { useContext, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { StyleSheet } from 'react-native';
import { AppContext } from '../../Contexts/AppContext';
import { getNotes, Note } from '../../Functions/DatabaseFunctions/Notes';
import NoteCard from '../NoteCard';
import ActionButton from 'react-native-action-button';
import Icon from 'react-native-vector-icons/FontAwesome5';
import { RelayPoolContext } from '../../Contexts/RelayPoolContext';
import { EventKind } from '../../lib/nostr/Events';
import { RelayFilters } from '../../lib/nostr/Relay';
import { getReplyEventId } from '../../Functions/RelayFunctions/Events';
import { getUsers } from '../../Functions/DatabaseFunctions/Users';
export const HomePage: React.FC = () => {
const { database, setPage, page } = useContext(AppContext);
const { lastEventId, setLastEventId, relayPool, publicKey } = useContext(RelayPoolContext);
const theme = useTheme();
const [notes, setNotes] = useState<Note[]>([]);
const { t } = useTranslation('common');
const loadNotes: () => void = () => {
if (database) {
getNotes(database, { contacts: true }).then((notes) => {
setNotes(notes);
});
}
};
const subscribeNotes: () => void = () => {
if (database) {
getNotes(database, { limit: 1 }).then((notes) => {
getUsers(database, { contacts: true }).then((users) => {
let message: RelayFilters = {
kinds: [EventKind.textNote, EventKind.recommendServer],
authors: [publicKey, ...users.map((user) => user.id)],
limit: 20,
};
if (notes.length > 0) {
message = {
...message,
since: notes[0].created_at,
};
}
relayPool?.subscribe('main-channel', message);
});
});
}
};
useEffect(() => {
loadNotes()
}, [lastEventId]);
useEffect(() => {
loadNotes();
subscribeNotes();
}, []);
const onPress: (note: Note) => void = (note) => {
if (note.kind !== EventKind.recommendServer) {
const replyEventId = getReplyEventId(note);
if (replyEventId) {
setPage(`${page}%note#${replyEventId}`);
} else if (note.id) {
setPage(`${page}%note#${note.id}`);
}
}
};
const itemCard: (note: Note) => JSX.Element = (note) => {
return (
<Card onPress={() => onPress(note)}>
<NoteCard note={note} />
</Card>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
},
icon: {
width: 32,
height: 32,
},
});
return (
<>
<Layout style={styles.container} level='4'>
<List data={notes} renderItem={(item) => itemCard(item.item)} />
</Layout>
<ActionButton
buttonColor={theme['color-primary-400']}
useNativeFeedback={true}
fixNativeFeedbackRadius={true}
>
<ActionButton.Item
buttonColor={theme['color-warning-500']}
title={t('homePage.send')}
onPress={() => setPage(`${page}%send`)}
>
<Icon name='paper-plane' size={30} color={theme['text-basic-color']} solid />
</ActionButton.Item>
</ActionButton>
</>
);
};
export default HomePage;

View File

@ -0,0 +1,182 @@
import React, { useContext, useEffect, useState } from 'react';
import { Button, Input, Layout, Text } from '@ui-kitten/components';
import { StyleSheet } from 'react-native';
import Loading from '../Loading';
import { RelayPoolContext } from '../../Contexts/RelayPoolContext';
import { useTranslation } from 'react-i18next';
import { tagToUser } from '../../Functions/RelayFunctions/Users';
import Relay, { RelayFilters } from '../../lib/nostr/Relay';
import { Event, EventKind } from '../../lib/nostr/Events';
import { AppContext } from '../../Contexts/AppContext';
import { getUsers, insertUserContact } from '../../Functions/DatabaseFunctions/Users';
import { getPublickey } from '../../lib/nostr/Bip';
import EncryptedStorage from 'react-native-encrypted-storage';
import { SQLiteDatabase } from 'react-native-sqlite-storage';
export const LandingPage: React.FC = () => {
const { privateKey, setPrivateKey, publicKey, setPublicKey, relayPool, initRelays } =
useContext(RelayPoolContext);
const { database, setPage, runMigrations, loadingDb } = useContext(AppContext);
const { t } = useTranslation('common');
const [init, setInit] = useState<boolean>(true);
const [loading, setLoading] = useState<boolean>(false);
const [status, setStatus] = useState<number>(0);
const [totalPets, setTotalPets] = useState<number>();
const [loadedUsers, setLoadedUsers] = useState<number>(0);
const [usersReady, setUsersReady] = useState<boolean>(false);
const styles = StyleSheet.create({
tab: {
height: '100%',
alignItems: 'center',
justifyContent: 'center',
},
svg: {
height: 340,
width: 340,
},
title: {
marginTop: -40,
marginBottom: -20,
fontFamily: 'SpaceGrotesk-Bold',
},
input: {
marginVertical: 2,
padding: 32,
},
});
useEffect(() => { // #1 STEP
if (init) {
EncryptedStorage.getItem('privateKey').then((result) => {
if (result && result !== '') {
setPrivateKey(result);
setPublicKey(getPublickey(result));
setUsersReady(true);
} if (!loadingDb) {
setInit(false);
} else {
runMigrations();
}
});
}
}, [init, relayPool, loadingDb]);
useEffect(() => {
if (usersReady && relayPool) {
initRelays()
setPage('home');
}
}, [usersReady, relayPool]);
useEffect(() => {
if (loading && publicKey !== '') {
initEvents();
}
}, [loading, publicKey]);
useEffect(() => {
if (loading && loadedUsers) {
loadUsers();
}
}, [loading, totalPets, loadedUsers]);
const initEvents: () => void = () => {
relayPool?.on('event', 'landing', (_relay: Relay, _subId?: string, event?: Event) => {
if (database && event) {
if (event.kind === EventKind.petNames) {
loadPets(event);
} else {
if (event.kind === EventKind.meta && event.pubkey !== publicKey) {
setLoadedUsers((prev) => prev + 1)
}
}
}
});
relayPool?.subscribe('main-channel', {
kinds: [EventKind.meta, EventKind.petNames],
authors: [publicKey],
});
};
const loadPets: (event: Event) => void = (event) => {
if (database) {
setTotalPets(event.tags.length);
insertUserContact(event, database).then(() => {
relayPool?.subscribe('main-channel', {
kinds: [EventKind.meta],
authors: event.tags.map((tag) => tagToUser(tag).id),
});
})
setStatus(2);
}
};
const requestUsers: (database: SQLiteDatabase) => void = () => {
if (database && status < 3) {
setUsersReady(true);
getUsers(database, { exludeIds: [publicKey], contacts: true }).then((users) => {
const message: RelayFilters = {
kinds: [EventKind.textNote, EventKind.recommendServer],
authors: [publicKey, ...users.map((user) => user.id)],
limit: 15,
};
relayPool?.subscribe('main-channel', message);
setStatus(3);
})
}
}
const loadUsers: () => void = () => {
if (database) {
getUsers(database, { exludeIds: [publicKey], contacts: true }).then((users) => {
if (loadedUsers === totalPets) {
requestUsers(database)
}
});
setTimeout(() => requestUsers(database), 10000);
}
};
const onPress: () => void = () => {
setLoading(true);
setPublicKey(getPublickey(privateKey));
setStatus(1);
EncryptedStorage.setItem('privateKey', privateKey);
};
const statusName: { [status: number]: string } = {
0: t('landing.connect'),
1: t('landing.connecting'),
2: `${t('landing.loadingContacts')} ${loadedUsers}/${totalPets ?? 0}`,
3: t('landing.loadingTimeline'),
};
return (
<Layout style={styles.tab}>
<Layout style={styles.svg}>
<Loading />
</Layout>
<Text style={styles.title} category='h1'>
NOSTROS
</Text>
{!init && (
<>
<Input
style={styles.input}
size='medium'
label={t('landing.privateKey')}
secureTextEntry={true}
onChangeText={setPrivateKey}
value={privateKey}
disabled={loading}
/>
<Button onPress={onPress} disabled={loading}>
{statusName[status]}
</Button>
</>
)}
</Layout>
);
};
export default LandingPage;

View File

@ -0,0 +1,31 @@
import React from 'react';
import { Animated, Easing } from 'react-native';
import { SvgXml } from 'react-native-svg';
interface LoadingProps {
style?: object;
}
export const Loading: React.FC<LoadingProps> = ({ style = {} }) => {
const logo = `<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svgjs="http://svgjs.dev/svgjs" viewBox="0 0 800 800"><g stroke="hsl(0, 0%, 100%)" fill="none" stroke-linecap="round" style="--darkreader-inline-stroke: #e8e6e3;" data-darkreader-inline-stroke=""><circle r="256" cx="400" cy="400" stroke-width="24" stroke-dasharray="68 51" stroke-dashoffset="25" transform="rotate(309, 400, 400)" opacity="1.00"></circle><circle r="224" cx="400" cy="400" stroke-width="23" stroke-dasharray="76 63" stroke-dashoffset="25" transform="rotate(258, 400, 400)" opacity="0.86"></circle><circle r="192" cx="400" cy="400" stroke-width="22" stroke-dasharray="63 31" stroke-dashoffset="25" transform="rotate(74, 400, 400)" opacity="0.73"></circle><circle r="160" cx="400" cy="400" stroke-width="21" stroke-dasharray="75 71" stroke-dashoffset="25" transform="rotate(62, 400, 400)" opacity="0.59"></circle><circle r="128" cx="400" cy="400" stroke-width="21" stroke-dasharray="43 37" stroke-dashoffset="25" transform="rotate(333, 400, 400)" opacity="0.46"></circle><circle r="96" cx="400" cy="400" stroke-width="20" stroke-dasharray="65 73" stroke-dashoffset="25" transform="rotate(17, 400, 400)" opacity="0.32"></circle><circle r="64" cx="400" cy="400" stroke-width="19" stroke-dasharray="33 58" stroke-dashoffset="25" transform="rotate(269, 400, 400)" opacity="0.19"></circle><circle r="32" cx="400" cy="400" stroke-width="18" stroke-dasharray="66 52" stroke-dashoffset="25" transform="rotate(281, 400, 400)" opacity="0.05"></circle></g></svg>`;
const spinValue = new Animated.Value(0);
Animated.timing(spinValue, {
toValue: 1,
duration: 100000,
easing: Easing.linear, // Easing is an additional import from react-native
useNativeDriver: true, // To make use of native driver for performance
}).start();
const spin = spinValue.interpolate({
inputRange: [0, 1],
outputRange: ['0deg', '2016deg'],
});
return (
<Animated.View style={{ ...style, ...{ transform: [{ rotate: spin }] } }}>
<SvgXml xml={logo} />
</Animated.View>
);
};
export default Loading;

View File

@ -0,0 +1,63 @@
import React, { useContext, useEffect, useState } from 'react';
import { Layout } from '@ui-kitten/components';
import { StyleSheet } from 'react-native';
import { AppContext } from '../../Contexts/AppContext';
import HomePage from '../HomePage';
import ProfilePage from '../ProfilePage';
import NavigationBar from '../NavigationBar';
import SendPage from '../SendPage';
import ContactsPage from '../ContactsPage';
import NotePage from '../NotePage';
import LandingPage from '../LandingPage';
import { RelayPoolContext } from '../../Contexts/RelayPoolContext';
import ConfigPage from '../ConfigPage';
export const MainLayout: React.FC = () => {
const { page } = useContext(AppContext);
const { relayPool } = useContext(RelayPoolContext);
const [lastPage, setLastPage] = useState<string>(page)
const styles = StyleSheet.create({
container: {
flex: 1,
},
});
const pagination: { [pageName: string]: JSX.Element } = {
landing: <LandingPage />,
home: <HomePage />,
send: <SendPage />,
profile: <ProfilePage />,
contacts: <ContactsPage />,
note: <NotePage />,
config: <ConfigPage />,
};
const breadcrump: string[] = page.split('%');
const pageToDisplay: string = breadcrump[breadcrump.length - 1].split('#')[0];
const clearSubscriptions: () => boolean = () => {
if (relayPool && lastPage && lastPage !== page) {
relayPool.unsubscribeAll()
relayPool.removeOn('event', lastPage)
setLastPage(page)
}
return true
}
return page === 'landing' ? (
<Layout style={styles.container} level='4'>
<LandingPage />
</Layout>
) : (
<>
<Layout style={styles.container} level='4'>
{clearSubscriptions() && pagination[pageToDisplay]}
</Layout>
<NavigationBar />
</>
);
};
export default MainLayout;

View File

@ -0,0 +1,44 @@
import React, { useContext } from 'react';
import { BottomNavigation, BottomNavigationTab, useTheme } from '@ui-kitten/components';
import { AppContext } from '../../Contexts/AppContext';
import { RelayPoolContext } from '../../Contexts/RelayPoolContext';
import Icon from 'react-native-vector-icons/FontAwesome5';
export const NavigationBar: React.FC = () => {
const { setPage, page } = useContext(AppContext);
const { publicKey } = useContext(RelayPoolContext);
const theme = useTheme();
const pageIndex: string[] = ['home', 'contacts', `profile`];
const getIndex: () => number = () => {
if (page.includes('profile#')) {
return page === `profile#${publicKey}` ? 2 : 1;
} else if (page.includes('note#')) {
return 0;
} else {
return pageIndex.indexOf(page);
}
};
return (
page && (
<BottomNavigation
selectedIndex={getIndex()}
onSelect={(index: number) => setPage(pageIndex[index])}
>
<BottomNavigationTab
icon={<Icon name='home' size={24} color={theme['text-basic-color']} />}
/>
<BottomNavigationTab
icon={<Icon name='address-book' size={24} color={theme['text-basic-color']} />}
/>
<BottomNavigationTab
icon={<Icon name='user' size={24} color={theme['text-basic-color']} />}
/>
</BottomNavigation>
)
);
};
export default NavigationBar;

View File

@ -0,0 +1,211 @@
import React, { useContext, useState } from 'react';
import { Button, Layout, Text, useTheme } from '@ui-kitten/components';
import { Note } from '../../Functions/DatabaseFunctions/Notes';
import { StyleSheet, TouchableOpacity } from 'react-native';
import UserAvatar from 'react-native-user-avatar';
import Markdown from 'react-native-markdown-display';
import { EventKind } from '../../lib/nostr/Events';
import Icon from 'react-native-vector-icons/FontAwesome5';
import { RelayPoolContext } from '../../Contexts/RelayPoolContext';
import { storeRelay } from '../../Functions/DatabaseFunctions/Relays';
import { AppContext } from '../../Contexts/AppContext';
import { showMessage } from 'react-native-flash-message';
import { t } from 'i18next';
import { getReplyEventId } from '../../Functions/RelayFunctions/Events';
import moment from 'moment';
import { populateRelay } from '../../Functions/RelayFunctions';
interface NoteCardProps {
note: Note;
}
export const NoteCard: React.FC<NoteCardProps> = ({ note }) => {
const theme = useTheme();
const { relayPool, setRelayPool, publicKey } = useContext(RelayPoolContext);
const { database, setPage, page } = useContext(AppContext);
const [relayAdded, setRelayAdded] = useState<boolean>(
Object.keys(relayPool?.relays ?? {}).includes(note.content),
);
const textNote: () => JSX.Element = () => {
return (
<>
<Layout style={styles.profile} level='2'>
<TouchableOpacity onPress={onPressUser}>
<UserAvatar
name={note.name && note.name !== '' ? note.name : note.pubkey}
src={note.picture}
size={38}
textColor={theme['text-basic-color']}
/>
</TouchableOpacity>
</Layout>
<Layout style={styles.contentNoAction} level='2'>
<Layout style={styles.titleText}>
<TouchableOpacity onPress={onPressUser}>
<Layout style={styles.pubkey}>
<Text appearance='hint'>
{note.name}
{note.name && ' - '}
{`${note.pubkey.slice(0, 6)}...${note.pubkey.slice(-6)}`}
</Text>
</Layout>
</TouchableOpacity>
<Layout style={styles.tags}>
{getReplyEventId(note) && (
<Icon name='comment-dots' size={16} color={theme['text-basic-color']} solid />
)}
</Layout>
</Layout>
<Layout style={styles.text}>
<Markdown style={markdownStyle}>{note.content}</Markdown>
</Layout>
<Layout style={styles.footer}>
<Text appearance='hint'>{moment.unix(note.created_at).format('DD-MM-YYYY hh:mm')}</Text>
</Layout>
</Layout>
</>
);
};
const relayNote: () => JSX.Element = () => {
const relayName = note.content.split('wss://')[1].split('/')[0];
const addRelay: () => void = () => {
if (relayPool) {
relayPool.add(note.content);
setRelayPool(relayPool);
storeRelay({ url: note.content }, database);
populateRelay(relayPool, database, publicKey)
showMessage({
message: t('alerts.relayAdded'),
description: note.content,
type: 'success',
});
setRelayAdded(true);
}
};
return (
<>
<Layout style={styles.profile} level='2'>
<Icon name='server' size={30} color={theme['text-basic-color']} solid />
</Layout>
<Layout style={styles.content} level='2'>
<Text appearance='hint'>{note.name}</Text>
<Text>{relayName}</Text>
</Layout>
<Layout style={styles.actions} level='2'>
{!relayAdded && (
<Button
status='success'
onPress={addRelay}
accessoryLeft={
<Icon name='plus-circle' size={16} color={theme['text-basic-color']} solid />
}
/>
)}
</Layout>
</>
);
};
const onPressUser: () => void = () => {
setPage(`${page}%profile#${note.pubkey}`);
};
const styles = StyleSheet.create({
layout: {
flexDirection: 'row',
backgroundColor: 'transparent',
},
profile: {
flex: 1,
width: 38,
alignItems: 'center',
backgroundColor: 'transparent',
},
content: {
flex: 4,
backgroundColor: 'transparent',
paddingLeft: 16,
paddingRight: 16,
},
contentNoAction: {
flex: 5,
backgroundColor: 'transparent',
paddingLeft: 16,
paddingRight: 16,
},
actions: {
flex: 1,
backgroundColor: 'transparent',
},
pubkey: {
backgroundColor: 'transparent',
},
footer: {
backgroundColor: 'transparent',
},
tags: {
backgroundColor: 'transparent',
marginLeft: 12,
},
titleText: {
backgroundColor: 'transparent',
flexDirection: 'row',
},
text: {
backgroundColor: 'transparent',
paddingRight: 10,
},
});
const markdownStyle = {
text: {
color: theme['text-basic-color'],
},
tr: {
borderColor: theme['border-primary-color-5'],
},
table: {
borderColor: theme['border-primary-color-5'],
},
blocklink: {
borderColor: theme['border-primary-color-5'],
},
hr: {
backgroundColor: theme['background-basic-color-3'],
},
blockquote: {
backgroundColor: theme['background-basic-color-3'],
borderColor: theme['border-primary-color-5'],
color: theme['text-basic-color'],
},
code_inline: {
borderColor: theme['border-primary-color-5'],
backgroundColor: theme['background-basic-color-3'],
color: theme['text-basic-color'],
},
code_block: {
borderColor: theme['border-primary-color-5'],
backgroundColor: theme['background-basic-color-3'],
color: theme['text-basic-color'],
},
fence: {
borderColor: theme['border-primary-color-5'],
backgroundColor: theme['background-basic-color-3'],
color: theme['text-basic-color'],
},
};
return (
note && (
<Layout style={styles.layout} level='2'>
{note.kind === EventKind.recommendServer ? relayNote() : textNote()}
</Layout>
)
);
};
export default NoteCard;

View File

@ -0,0 +1,151 @@
import {
Card,
Layout,
List,
TopNavigation,
TopNavigationAction,
useTheme,
} from '@ui-kitten/components';
import React, { useContext, useEffect, useState } from 'react';
import { AppContext } from '../../Contexts/AppContext';
import { getNotes, Note } from '../../Functions/DatabaseFunctions/Notes';
import { RelayPoolContext } from '../../Contexts/RelayPoolContext';
import Icon from 'react-native-vector-icons/FontAwesome5';
import NoteCard from '../NoteCard';
import { EventKind } from '../../lib/nostr/Events';
import { RelayFilters } from '../../lib/nostr/Relay';
import { StyleSheet } from 'react-native';
import Loading from '../Loading';
import ActionButton from 'react-native-action-button';
import { useTranslation } from 'react-i18next';
import { getDirectReplies, getReplyEventId } from '../../Functions/RelayFunctions/Events';
export const NotePage: React.FC = () => {
const { page, setPage, database } = useContext(AppContext);
const { lastEventId, relayPool } = useContext(RelayPoolContext);
const [note, setNote] = useState<Note>();
const [replies, setReplies] = useState<Note[]>([]);
const theme = useTheme();
const { t } = useTranslation('common');
const breadcrump = page.split('%');
const eventId = breadcrump[breadcrump.length - 1].split('#')[1];
useEffect(() => {
getNotes(database, { filters: { id: eventId } }).then((events) => {
if (events.length > 0) {
const event = events[0];
setNote(event)
getNotes(database, { filters: { reply_event_id: eventId } }).then((notes) => {
const rootReplies = getDirectReplies(notes, event);
if (rootReplies.length > 0) {
setReplies(rootReplies as Note[]);
const message: RelayFilters = {
kinds: [EventKind.meta],
authors: rootReplies.map((note) => note.pubkey),
};
relayPool?.subscribe('main-channel', message);
} else {
setReplies([]);
}
});
}
});
relayPool?.subscribe('main-channel', {
kinds: [EventKind.textNote, EventKind.recommendServer],
ids: [eventId],
});
relayPool?.subscribe('main-channel', {
kinds: [EventKind.textNote, EventKind.recommendServer],
'#e': [eventId],
});
}, [lastEventId, page]);
const onPressBack: () => void = () => {
console.log(breadcrump.slice(0, -1).join('%'))
setPage(breadcrump.slice(0, -1).join('%'));
};
const renderBackAction = (): JSX.Element => {
return (
<TopNavigationAction
icon={<Icon name='arrow-left' size={16} color={theme['text-basic-color']} />}
onPress={onPressBack}
/>
);
};
const onPressNote: (note: Note) => void = (note) => {
if (note.kind !== EventKind.recommendServer) {
const replyEventId = getReplyEventId(note);
if (replyEventId && replyEventId !== eventId) {
setPage(`${page}%note#${replyEventId}`);
} else if (note.id) {
setPage(`${page}%note#${note.id}`);
}
setReplies([])
}
};
const ItemCard: (note?: Note) => JSX.Element = (note) => {
if (note?.id === eventId) {
return (
<Layout style={styles.main} level='2'>
<NoteCard note={note} />
</Layout>
)
} else if (note) {
return (
<Card onPress={() => onPressNote(note)}>
<NoteCard note={note} />
</Card>
);
} else {
return <></>;
}
};
const styles = StyleSheet.create({
main: {
paddingBottom: 32,
paddingTop: 26,
paddingLeft: 26,
paddingRight: 26,
},
loading: {
maxHeight: 160,
},
});
return (
<>
<TopNavigation
alignment='center'
title={`${eventId.slice(0, 12)}...${eventId.slice(-12)}`}
accessoryLeft={renderBackAction}
/>
<Layout level='4'>
{note ? (
<List data={[note, ...replies]} renderItem={(item) => ItemCard(item?.item)} />
) : (
<Loading style={styles.loading} />
)}
</Layout>
<ActionButton
buttonColor={theme['color-primary-400']}
useNativeFeedback={true}
fixNativeFeedbackRadius={true}
>
<ActionButton.Item
buttonColor={theme['color-warning-500']}
title={t('notePage.reply')}
onPress={() => setPage(`send#${eventId}`)}
>
<Icon name='reply' size={30} color={theme['text-basic-color']} solid />
</ActionButton.Item>
</ActionButton>
</>
);
};
export default NotePage;

View File

@ -0,0 +1,300 @@
import {
Card,
Layout,
List,
Spinner,
Text,
TopNavigation,
TopNavigationAction,
useTheme,
} from '@ui-kitten/components';
import React, { useContext, useEffect, useState } from 'react';
import { StyleSheet, TouchableOpacity } from 'react-native';
import { AppContext } from '../../Contexts/AppContext';
import UserAvatar from 'react-native-user-avatar';
import { getNotes, Note } from '../../Functions/DatabaseFunctions/Notes';
import NoteCard from '../NoteCard';
import { RelayPoolContext } from '../../Contexts/RelayPoolContext';
import {
getUser,
getUsers,
removeContact,
addContact,
User,
} from '../../Functions/DatabaseFunctions/Users';
import { EventKind, Event } from '../../lib/nostr/Events';
import Relay from '../../lib/nostr/Relay';
import Icon from 'react-native-vector-icons/FontAwesome5';
import ActionButton from 'react-native-action-button';
import { useTranslation } from 'react-i18next';
import { populatePets, tagToUser } from '../../Functions/RelayFunctions/Users';
import { getReplyEventId } from '../../Functions/RelayFunctions/Events';
import Loading from '../Loading';
import { storeEvent } from '../../Functions/DatabaseFunctions/Events';
export const ProfilePage: React.FC = () => {
const { database, page, setPage } = useContext(AppContext);
const { publicKey, lastEventId, relayPool, setLastEventId } = useContext(RelayPoolContext);
const theme = useTheme();
const [notes, setNotes] = useState<Note[]>([]);
const { t } = useTranslation('common');
const [user, setUser] = useState<User | null>(null);
const [contacts, setContactsIds] = useState<string[]>();
const [isContact, setIsContact] = useState<boolean>();
const breadcrump = page.split('%');
const userId = breadcrump[breadcrump.length - 1].split('#')[1] ?? publicKey;
const username = user?.name === '' ? user?.id : user?.name;
useEffect(() => {
setUser(null)
setNotes([])
relayPool?.on('event', 'profile', (_relay: Relay, _subId?: string, event?: Event) => {
console.log('PROFILE EVENT =======>', event);
if (database && event?.id && event.pubkey === userId) {
if (event.kind === EventKind.petNames) {
const ids = event.tags.map((tag) => tagToUser(tag).id);
setContactsIds(ids);
} else if (event.kind === EventKind.meta) {
storeEvent(event, database).finally(() => {
if (event?.id) setLastEventId(event.id)
});
}
}
});
if (database) {
getNotes(database, { filters: { pubkey: userId }, limit: 1 }).then((notes) => {
if (notes) {
relayPool?.subscribe('main-channel', {
kinds: [EventKind.textNote, EventKind.recommendServer],
authors: [userId],
limit: 10,
since: notes[0]?.created_at,
});
}
});
}
relayPool?.subscribe('main-channel', {
kinds: [EventKind.meta, EventKind.petNames],
authors: [userId],
});
}, [page]);
useEffect(() => {
if (database) {
getUser(userId, database).then((user) => {
setUser(user);
setIsContact(user?.contact);
});
if (userId === publicKey) {
getUsers(database, { contacts: true }).then((users) => {
setContactsIds(users.map((user) => user.id));
});
}
getNotes(database, { filters: { pubkey: userId } }).then((notes) => {
if (notes) {
setNotes(notes);
}
});
}
}, [lastEventId, page]);
const removeAuthor: () => void = () => {
if (relayPool && database) {
removeContact(userId, database).then(() => {
populatePets(relayPool, database, publicKey)
setIsContact(false)
});
}
};
const addAuthor: () => void = () => {
if (relayPool && database) {
addContact(userId, database).then(() => {
populatePets(relayPool, database, publicKey)
setIsContact(true)
});
}
};
const renderOptions: () => JSX.Element = () => {
if (publicKey === userId) {
return (
<TopNavigationAction
icon={<Icon name='dna' size={16} color={theme['text-basic-color']} solid />}
onPress={() => setPage('config')}
/>
);
} else {
if (user) {
if (isContact) {
return (
<TopNavigationAction
icon={<Icon name='user-minus' size={16} color={theme['color-danger-500']} solid />}
onPress={removeAuthor}
/>
);
} else {
return (
<TopNavigationAction
icon={<Icon name='user-plus' size={16} color={theme['color-success-500']} solid />}
onPress={addAuthor}
/>
);
}
} else {
return <Spinner size='tiny' />;
}
}
};
const onPressBack: () => void = () => {
setPage(breadcrump.slice(0, -1).join('%'));
};
const renderBackAction = (): JSX.Element => {
if (publicKey === userId) {
return <></>;
} else {
return (
<TopNavigationAction
icon={<Icon name='arrow-left' size={16} color={theme['text-basic-color']} />}
onPress={onPressBack}
/>
);
}
};
const styles = StyleSheet.create({
list: {
flex: 1,
},
icon: {
width: 32,
height: 32,
},
settingsIcon: {
width: 48,
height: 48,
},
avatar: {
width: 140,
marginBottom: 16,
},
profile: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
marginBottom: 2,
paddingLeft: 32,
paddingRight: 32,
},
loading: {
maxHeight: 160,
},
about: {
flex: 4,
maxHeight: 200,
},
stats: {
flex: 1,
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
},
description: {
marginTop: 16,
flexDirection: 'row',
},
});
const itemCard: (note: Note) => JSX.Element = (note) => {
return (
<Card onPress={() => onPressNote(note)}>
<NoteCard note={note} />
</Card>
);
};
const onPressNote: (note: Note) => void = (note) => {
if (note.kind !== EventKind.recommendServer) {
const mainEventId = getReplyEventId(note);
if (mainEventId) {
setPage(`note#${mainEventId}`);
} else if (note.id) {
setPage(`note#${note.id}`);
}
}
};
const onPressId: () => void = () => {
// FIXME
// Clipboard.setString(user?.id ?? '');
};
const profile: JSX.Element = (
<Layout style={styles.profile} level='3'>
<Layout style={styles.avatar} level='3'>
{user ? (
<UserAvatar
name={user?.name && user?.name !== '' ? user?.name : user.id}
src={user?.picture}
size={140}
textColor={theme['text-basic-color']}
/>
) : (
<Loading style={styles.loading} />
)}
</Layout>
<TouchableOpacity onPress={onPressId}>
<Text appearance='hint'>{user?.id}</Text>
</TouchableOpacity>
<Layout style={styles.description} level='3'>
{user && (
<>
<Layout style={styles.stats} level='3'>
<Text>{contacts?.length ?? <Spinner size='tiny' />} </Text>
<Icon name='address-book' size={16} color={theme['text-basic-color']} solid />
</Layout>
<Layout style={styles.about} level='3'>
<Text numberOfLines={5} ellipsizeMode='tail'>
{user?.about}
</Text>
</Layout>
</>
)}
</Layout>
</Layout>
);
return (
<>
<TopNavigation
alignment='center'
title={username}
accessoryLeft={renderBackAction}
accessoryRight={renderOptions}
/>
{profile}
<Layout style={styles.list} level='3'>
<List data={notes} renderItem={(item) => itemCard(item.item)} />
</Layout>
{publicKey === userId && (
<ActionButton
buttonColor={theme['color-primary-400']}
useNativeFeedback={true}
fixNativeFeedbackRadius={true}
>
<ActionButton.Item
buttonColor={theme['color-warning-500']}
title={t('profilePage.send')}
onPress={() => setPage('send')}
>
<Icon name='paper-plane' size={30} color={theme['text-basic-color']} solid />
</ActionButton.Item>
</ActionButton>
)}
</>
);
};
export default ProfilePage;

View File

@ -0,0 +1,126 @@
import {
Button,
Input,
Layout,
Spinner,
TopNavigation,
TopNavigationAction,
useTheme,
} from '@ui-kitten/components';
import React, { useContext, useEffect, useState } from 'react';
import { StyleSheet } from 'react-native';
import { AppContext } from '../../Contexts/AppContext';
import Icon from 'react-native-vector-icons/FontAwesome5';
import { Event } from '../../lib/nostr/Events';
import { useTranslation } from 'react-i18next';
import { RelayPoolContext } from '../../Contexts/RelayPoolContext';
import moment from 'moment';
import { getNotes } from '../../Functions/DatabaseFunctions/Notes';
import { getETags } from '../../Functions/RelayFunctions/Events';
export const SendPage: React.FC = () => {
const theme = useTheme();
const { setPage, page, database } = useContext(AppContext);
const { relayPool, publicKey, lastEventId } = useContext(RelayPoolContext);
const { t } = useTranslation('common');
const [content, setContent] = useState<string>('');
const [sending, setSending] = useState<boolean>(false);
const [noteId, setNoteId] = useState<string>();
const breadcrump = page.split('%');
const eventId = breadcrump[breadcrump.length - 1].split('#')[1];
useEffect(() => {
if (sending && noteId === lastEventId) {
setPage(breadcrump.slice(0, -1).join('%') || 'home');
}
}, [lastEventId]);
const styles = StyleSheet.create({
container: {
flex: 1,
},
actionContainer: {
marginTop: 30,
paddingLeft: 32,
paddingRight: 32,
},
button: {
marginTop: 30,
},
});
const onPressBack: () => void = () => {
setPage(breadcrump.slice(0, -1).join('%'));
};
const onPressSend: () => void = () => {
getNotes(database, { filters: { id: eventId } }).then((notes) => {
let tags: string[][] = [];
const note = notes[0];
if (note) {
tags = note.tags;
if (getETags(note).length === 0) {
tags.push(['e', eventId, '', 'root']);
} else {
tags.push(['e', eventId, '', 'reply']);
}
}
const event: Event = {
content,
created_at: moment().unix(),
kind: 1,
pubkey: publicKey,
tags,
};
relayPool?.sendEvent(event);
setNoteId(note.id)
setSending(true);
});
};
const renderBackAction = (): JSX.Element => (
<TopNavigationAction
icon={<Icon name='arrow-left' size={16} color={theme['text-basic-color']} />}
onPress={onPressBack}
/>
);
return (
<>
<Layout style={styles.container} level='2'>
<TopNavigation
alignment='center'
title={t('sendPage.title')}
accessoryLeft={renderBackAction}
/>
<Layout style={styles.actionContainer} level='2'>
<Layout>
<Input
multiline={true}
textStyle={{ minHeight: 64 }}
placeholder={t('sendPage.placeholder')}
value={content}
onChangeText={setContent}
size='large'
autoFocus={true}
keyboardType='twitter'
/>
</Layout>
<Layout style={styles.button}>
<Button
onPress={onPressSend}
disabled={sending}
accessoryLeft={sending ? <Spinner size='tiny' /> : <></>}
>
{t('sendPage.send')}
</Button>
</Layout>
</Layout>
</Layout>
</>
);
};
export default SendPage;

View File

@ -0,0 +1,61 @@
import React, { useContext } from 'react';
import { Card, Layout, Text, useTheme } from '@ui-kitten/components';
import { User } from '../../Functions/DatabaseFunctions/Users';
import { StyleSheet } from 'react-native';
import UserAvatar from 'react-native-user-avatar';
import { AppContext } from '../../Contexts/AppContext';
interface NoteCardProps {
user: User;
}
export const NoteCard: React.FC<NoteCardProps> = ({ user }) => {
const { setPage, page } = useContext(AppContext);
const theme = useTheme();
const styles = StyleSheet.create({
layout: {
flex: 1,
flexDirection: 'row',
backgroundColor: 'transparent',
},
profile: {
flex: 1,
width: 38,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'transparent',
},
content: {
flex: 5,
backgroundColor: 'transparent',
},
actions: {
flex: 1,
backgroundColor: 'transparent',
},
});
return (
user && (
<Card onPress={() => setPage(`${page}%profile#${user.id}`)}>
<Layout style={styles.layout} level='2'>
<Layout style={styles.profile}>
<UserAvatar
name={user.name ?? user.id ?? ''}
src={user.picture}
size={38}
textColor={theme['text-basic-color']}
/>
</Layout>
<Layout style={styles.content} level='2'>
<Text>{user.name}</Text>
<Text appearance='hint'>{user.id}</Text>
</Layout>
</Layout>
</Card>
)
);
};
export default NoteCard;

View File

@ -0,0 +1,56 @@
import React, { useEffect, useState } from 'react';
import { SQLiteDatabase } from 'react-native-sqlite-storage';
import { initDatabase } from '../Functions/DatabaseFunctions';
import { createInitDatabase } from '../Functions/DatabaseFunctions/Migrations';
import FlashMessage from 'react-native-flash-message';
export interface AppContextProps {
page: string;
setPage: (page: string) => void;
runMigrations: () => void;
loadingDb: boolean;
database: SQLiteDatabase | null;
}
export interface AppContextProviderProps {
children: React.ReactNode;
}
export const initialAppContext: AppContextProps = {
page: 'landing',
setPage: () => {},
runMigrations: () => {},
loadingDb: true,
database: null,
};
export const AppContextProvider = ({ children }: AppContextProviderProps): JSX.Element => {
const [page, setPage] = useState<string>(initialAppContext.page);
const [database, setDatabase] = useState<SQLiteDatabase | null>(null);
const [loadingDb, setLoadingDb] = useState<boolean>(initialAppContext.loadingDb);
const runMigrations: () => void = async () => {
const db = initDatabase()
setDatabase(db)
createInitDatabase(db).then(() => {
setLoadingDb(false);
});
};
return (
<AppContext.Provider
value={{
page,
setPage,
loadingDb,
database,
runMigrations,
}}
>
{children}
<FlashMessage position='top' />
</AppContext.Provider>
);
};
export const AppContext = React.createContext(initialAppContext);

View File

@ -0,0 +1,124 @@
import React, { useContext, useEffect, useState } from 'react';
import Relay from '../lib/nostr/Relay';
import { Event, EventKind } from '../lib/nostr/Events';
import RelayPool from '../lib/nostr/RelayPool/intex';
import { AppContext } from './AppContext';
import { storeEvent } from '../Functions/DatabaseFunctions/Events';
import { getRelays, Relay as RelayEntity, storeRelay } from '../Functions/DatabaseFunctions/Relays';
import { showMessage } from 'react-native-flash-message';
import { getReplyEventId } from '../Functions/RelayFunctions/Events';
export interface RelayPoolContextProps {
relayPool?: RelayPool;
setRelayPool: (relayPool: RelayPool) => void;
publicKey: string;
setPublicKey: (privateKey: string) => void;
privateKey: string;
setPrivateKey: (privateKey: string) => void;
lastEventId?: string;
setLastEventId: (lastEventId: string) => void;
loadingRelays: boolean;
initRelays: () => void;
loadRelays: () => void;
}
export interface RelayPoolContextProviderProps {
children: React.ReactNode;
}
export const initialRelayPoolContext: RelayPoolContextProps = {
publicKey: '',
setPublicKey: () => {},
privateKey: '',
setPrivateKey: () => {},
setRelayPool: () => {},
setLastEventId: () => {},
loadingRelays: true,
initRelays: () => {},
loadRelays: () => {},
};
export const RelayPoolContextProvider = ({
children,
}: RelayPoolContextProviderProps): JSX.Element => {
const { database, loadingDb } = useContext(AppContext);
const [publicKey, setPublicKey] = useState<string>('');
const [privateKey, setPrivateKey] = useState<string>('');
const [relayPool, setRelayPool] = useState<RelayPool>();
const [lastEventId, setLastEventId] = useState<string>();
const [loadingRelays, setLoadingRelays] = useState<boolean>(true);
const initRelays: () => void = () => {
relayPool?.on(
'notice',
'RelayPoolContextProvider',
(relay: Relay, _subId?: string, event?: Event) => {
showMessage({
message: relay.url,
description: event?.content ?? '',
type: 'info',
});
},
);
relayPool?.on(
'event',
'RelayPoolContextProvider',
(relay: Relay, _subId?: string, event?: Event) => {
console.log('RELAYPOOL EVENT =======>', relay.url, event);
if (database && event?.id && event.kind !== EventKind.petNames) {
storeEvent(event, database).finally(() => setLastEventId(event.id));
}
},
);
setLoadingRelays(false);
};
const loadRelays: () => void = () => {
if (database) {
getRelays(database).then((relays: RelayEntity[]) => {
const initRelayPool = new RelayPool([], privateKey);
if (relays.length > 0) {
relays.forEach((relay) => {
initRelayPool.add(relay.url);
});
} else {
['wss://relay.damus.io'].forEach((relayUrl) => {
initRelayPool.add(relayUrl);
storeRelay({ url: relayUrl }, database);
});
}
setRelayPool(initRelayPool);
})
}
}
useEffect(() => {
if (privateKey !== '' && !loadingDb && loadingRelays) {
loadRelays()
}
}, [privateKey, loadingDb])
return (
<RelayPoolContext.Provider
value={{
relayPool,
setRelayPool,
publicKey,
setPublicKey,
privateKey,
setPrivateKey,
lastEventId,
setLastEventId,
loadingRelays,
initRelays,
loadRelays,
}}
>
{children}
</RelayPoolContext.Provider>
);
};
export const RelayPoolContext = React.createContext(initialRelayPoolContext);

View File

@ -0,0 +1,13 @@
import { SQLError, Transaction } from 'react-native-sqlite-storage';
export const errorCallback: (
query: string,
reject?: (reason?: any) => void,
) => (transaction: Transaction, error: SQLError) => void = (query, reject) => {
const callback: (transaction: Transaction, error: SQLError) => void = (_transaction, error) => {
console.log('SQL ERROR =========>', query, error);
if (reject) reject(error);
};
return callback;
};

View File

@ -0,0 +1,21 @@
import { SQLiteDatabase } from 'react-native-sqlite-storage';
import { Event, EventKind } from '../../../lib/nostr/Events';
import { insertNote } from '../Notes';
import { insertUserMeta } from '../Users';
export const storeEvent: (event: Event, db: SQLiteDatabase) => Promise<void> = async (
event,
db,
) => {
return await new Promise<void>((resolve, reject) => {
try {
if (event.kind === EventKind.meta) {
insertUserMeta(event, db).then(resolve);
} else if (event.kind === EventKind.textNote || event.kind === EventKind.recommendServer) {
insertNote(event, db).then(resolve);
}
} catch (e) {
reject(e);
}
});
};

View File

@ -0,0 +1,47 @@
import { SQLiteDatabase } from 'react-native-sqlite-storage';
import { simpleExecute } from '..';
export const createInitDatabase: (db: SQLiteDatabase) => Promise<void> = async (db) => {
return await new Promise<void>((resolve) => {
simpleExecute(
`
CREATE TABLE IF NOT EXISTS nostros_notes(
id TEXT PRIMARY KEY NOT NULL,
content TEXT NOT NULL,
created_at INT NOT NULL,
kind INT NOT NULL,
pubkey TEXT NOT NULL,
sig TEXT NOT NULL,
tags TEXT NOT NULL,
main_event_id TEXT,
reply_event_id TEXT
);
`,
db,
).then(() => {
simpleExecute(
`
CREATE TABLE IF NOT EXISTS nostros_users(
id TEXT PRIMARY KEY NOT NULL,
name TEXT,
picture TEXT,
about TEXT,
main_relay TEXT,
contact BOOLEAN DEFAULT FALSE
);
`,
db,
).then(() => {
simpleExecute(
`
CREATE TABLE IF NOT EXISTS nostros_relays(
url TEXT PRIMARY KEY NOT NULL,
pet INTEGER
);
`,
db,
).then(() => resolve())
})
})
})
};

View File

@ -0,0 +1,108 @@
import { SQLiteDatabase } from 'react-native-sqlite-storage';
import { getItems } from '..';
import { Event, EventKind, verifySignature } from '../../../lib/nostr/Events';
import { getMainEventId, getReplyEventId } from '../../RelayFunctions/Events';
import { errorCallback } from '../Errors';
export interface Note extends Event {
name: string;
picture: string;
}
const databaseToEntity: (object: any) => Note = (object) => {
object.tags = JSON.parse(object.tags);
return object as Note;
};
export const insertNote: (event: Event, db: SQLiteDatabase) => Promise<void> = async (
event,
db,
) => {
return await new Promise<void>((resolve, reject) => {
if (!verifySignature(event) || !event.id) return reject(new Error('Bad event'));
if (![EventKind.textNote, EventKind.recommendServer].includes(event.kind)) return reject(new Error('Bad Kind'));
getNotes(db, { filters: { id: event.id } }).then((notes) => {
if (notes.length === 0 && event.id && event.sig) {
const mainEventId = getMainEventId(event) ?? '';
const replyEventId = getReplyEventId(event) ?? '';
const content = event.content.split("'").join("''");
const tags = JSON.stringify(event.tags).split("'").join("''");
const eventQuery = `INSERT INTO nostros_notes
(id,content,created_at,kind,pubkey,sig,tags,main_event_id,reply_event_id)
VALUES
(
'${event.id}',
'${content}',
${event.created_at},
${event.kind},
'${event.pubkey}',
'${event.sig}',
'${tags}',
'${mainEventId}',
'${replyEventId}'
);`;
db.transaction((transaction) => {
transaction.executeSql(
eventQuery,
[],
() => resolve(),
errorCallback(eventQuery, reject),
);
});
} else {
reject(new Error('Note already exists'));
}
});
});
};
export const getNotes: (
db: SQLiteDatabase,
options: {
filters?: { [column: string]: string };
limit?: number;
contacts?: boolean;
},
) => Promise<Note[]> = async (db, { filters = {}, limit, contacts }) => {
let notesQuery = `
SELECT nostros_notes.*, nostros_users.name, nostros_users.picture, nostros_users.contact FROM nostros_notes
LEFT JOIN nostros_users ON nostros_users.id = nostros_notes.pubkey
`;
if (filters) {
const keys = Object.keys(filters);
if (Object.keys(filters).length > 0) {
notesQuery += 'WHERE ';
keys.forEach((column, index) => {
notesQuery += `nostros_notes.${column} = '${filters[column]}' `;
if (index < keys.length - 1) notesQuery += 'AND ';
});
}
}
if (contacts) {
if (Object.keys(filters).length > 0) {
notesQuery += 'AND nostros_users.contact = TRUE ';
} else {
notesQuery += 'WHERE nostros_users.contact = TRUE ';
}
}
notesQuery += 'ORDER BY nostros_notes.created_at DESC ';
if (limit) {
notesQuery += `LIMIT ${limit}`;
}
return await new Promise<Note[]>((resolve, reject) => {
db.readTransaction((transaction) => {
transaction.executeSql(
notesQuery,
[],
(_transaction, resultSet) => {
const items: object[] = getItems(resultSet);
const notes: Note[] = items.map((object) => databaseToEntity(object));
resolve(notes);
},
errorCallback(notesQuery, reject),
);
});
});
};

View File

@ -0,0 +1,82 @@
import { SQLiteDatabase } from 'react-native-sqlite-storage';
import { getItems } from '..';
import { errorCallback } from '../Errors';
export interface Relay {
url: string;
name?: string;
}
const databaseToEntity: (object: any) => Relay = (object) => {
return object as Relay;
};
export const storeRelay: (relay: Relay, db: SQLiteDatabase) => void = async (relay, db) => {
if (relay.url) {
const relays: Relay[] = await searchRelays(relay.url, db);
if (relays.length === 0) {
const eventQuery = `
INSERT INTO nostros_relays
(url)
VALUES
(
'${relay.url.split("'").join("''")}'
);
`;
await new Promise<void>((resolve, reject) => {
db.transaction((transaction) => {
transaction.executeSql(
eventQuery,
[],
() => resolve(),
errorCallback(eventQuery, reject),
);
});
});
}
}
};
export const searchRelays: (relayUrl: string, db: SQLiteDatabase) => Promise<Relay[]> = async (
relayUrl,
db,
) => {
const searchQuery = `
SELECT * FROM nostros_relays WHERE url = '${relayUrl}';
`;
return await new Promise<Relay[]>((resolve, reject) => {
db.transaction((transaction) => {
transaction.executeSql(
searchQuery,
[],
(_transaction, resultSet) => {
const items: object[] = getItems(resultSet);
const notes: Relay[] = items.map((object) => databaseToEntity(object));
resolve(notes);
},
errorCallback(searchQuery, reject),
);
});
});
};
export const getRelays: (db: SQLiteDatabase) => Promise<Relay[]> = async (db) => {
const notesQuery = `SELECT * FROM nostros_relays;`;
return await new Promise<Relay[]>((resolve, reject) => {
db.readTransaction((transaction) => {
transaction.executeSql(
notesQuery,
[],
(_transaction, resultSet) => {
const items: object[] = getItems(resultSet);
const relays: Relay[] = items.map((object) => databaseToEntity(object));
resolve(relays);
},
errorCallback(notesQuery, reject),
);
});
});
};

View File

@ -0,0 +1,176 @@
import { SQLiteDatabase } from 'react-native-sqlite-storage';
import { getItems } from '..';
import { Event, EventKind, verifySignature } from '../../../lib/nostr/Events';
import { tagToUser } from '../../RelayFunctions/Users';
import { errorCallback } from '../Errors';
export interface User {
id: string;
main_relay?: string;
name?: string;
picture?: string;
about?: string;
contact?: boolean;
}
const databaseToEntity: (object: object) => User = (object) => {
return object as User;
};
export const insertUserMeta: (event: Event, db: SQLiteDatabase) => Promise<void> = async (
event,
db,
) => {
return await new Promise<void>((resolve, reject) => {
if (!verifySignature(event)) return reject(new Error('Bad signature'));
if (event.kind !== EventKind.meta) return reject(new Error('Bad Kind'));
const user: User = JSON.parse(event.content);
user.id = event.pubkey;
getUser(user.id, db).then((userDb) => {
let userQuery = '';
const id = user.id?.replace("\\'", "'") ?? '';
const name = user.name?.replace("\\'", "'") ?? '';
const mainRelay = user.main_relay?.replace("\\'", "'") ?? '';
const about = user.about?.replace("\\'", "'") ?? '';
const picture = user.picture?.replace("\\'", "'") ?? '';
if (userDb) {
userQuery = `
UPDATE nostros_users
SET name = '${name.split("'").join("''")}',
main_relay = '${mainRelay.split("'").join("''")}',
about = '${about.split("'").join("''")}',
picture = '${picture.split("'").join("''")}'
WHERE id = '${user.id}';
`;
} else {
userQuery = `
INSERT INTO nostros_users
(id, name, picture, about, main_relay)
VALUES
('${id}', '${name.split("'").join("''")}', '${picture.split("'").join("''")}', '${about.split("'").join("''")}', '');
`;
}
db.transaction((transaction) => {
transaction.executeSql(userQuery, [], () => resolve(), errorCallback(userQuery, reject));
});
});
});
};
export const insertUserContact: (event: Event, db: SQLiteDatabase) => Promise<void> = async (
event,
db,
) => {
return await new Promise<void>((resolve, reject) => {
if (!verifySignature(event)) return reject(new Error('Bad signature'));
if (event.kind !== EventKind.petNames) return reject(new Error('Bad Kind'));
const userTags: string[] = event.tags.map((tag) => tagToUser(tag).id);
userTags.forEach((userId) => {
addContact(userId, db);
});
resolve();
});
};
export const getUser: (pubkey: string, db: SQLiteDatabase) => Promise<User | null> = async (
pubkey,
db,
) => {
const userQuery = `SELECT * FROM nostros_users WHERE id = '${pubkey}';`;
return await new Promise<User | null>((resolve, reject) => {
db.readTransaction((transaction) => {
transaction.executeSql(
userQuery,
[],
(_transaction, resultSet) => {
if (resultSet.rows.length > 0) {
const items: object[] = getItems(resultSet);
const user: User = databaseToEntity(items[0]);
resolve(user);
} else {
resolve(null);
}
},
errorCallback(userQuery, reject),
);
});
});
};
export const removeContact: (pubkey: string, db: SQLiteDatabase) => Promise<void> = async (
pubkey,
db,
) => {
const userQuery = `UPDATE nostros_users SET contact = FALSE WHERE id = '${pubkey}'`;
return await new Promise<void>((resolve, reject) => {
db.transaction((transaction) => {
transaction.executeSql(userQuery, [], () => resolve(), errorCallback(userQuery, reject));
});
});
};
export const addContact: (pubkey: string, db: SQLiteDatabase) => Promise<void> = async (
pubkey,
db,
) => {
return await new Promise<void>((resolve, reject) => {
getUser(pubkey, db).then((userDb) => {
let userQuery = '';
if (userDb) {
userQuery = `
UPDATE nostros_users SET contact = TRUE WHERE id = '${pubkey}';
`;
} else {
userQuery = `
INSERT INTO nostros_users (id, contact) VALUES ('${pubkey}', TRUE);
`;
}
db.transaction((transaction) => {
transaction.executeSql(userQuery, [], () => resolve(), errorCallback(userQuery, reject));
});
});
});
};
export const getUsers: (
db: SQLiteDatabase,
options: { exludeIds?: string[]; contacts?: boolean },
) => Promise<User[]> = async (db, { exludeIds, contacts }) => {
let userQuery = `SELECT * FROM nostros_users `;
if (contacts) {
userQuery += `WHERE contact = TRUE `;
}
if (exludeIds && exludeIds.length > 0) {
if (!contacts) {
userQuery += `WHERE `;
} else {
userQuery += `AND `;
}
userQuery += `id NOT IN ('${exludeIds.join("', '")}') `;
}
userQuery += `ORDER BY name,id`;
return await new Promise<User[]>((resolve, reject) => {
db.readTransaction((transaction) => {
transaction.executeSql(
userQuery,
[],
(_transaction, resultSet) => {
if (resultSet.rows.length > 0) {
const items: object[] = getItems(resultSet);
const users: User[] = items.map((object) => databaseToEntity(object));
resolve(users);
} else {
resolve([]);
}
},
errorCallback(userQuery, reject),
);
});
});
};

View File

@ -0,0 +1,44 @@
import SQLite, { ResultSet, SQLiteDatabase, Transaction } from 'react-native-sqlite-storage';
import { errorCallback } from './Errors';
export const initDatabase: () => SQLiteDatabase = () => {
return SQLite.openDatabase(
{ name: 'nostros.db', location: 'default' },
() => {},
() => {},
);
};
export const getItems: (resultSet: ResultSet) => object[] = (resultSet) => {
const result: object[] = [];
for (let i = 0; i < resultSet.rows.length; i++) {
result.push(resultSet.rows.item(i));
}
return result;
};
export const simpleExecute: (query: string, db: SQLiteDatabase) => Promise<Transaction> = async (query, db) => {
return await db.transaction((transaction) => {
transaction.executeSql(query, [], () => {}, errorCallback(query));
})
};
export const dropTables: (db: SQLiteDatabase) => Promise<Transaction> = async (db) => {
const dropQueries = [
'DROP TABLE IF EXISTS nostros_notes;',
'DROP TABLE IF EXISTS nostros_users;',
'DROP TABLE IF EXISTS nostros_relays;'
]
return await db.transaction((transaction) => {
dropQueries.forEach((query) => {
transaction.executeSql(
query,
[],
() => {},
errorCallback(query),
);
})
});
};

View File

@ -0,0 +1,41 @@
import { Event } from '../../../lib/nostr/Events';
export const getMainEventId: (event: Event) => string | null = (event) => {
const eTags = getETags(event);
let mainTag = eTags.find((tag) => {
return tag[3] === 'root';
});
if (!mainTag) {
mainTag = eTags[0];
}
return mainTag ? mainTag[1] : null;
};
export const getReplyEventId: (event: Event) => string | null = (event) => {
const eTags = getETags(event);
let mainTag = eTags.find((tag) => {
return tag[3] === 'reply';
});
if (!mainTag) {
mainTag = eTags[eTags.length - 1];
}
return mainTag ? mainTag[1] : null;
};
export const getDirectReplies: (replies: Event[], event: Event) => Event[] = (replies, event) => {
const expectedTags: number = getETags(event).length + 1;
const filter = replies.filter((event) => {
const eventETags = getETags(event);
return eventETags.length === expectedTags;
});
return filter;
};
export const getETags: (event: Event) => string[][] = (event) => {
return event.tags.filter((tag) => tag[0] === 'e');
};

View File

@ -0,0 +1,63 @@
import moment from 'moment';
import { SQLiteDatabase } from 'react-native-sqlite-storage';
import RelayPool from '../../../lib/nostr/RelayPool/intex';
import { getUser, getUsers, User } from '../../DatabaseFunctions/Users';
import { Event } from '../../../lib/nostr/Events';
export const usersToTags: (users: User[]) => string[][] = (users) => {
return users.map((user): string[] => {
return ['p', user.id, user.main_relay ?? '', user.name ?? ''];
});
};
export const tagsToUsers: (tags: string[][]) => User[] = (tags) => {
return tags.map((tag): User => {
return tagToUser(tag);
});
};
export const tagToUser: (tag: string[]) => User = (tag) => {
return {
id: tag[1],
main_relay: tag[2],
name: tag[3],
};
};
export const populatePets: (relayPool: RelayPool, database: SQLiteDatabase, publicKey: string) => void = (relayPool, database, publicKey) => {
getUsers(database, { exludeIds: [publicKey], contacts: true }).then((results) => {
if (results) {
const event: Event = {
content: '',
created_at: moment().unix(),
kind: 3,
pubkey: publicKey,
tags: usersToTags(results),
};
relayPool?.sendEvent(event);
}
});
}
export const populateProfile: (relayPool: RelayPool, database: SQLiteDatabase, publicKey: string) => void = (relayPool, database, publicKey) => {
getUser(publicKey, database).then((result) => {
if (result) {
const profile = {
name: result.name,
main_relay: result.main_relay,
picture: result.picture,
about: result.about
}
const event: Event = {
content: JSON.stringify(profile),
created_at: moment().unix(),
kind: 0,
pubkey: publicKey,
tags: usersToTags([result]),
};
relayPool?.sendEvent(event);
}
});
}

View File

@ -0,0 +1,8 @@
import { SQLiteDatabase } from "react-native-sqlite-storage"
import RelayPool from "../../lib/nostr/RelayPool/intex"
import { populatePets, populateProfile } from "./Users"
export const populateRelay: (relayPool: RelayPool, database: SQLiteDatabase, publicKey: string) => void = (relayPool, database, publicKey) => {
populateProfile(relayPool, database, publicKey)
populatePets(relayPool, database, publicKey)
}

18
frontend/Locales/en.json Normal file
View File

@ -0,0 +1,18 @@
{
"navigationBar": {
"home": "Home",
"profile": "Profile"
},
"homePage": {
"search": "Search",
"send": "Send"
},
"sendPage": {
"title": "Send a note",
"placeholder": "Say something to the world...",
"send": "Send"
},
"alerts": {
"relayAdded": "Relay added"
}
}

46
frontend/index.tsx Normal file
View File

@ -0,0 +1,46 @@
import React from 'react';
import { ApplicationProvider, IconRegistry } from '@ui-kitten/components';
import theme from './theme.json';
import { EvaIconsPack } from '@ui-kitten/eva-icons';
import * as eva from '@eva-design/eva';
import { AppContextProvider } from './Contexts/AppContext';
import MainLayout from './Components/MainLayout';
import { I18nextProvider } from 'react-i18next';
import i18n from 'i18next';
import localeEN from './Locales/en.json';
import { RelayPoolContextProvider } from './Contexts/RelayPoolContext';
void i18n.init({
compatibilityJSON: 'v3',
defaultNS: 'common',
lng: 'en',
resources: {
en: localeEN,
},
});
export const Frontend: React.FC = () => {
const mapping = {
strict: {
'text-font-family': 'OpenSans-Regular',
},
components: {},
};
return (
<>
<IconRegistry icons={EvaIconsPack} />
<ApplicationProvider {...eva} theme={{ ...eva.dark, ...theme }} customMapping={mapping}>
<I18nextProvider i18n={i18n}>
<AppContextProvider>
<RelayPoolContextProvider>
<MainLayout />
</RelayPoolContextProvider>
</AppContextProvider>
</I18nextProvider>
</ApplicationProvider>
</>
);
};
export default Frontend;

View File

@ -0,0 +1,12 @@
import ecurve from 'ecurve';
import BigInteger from 'bigi';
export const getPublickey: (privateKey: string) => string = (privateKey) => {
const privateKeyBuffer = Buffer.from(privateKey, 'hex');
const ecparams = ecurve.getCurveByName('secp256k1');
const curvePt = ecparams.G.multiply(BigInteger.fromBuffer(privateKeyBuffer));
const publicKey = curvePt.getEncoded(true);
return publicKey.toString('hex').slice(2);
};

View File

@ -0,0 +1,73 @@
import schnorr from 'bip-schnorr';
export interface Event {
content: string;
created_at: number;
id?: string;
kind: 0 | 1 | 2 | 3;
pubkey: string;
sig?: string;
tags: string[][];
}
export enum EventKind {
meta = 0,
textNote = 1,
recommendServer = 2,
petNames = 3,
}
export const serializeEvent: (event: Event) => string = (event) => {
return JSON.stringify([0, event.pubkey, event.created_at, event.kind, event.tags, event.content]);
};
export const getEventHash: (event: Event) => Buffer = (event) => {
return schnorr.convert.hash(Buffer.from(serializeEvent(event)));
};
export const validateEvent: (event: Event) => boolean = (event) => {
if (event.id !== getEventHash(event).toString('hex')) return false;
if (typeof event.content !== 'string') return false;
if (typeof event.created_at !== 'number') return false;
if (!Array.isArray(event.tags)) return false;
for (let i = 0; i < event.tags.length; i++) {
const tag = event.tags[i];
if (!Array.isArray(tag)) return false;
for (let j = 0; j < tag.length; j++) {
if (typeof tag[j] === 'object') return false;
}
}
return true;
};
export const verifySignature: (event: Event) => Promise<boolean> = async (event) => {
try {
schnorr.verify(
Buffer.from(event.pubkey, 'hex'),
Buffer.from(event?.id, 'hex'),
Buffer.from(event?.sig, 'hex'),
);
return true;
} catch (_e) {
console.error(`The signature verification failed`);
return false;
}
};
export const signEvent: (event: Event, privateKey: string) => Promise<Event> = async (
event,
privateKey,
) => {
const hash = getEventHash(event);
const signature: string = Buffer.from(await schnorr.sign(privateKey, hash), 'hex').toString(
'hex',
);
event.id = hash.toString('hex');
event.sig = signature;
return event;
};

View File

@ -0,0 +1,141 @@
import { Event } from '../Events';
import { v5 as uuidv5 } from 'uuid';
export interface RelayFilters {
ids?: string[];
authors?: string[];
kinds?: number[];
'#e'?: string[];
'#p'?: string[];
since?: number;
limit?: number;
until?: number;
}
export interface RelayMessage {
data: string;
}
export interface RelayOptions {
reconnect?: boolean;
}
class Relay {
constructor(relayUrl: string, options: RelayOptions = { reconnect: true }) {
this.url = relayUrl;
this.options = options;
this.manualClose = false;
this.socket = new WebSocket(this.url);
this.subscriptions = {};
this.onOpen = () => {};
this.onEvent = () => {};
this.onEsoe = () => {};
this.onNotice = () => {};
this.initWebsocket();
}
private readonly options: RelayOptions;
private socket: WebSocket;
private manualClose: boolean;
private subscriptions: { [subId: string]: string[] };
private readonly initWebsocket: () => void = () => {
this.socket.onmessage = (message) => {
this.handleNostrMessage(message as RelayMessage);
};
this.socket.onclose = this.onClose;
this.socket.onerror = this.onError;
this.socket.onopen = () => this.onOpen(this);
};
private readonly onClose: () => void = () => {
if (!this.manualClose && this.options.reconnect) this.initWebsocket();
};
private readonly onError: () => void = () => {
if (this.options.reconnect) this.initWebsocket();
};
private readonly handleNostrMessage: (message: RelayMessage) => void = (message) => {
const data: any[] = JSON.parse(message.data);
if (data.length >= 2) {
const id: string = data[1];
if (data[0] === 'EVENT') {
if (data.length < 3) return;
const message: Event = data[2];
return this.onEvent(this, id, message);
} else if (data[0] === 'EOSE') {
return this.onEsoe(this, id);
} else if (data[0] === 'NOTICE') {
return this.onNotice(this, [...data.slice(1)]);
}
}
};
private readonly send: (message: object) => void = async (message) => {
const tosend = JSON.stringify(message);
if (this.socket.readyState !== WebSocket.OPEN) {
setTimeout(() => {
this.send(message);
}, 500);
} else {
try {
console.log('SEND =====>', tosend);
this.socket.send(tosend);
} catch (e) {
console.log('Failed ot send Event', e);
}
}
};
public url: string;
public onOpen: (relay: Relay) => void;
public onEvent: (relay: Relay, subId: string, event: Event) => void;
public onEsoe: (relay: Relay, subId: string) => void;
public onNotice: (relay: Relay, events: Event[]) => void;
public readonly close: () => void = () => {
if (this.socket) {
this.manualClose = true;
this.socket.close();
}
};
public readonly sendEvent: (event: Event) => void = (event) => {
this.send(['EVENT', event]);
};
public readonly subscribe: (subId: string, filters?: RelayFilters) => void = (
subId,
filters = {},
) => {
const uuid = uuidv5(
`${subId}${JSON.stringify(filters)}`,
'57003344-b2cb-4b6f-a579-fae9e82c370a',
);
if (this.subscriptions[subId]?.includes(uuid)) {
console.log('Subscription already done!');
} else {
this.send(['REQ', subId, filters]);
const newSubscriptions = [...(this.subscriptions[subId] ?? []), uuid];
this.subscriptions[subId] = newSubscriptions;
}
};
public readonly unsubscribe: (subId: string) => void = (subId) => {
this.send(['CLOSE', subId]);
delete this.subscriptions[subId];
};
public readonly unsubscribeAll: () => void = () => {
Object.keys(this.subscriptions).forEach((subId: string) => {
this.send(['CLOSE', subId]);
});
this.subscriptions = {};
};
}
export default Relay;

View File

@ -0,0 +1,140 @@
import { signEvent, validateEvent, Event } from '../Events';
import Relay, { RelayFilters, RelayOptions } from '../Relay';
export interface OnFunctions {
open: { [id: string]: (relay: Relay) => void };
event: { [id: string]: (relay: Relay, subId: string, event: Event) => void };
esoe: { [id: string]: (relay: Relay, subId: string) => void };
notice: { [id: string]: (relay: Relay, events: Event[]) => void };
}
class RelayPool {
constructor(relaysUrls: string[], privateKey: string, options: RelayOptions = {}) {
this.relays = {};
this.privateKey = privateKey;
this.options = options;
this.onFunctions = {
open: {},
event: {},
esoe: {},
notice: {},
};
relaysUrls.forEach((relayUrl) => {
this.add(relayUrl);
});
this.setupHandlers();
}
private readonly privateKey: string;
private readonly options: RelayOptions;
private readonly onFunctions: OnFunctions;
public relays: { [url: string]: Relay };
private readonly setupHandlers: () => void = () => {
Object.keys(this.relays).forEach((relayUrl: string) => {
const relay: Relay = this.relays[relayUrl];
relay.onOpen = (openRelay) => {
Object.keys(this.onFunctions.open).forEach((id) => this.onFunctions.open[id](openRelay));
};
relay.onEvent = (eventRelay, subId, event) => {
Object.keys(this.onFunctions.event).forEach((id) =>
this.onFunctions.event[id](eventRelay, subId, event),
);
};
relay.onEsoe = (eventRelay, subId) => {
Object.keys(this.onFunctions.esoe).forEach((id) =>
this.onFunctions.esoe[id](eventRelay, subId),
);
};
relay.onNotice = (eventRelay, events) => {
Object.keys(this.onFunctions.notice).forEach((id) =>
this.onFunctions.notice[id](eventRelay, events),
);
};
});
};
public on: (
method: 'open' | 'event' | 'esoe' | 'notice',
id: string,
fn: (relay: Relay, subId?: string, event?: Event) => void,
) => void = (method, id, fn) => {
this.onFunctions[method][id] = fn;
};
public removeOn: (method: 'open' | 'event' | 'esoe' | 'notice', id: string) => void = (
method,
id,
) => {
delete this.onFunctions[method][id];
};
public readonly add: (relayUrl: string) => boolean = (relayUrl) => {
if (this.relays[relayUrl]) return false;
this.relays[relayUrl] = new Relay(relayUrl, this.options);
this.setupHandlers();
return true;
};
public readonly close: () => void = () => {
Object.keys(this.relays).forEach((relayUrl: string) => {
const relay: Relay = this.relays[relayUrl];
relay.close();
});
};
public readonly remove: (relayUrl: string) => boolean = (relayUrl) => {
const relay: Relay | undefined = this.relays[relayUrl];
if (relay) {
relay.close();
delete this.relays[relayUrl];
return true;
}
return false;
};
public readonly sendEvent: (event: Event) => Promise<Event | null> = async (event) => {
const signedEvent: Event = await signEvent(event, this.privateKey);
if (validateEvent(signedEvent)) {
Object.keys(this.relays).forEach((relayUrl: string) => {
const relay: Relay = this.relays[relayUrl];
relay.sendEvent(signedEvent);
});
return signedEvent
} else {
console.log('Not valid event', event);
}
return null
};
public readonly subscribe: (subId: string, filters?: RelayFilters) => void = (subId, filters) => {
Object.keys(this.relays).forEach((relayUrl: string) => {
this.relays[relayUrl].subscribe(subId, filters);
});
};
public readonly unsubscribe: (subId: string) => void = (subId) => {
Object.keys(this.relays).forEach((relayUrl: string) => {
this.relays[relayUrl].unsubscribe(subId);
});
};
public readonly unsubscribeAll: () => void = () => {
Object.keys(this.relays).forEach((relayUrl: string) => {
this.relays[relayUrl].unsubscribeAll();
});
};
}
export default RelayPool;

47
frontend/theme.json Normal file
View File

@ -0,0 +1,47 @@
{
"color-primary-100": "#D1EDFE",
"color-primary-200": "#A3D8FE",
"color-primary-300": "#74BEFC",
"color-primary-400": "#52A5FA",
"color-primary-500": "#1A7EF7",
"color-primary-600": "#1361D4",
"color-primary-700": "#0D48B1",
"color-primary-800": "#08328F",
"color-primary-900": "#042376",
"color-success-100": "#DFFED1",
"color-success-200": "#B7FEA3",
"color-success-300": "#86FC74",
"color-success-400": "#59FA52",
"color-success-500": "#1AF724",
"color-success-600": "#13D42C",
"color-success-700": "#0DB131",
"color-success-800": "#088F32",
"color-success-900": "#047632",
"color-info-100": "#D1FEF1",
"color-info-200": "#A3FEEB",
"color-info-300": "#74FCEB",
"color-info-400": "#52FAF3",
"color-info-500": "#1AEDF7",
"color-info-600": "#13BBD4",
"color-info-700": "#0D8EB1",
"color-info-800": "#08678F",
"color-info-900": "#044B76",
"color-warning-100": "#FEF2D1",
"color-warning-200": "#FEE1A3",
"color-warning-300": "#FCCB74",
"color-warning-400": "#FAB552",
"color-warning-500": "#F7931A",
"color-warning-600": "#D47413",
"color-warning-700": "#B1580D",
"color-warning-800": "#8F3F08",
"color-warning-900": "#762E04",
"color-danger-100": "#FFE4D8",
"color-danger-200": "#FFC3B2",
"color-danger-300": "#FF9B8B",
"color-danger-400": "#FF766F",
"color-danger-500": "#FF3F46",
"color-danger-600": "#DB2E43",
"color-danger-700": "#B71F40",
"color-danger-800": "#93143A",
"color-danger-900": "#7A0C37"
}

9
index.js Normal file
View File

@ -0,0 +1,9 @@
/**
* @format
*/
import { AppRegistry } from 'react-native';
import App from './App';
import { name as appName } from './app.json';
AppRegistry.registerComponent(appName, () => App);

29
ios/Podfile Normal file
View File

@ -0,0 +1,29 @@
require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
platform :ios, '10.0'
target 'nostros' do
config = use_native_modules!
use_react_native!(
:path => config[:reactNativePath],
# to enable hermes on iOS, change `false` to `true` and then install pods
:hermes_enabled => false
)
target 'nostrosTests' do
inherit! :complete
# Pods for testing
end
# Enables Flipper.
#
# Note that if you have use_frameworks! enabled, Flipper will not work and
# you should disable the next line.
use_flipper!()
post_install do |installer|
react_native_post_install(installer)
end
end

View File

@ -0,0 +1,563 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 54;
objects = {
/* Begin PBXBuildFile section */
00E356F31AD99517003FC87E /* nostrosTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 00E356F21AD99517003FC87E /* nostrosTests.m */; };
13B07FBC1A68108700A75B9A /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.m */; };
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; };
13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */; };
F0CC5BD283DA4FE282F1E5D8 /* SpaceGrotesk-Bold.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 056D5755DC9C471CB39B4A1F /* SpaceGrotesk-Bold.ttf */; };
3D3896E8C0E9405987C0B57B /* SpaceGrotesk-Light.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 4CC8B8FABAE64FE1911082A7 /* SpaceGrotesk-Light.ttf */; };
D03CA6C9567C4E6C8BAB8429 /* SpaceGrotesk-Medium.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 5463558C846C46E9A392CD22 /* SpaceGrotesk-Medium.ttf */; };
A6743A253DA345A3A0F60F89 /* SpaceGrotesk-Regular.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 99804F7DBF0B4CB6B99F71B3 /* SpaceGrotesk-Regular.ttf */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
00E356F41AD99517003FC87E /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 83CBB9F71A601CBA00E9B192 /* Project object */;
proxyType = 1;
remoteGlobalIDString = 13B07F861A680F5B00A75B9A;
remoteInfo = nostros;
};
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
00E356EE1AD99517003FC87E /* nostrosTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = nostrosTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
00E356F11AD99517003FC87E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
00E356F21AD99517003FC87E /* nostrosTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = nostrosTests.m; sourceTree = "<group>"; };
13B07F961A680F5B00A75B9A /* nostros.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = nostros.app; sourceTree = BUILT_PRODUCTS_DIR; };
13B07FAF1A68108700A75B9A /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AppDelegate.h; path = nostros/AppDelegate.h; sourceTree = "<group>"; };
13B07FB01A68108700A75B9A /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AppDelegate.m; path = nostros/AppDelegate.m; sourceTree = "<group>"; };
13B07FB51A68108700A75B9A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Images.xcassets; path = nostros/Images.xcassets; sourceTree = "<group>"; };
13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = nostros/Info.plist; sourceTree = "<group>"; };
13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = nostros/main.m; sourceTree = "<group>"; };
81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = LaunchScreen.storyboard; path = nostros/LaunchScreen.storyboard; sourceTree = "<group>"; };
ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
056D5755DC9C471CB39B4A1F /* SpaceGrotesk-Bold.ttf */ = {isa = PBXFileReference; name = "SpaceGrotesk-Bold.ttf"; path = "../assets/fonts/SpaceGrotesk-Bold.ttf"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = unknown; explicitFileType = undefined; includeInIndex = 0; };
4CC8B8FABAE64FE1911082A7 /* SpaceGrotesk-Light.ttf */ = {isa = PBXFileReference; name = "SpaceGrotesk-Light.ttf"; path = "../assets/fonts/SpaceGrotesk-Light.ttf"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = unknown; explicitFileType = undefined; includeInIndex = 0; };
5463558C846C46E9A392CD22 /* SpaceGrotesk-Medium.ttf */ = {isa = PBXFileReference; name = "SpaceGrotesk-Medium.ttf"; path = "../assets/fonts/SpaceGrotesk-Medium.ttf"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = unknown; explicitFileType = undefined; includeInIndex = 0; };
99804F7DBF0B4CB6B99F71B3 /* SpaceGrotesk-Regular.ttf */ = {isa = PBXFileReference; name = "SpaceGrotesk-Regular.ttf"; path = "../assets/fonts/SpaceGrotesk-Regular.ttf"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = unknown; explicitFileType = undefined; includeInIndex = 0; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
00E356EB1AD99517003FC87E /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
13B07F8C1A680F5B00A75B9A /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
00E356EF1AD99517003FC87E /* nostrosTests */ = {
isa = PBXGroup;
children = (
00E356F21AD99517003FC87E /* nostrosTests.m */,
00E356F01AD99517003FC87E /* Supporting Files */,
);
path = nostrosTests;
sourceTree = "<group>";
};
00E356F01AD99517003FC87E /* Supporting Files */ = {
isa = PBXGroup;
children = (
00E356F11AD99517003FC87E /* Info.plist */,
);
name = "Supporting Files";
sourceTree = "<group>";
};
13B07FAE1A68108700A75B9A /* nostros */ = {
isa = PBXGroup;
children = (
13B07FAF1A68108700A75B9A /* AppDelegate.h */,
13B07FB01A68108700A75B9A /* AppDelegate.m */,
13B07FB51A68108700A75B9A /* Images.xcassets */,
13B07FB61A68108700A75B9A /* Info.plist */,
81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */,
13B07FB71A68108700A75B9A /* main.m */,
);
name = nostros;
sourceTree = "<group>";
};
2D16E6871FA4F8E400B85C8A /* Frameworks */ = {
isa = PBXGroup;
children = (
ED297162215061F000B7C4FE /* JavaScriptCore.framework */,
);
name = Frameworks;
sourceTree = "<group>";
};
832341AE1AAA6A7D00B99B32 /* Libraries */ = {
isa = PBXGroup;
children = (
);
name = Libraries;
sourceTree = "<group>";
};
83CBB9F61A601CBA00E9B192 = {
isa = PBXGroup;
children = (
13B07FAE1A68108700A75B9A /* nostros */,
832341AE1AAA6A7D00B99B32 /* Libraries */,
00E356EF1AD99517003FC87E /* nostrosTests */,
83CBBA001A601CBA00E9B192 /* Products */,
2D16E6871FA4F8E400B85C8A /* Frameworks */,
8214B28D83464FB8B9B86BD0 /* Resources */,
);
indentWidth = 2;
sourceTree = "<group>";
tabWidth = 2;
usesTabs = 0;
};
83CBBA001A601CBA00E9B192 /* Products */ = {
isa = PBXGroup;
children = (
13B07F961A680F5B00A75B9A /* nostros.app */,
00E356EE1AD99517003FC87E /* nostrosTests.xctest */,
);
name = Products;
sourceTree = "<group>";
};
8214B28D83464FB8B9B86BD0 /* Resources */ = {
isa = "PBXGroup";
children = (
056D5755DC9C471CB39B4A1F /* SpaceGrotesk-Bold.ttf */,
4CC8B8FABAE64FE1911082A7 /* SpaceGrotesk-Light.ttf */,
5463558C846C46E9A392CD22 /* SpaceGrotesk-Medium.ttf */,
99804F7DBF0B4CB6B99F71B3 /* SpaceGrotesk-Regular.ttf */,
);
name = Resources;
sourceTree = "<group>";
path = "";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
00E356ED1AD99517003FC87E /* nostrosTests */ = {
isa = PBXNativeTarget;
buildConfigurationList = 00E357021AD99517003FC87E /* Build configuration list for PBXNativeTarget "nostrosTests" */;
buildPhases = (
00E356EA1AD99517003FC87E /* Sources */,
00E356EB1AD99517003FC87E /* Frameworks */,
00E356EC1AD99517003FC87E /* Resources */,
);
buildRules = (
);
dependencies = (
00E356F51AD99517003FC87E /* PBXTargetDependency */,
);
name = nostrosTests;
productName = nostrosTests;
productReference = 00E356EE1AD99517003FC87E /* nostrosTests.xctest */;
productType = "com.apple.product-type.bundle.unit-test";
};
13B07F861A680F5B00A75B9A /* nostros */ = {
isa = PBXNativeTarget;
buildConfigurationList = 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "nostros" */;
buildPhases = (
FD10A7F022414F080027D42C /* Start Packager */,
13B07F871A680F5B00A75B9A /* Sources */,
13B07F8C1A680F5B00A75B9A /* Frameworks */,
13B07F8E1A680F5B00A75B9A /* Resources */,
00DD1BFF1BD5951E006B06BC /* Bundle React Native code and images */,
);
buildRules = (
);
dependencies = (
);
name = nostros;
productName = nostros;
productReference = 13B07F961A680F5B00A75B9A /* nostros.app */;
productType = "com.apple.product-type.application";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
83CBB9F71A601CBA00E9B192 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1210;
TargetAttributes = {
00E356ED1AD99517003FC87E = {
CreatedOnToolsVersion = 6.2;
TestTargetID = 13B07F861A680F5B00A75B9A;
};
13B07F861A680F5B00A75B9A = {
LastSwiftMigration = 1120;
};
};
};
buildConfigurationList = 83CBB9FA1A601CBA00E9B192 /* Build configuration list for PBXProject "nostros" */;
compatibilityVersion = "Xcode 12.0";
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = 83CBB9F61A601CBA00E9B192;
productRefGroup = 83CBBA001A601CBA00E9B192 /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
13B07F861A680F5B00A75B9A /* nostros */,
00E356ED1AD99517003FC87E /* nostrosTests */,
);
};
/* End PBXProject section */
/* Begin PBXResourcesBuildPhase section */
00E356EC1AD99517003FC87E /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
13B07F8E1A680F5B00A75B9A /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */,
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */,
F0CC5BD283DA4FE282F1E5D8 /* SpaceGrotesk-Bold.ttf in Resources */,
3D3896E8C0E9405987C0B57B /* SpaceGrotesk-Light.ttf in Resources */,
D03CA6C9567C4E6C8BAB8429 /* SpaceGrotesk-Medium.ttf in Resources */,
A6743A253DA345A3A0F60F89 /* SpaceGrotesk-Regular.ttf in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */
/* Begin PBXShellScriptBuildPhase section */
00DD1BFF1BD5951E006B06BC /* Bundle React Native code and images */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Bundle React Native code and images";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "set -e\n\nexport NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh\n";
};
FD10A7F022414F080027D42C /* Start Packager */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
name = "Start Packager";
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "export RCT_METRO_PORT=\"${RCT_METRO_PORT:=8081}\"\necho \"export RCT_METRO_PORT=${RCT_METRO_PORT}\" > \"${SRCROOT}/../node_modules/react-native/scripts/.packager.env\"\nif [ -z \"${RCT_NO_LAUNCH_PACKAGER+xxx}\" ] ; then\n if nc -w 5 -z localhost ${RCT_METRO_PORT} ; then\n if ! curl -s \"http://localhost:${RCT_METRO_PORT}/status\" | grep -q \"packager-status:running\" ; then\n echo \"Port ${RCT_METRO_PORT} already in use, packager is either not running or not running correctly\"\n exit 2\n fi\n else\n open \"$SRCROOT/../node_modules/react-native/scripts/launchPackager.command\" || echo \"Can't start packager automatically\"\n fi\nfi\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
00E356EA1AD99517003FC87E /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
00E356F31AD99517003FC87E /* nostrosTests.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
13B07F871A680F5B00A75B9A /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
13B07FBC1A68108700A75B9A /* AppDelegate.m in Sources */,
13B07FC11A68108700A75B9A /* main.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin PBXTargetDependency section */
00E356F51AD99517003FC87E /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 13B07F861A680F5B00A75B9A /* nostros */;
targetProxy = 00E356F41AD99517003FC87E /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */
/* Begin XCBuildConfiguration section */
00E356F61AD99517003FC87E /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
INFOPLIST_FILE = nostrosTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
OTHER_LDFLAGS = (
"-ObjC",
"-lc++",
"$(inherited)",
);
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/nostros.app/nostros";
};
name = Debug;
};
00E356F71AD99517003FC87E /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
COPY_PHASE_STRIP = NO;
INFOPLIST_FILE = nostrosTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
OTHER_LDFLAGS = (
"-ObjC",
"-lc++",
"$(inherited)",
);
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/nostros.app/nostros";
};
name = Release;
};
13B07F941A680F5B00A75B9A /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 1;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = nostros/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
OTHER_LDFLAGS = (
"$(inherited)",
"-ObjC",
"-lc++",
);
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = nostros;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
VERSIONING_SYSTEM = "apple-generic";
};
name = Debug;
};
13B07F951A680F5B00A75B9A /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 1;
INFOPLIST_FILE = nostros/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
OTHER_LDFLAGS = (
"$(inherited)",
"-ObjC",
"-lc++",
);
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = nostros;
SWIFT_VERSION = 5.0;
VERSIONING_SYSTEM = "apple-generic";
};
name = Release;
};
83CBBA201A601CBA00E9B192 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = (
/usr/lib/swift,
"$(inherited)",
);
LIBRARY_SEARCH_PATHS = (
"\"$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)\"",
"\"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)\"",
"\"$(inherited)\"",
);
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
};
name = Debug;
};
83CBBA211A601CBA00E9B192 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = YES;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = (
/usr/lib/swift,
"$(inherited)",
);
LIBRARY_SEARCH_PATHS = (
"\"$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)\"",
"\"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)\"",
"\"$(inherited)\"",
);
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
VALIDATE_PRODUCT = YES;
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
00E357021AD99517003FC87E /* Build configuration list for PBXNativeTarget "nostrosTests" */ = {
isa = XCConfigurationList;
buildConfigurations = (
00E356F61AD99517003FC87E /* Debug */,
00E356F71AD99517003FC87E /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "nostros" */ = {
isa = XCConfigurationList;
buildConfigurations = (
13B07F941A680F5B00A75B9A /* Debug */,
13B07F951A680F5B00A75B9A /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
83CBB9FA1A601CBA00E9B192 /* Build configuration list for PBXProject "nostros" */ = {
isa = XCConfigurationList;
buildConfigurations = (
83CBBA201A601CBA00E9B192 /* Debug */,
83CBBA211A601CBA00E9B192 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 83CBB9F71A601CBA00E9B192 /* Project object */;
}

View File

@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1210"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "13B07F861A680F5B00A75B9A"
BuildableName = "nostros.app"
BlueprintName = "nostros"
ReferencedContainer = "container:nostros.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "00E356ED1AD99517003FC87E"
BuildableName = "nostrosTests.xctest"
BlueprintName = "nostrosTests"
ReferencedContainer = "container:nostros.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "13B07F861A680F5B00A75B9A"
BuildableName = "nostros.app"
BlueprintName = "nostros"
ReferencedContainer = "container:nostros.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "13B07F861A680F5B00A75B9A"
BuildableName = "nostros.app"
BlueprintName = "nostros"
ReferencedContainer = "container:nostros.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@ -0,0 +1,8 @@
#import <React/RCTBridgeDelegate.h>
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate>
@property (nonatomic, strong) UIWindow *window;
@end

62
ios/nostros/AppDelegate.m Normal file
View File

@ -0,0 +1,62 @@
#import "AppDelegate.h"
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#ifdef FB_SONARKIT_ENABLED
#import <FlipperKit/FlipperClient.h>
#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
#import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
#import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>
#import <FlipperKitReactPlugin/FlipperKitReactPlugin.h>
static void InitializeFlipper(UIApplication *application) {
FlipperClient *client = [FlipperClient sharedClient];
SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults];
[client addPlugin:[[FlipperKitLayoutPlugin alloc] initWithRootNode:application withDescriptorMapper:layoutDescriptorMapper]];
[client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]];
[client addPlugin:[FlipperKitReactPlugin new]];
[client addPlugin:[[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]];
[client start];
}
#endif
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
#ifdef FB_SONARKIT_ENABLED
InitializeFlipper(application);
#endif
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
moduleName:@"nostros"
initialProperties:nil];
if (@available(iOS 13.0, *)) {
rootView.backgroundColor = [UIColor systemBackgroundColor];
} else {
rootView.backgroundColor = [UIColor whiteColor];
}
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = [UIViewController new];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
return YES;
}
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}
@end

View File

@ -0,0 +1,38 @@
{
"images": [
{
"idiom": "iphone",
"size": "29x29",
"scale": "2x"
},
{
"idiom": "iphone",
"size": "29x29",
"scale": "3x"
},
{
"idiom": "iphone",
"size": "40x40",
"scale": "2x"
},
{
"idiom": "iphone",
"size": "40x40",
"scale": "3x"
},
{
"idiom": "iphone",
"size": "60x60",
"scale": "2x"
},
{
"idiom": "iphone",
"size": "60x60",
"scale": "3x"
}
],
"info": {
"version": 1,
"author": "xcode"
}
}

View File

@ -0,0 +1,6 @@
{
"info": {
"version": 1,
"author": "xcode"
}
}

62
ios/nostros/Info.plist Normal file
View File

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>nostros</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>localhost</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
</dict>
<key>NSLocationWhenInUseUsageDescription</key>
<string/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>UIAppFonts</key>
<array>
<string>SpaceGrotesk-Bold.ttf</string>
<string>SpaceGrotesk-Light.ttf</string>
<string>SpaceGrotesk-Medium.ttf</string>
<string>SpaceGrotesk-Regular.ttf</string>
</array>
</dict>
</plist>

View File

@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="15702" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15704"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="EHf-IW-A2E">
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="nostros" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="GJd-Yh-RWb">
<rect key="frame" x="0.0" y="202" width="375" height="43"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="36"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Powered by React Native" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="MN2-I3-ftu">
<rect key="frame" x="0.0" y="626" width="375" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<constraints>
<constraint firstItem="Bcu-3y-fUS" firstAttribute="bottom" secondItem="MN2-I3-ftu" secondAttribute="bottom" constant="20" id="OZV-Vh-mqD"/>
<constraint firstItem="Bcu-3y-fUS" firstAttribute="centerX" secondItem="GJd-Yh-RWb" secondAttribute="centerX" id="Q3B-4B-g5h"/>
<constraint firstItem="MN2-I3-ftu" firstAttribute="centerX" secondItem="Bcu-3y-fUS" secondAttribute="centerX" id="akx-eg-2ui"/>
<constraint firstItem="MN2-I3-ftu" firstAttribute="leading" secondItem="Bcu-3y-fUS" secondAttribute="leading" id="i1E-0Y-4RG"/>
<constraint firstItem="GJd-Yh-RWb" firstAttribute="centerY" secondItem="Ze5-6b-2t3" secondAttribute="bottom" multiplier="1/3" constant="1" id="moa-c2-u7t"/>
<constraint firstItem="GJd-Yh-RWb" firstAttribute="leading" secondItem="Bcu-3y-fUS" secondAttribute="leading" symbolic="YES" id="x7j-FC-K8j"/>
</constraints>
<viewLayoutGuide key="safeArea" id="Bcu-3y-fUS"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="52.173913043478265" y="375"/>
</scene>
</scenes>
</document>

9
ios/nostros/main.m Normal file
View File

@ -0,0 +1,9 @@
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char * argv[]) {
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>

View File

@ -0,0 +1,65 @@
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
#import <React/RCTLog.h>
#import <React/RCTRootView.h>
#define TIMEOUT_SECONDS 600
#define TEXT_TO_LOOK_FOR @"Welcome to React"
@interface nostrosTests : XCTestCase
@end
@implementation nostrosTests
- (BOOL)findSubviewInView:(UIView *)view matching:(BOOL(^)(UIView *view))test
{
if (test(view)) {
return YES;
}
for (UIView *subview in [view subviews]) {
if ([self findSubviewInView:subview matching:test]) {
return YES;
}
}
return NO;
}
- (void)testRendersWelcomeScreen
{
UIViewController *vc = [[[RCTSharedApplication() delegate] window] rootViewController];
NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS];
BOOL foundElement = NO;
__block NSString *redboxError = nil;
#ifdef DEBUG
RCTSetLogFunction(^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) {
if (level >= RCTLogLevelError) {
redboxError = message;
}
});
#endif
while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) {
[[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
[[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
foundElement = [self findSubviewInView:vc.view matching:^BOOL(UIView *view) {
if ([view.accessibilityLabel isEqualToString:TEXT_TO_LOOK_FOR]) {
return YES;
}
return NO;
}];
}
#ifdef DEBUG
RCTSetLogFunction(RCTDefaultLogFunction);
#endif
XCTAssertNil(redboxError, @"RedBox error: %@", redboxError);
XCTAssertTrue(foundElement, @"Couldn't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS);
}
@end

26
metro.config.js Normal file
View File

@ -0,0 +1,26 @@
/**
* Metro configuration for React Native
* https://github.com/facebook/react-native
*
* @format
*/
const MetroConfig = require('@ui-kitten/metro-config');
/**
* @see https://akveo.github.io/react-native-ui-kitten/docs/guides/improving-performance
*/
const evaConfig = {
evaPackage: '@eva-design/eva',
};
module.exports = MetroConfig.create(evaConfig, {
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: false,
},
}),
},
});

87
package.json Normal file
View File

@ -0,0 +1,87 @@
{
"name": "nostros",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
"format": "eslint --fix '**/**/*.{js,ts,tsx}' && prettier --write '**/**/*.{js,jsx,ts,tsx,css,md,json}' --config ./.prettierrc"
},
"dependencies": {
"@eva-design/eva": "^2.1.0",
"@ui-kitten/components": "5.1.2",
"@ui-kitten/eva-icons": "5.1.2",
"@ui-kitten/metro-config": "5.1.2",
"assert": "^2.0.0",
"bip-schnorr": "^0.6.6",
"buffer": "^6.0.3",
"create-hash": "^1.2.0",
"events": "^3.3.0",
"i18next": "^21.10.0",
"moment": "^2.29.4",
"react": "17.0.1",
"react-i18next": "^11.18.6",
"react-native": "0.64.1",
"react-native-action-button": "^2.8.5",
"react-native-encrypted-storage": "^4.0.2",
"react-native-flash-message": "^0.3.1",
"react-native-markdown-display": "^7.0.0-alpha.2",
"react-native-sqlite-storage": "^6.0.1",
"react-native-svg": "^13.4.0",
"react-native-user-avatar": "^1.0.8",
"react-native-vector-icons": "^9.2.0",
"react-native-webview": "^11.23.1",
"safe-buffer": "^5.2.1",
"sqlstring": "^2.3.3",
"stream": "^0.0.2",
"uuid": "^9.0.0"
},
"devDependencies": {
"@babel/core": "^7.12.9",
"@babel/runtime": "^7.12.5",
"@react-native-community/eslint-config": "^2.0.0",
"@types/create-hash": "^1.2.2",
"@types/jest": "^26.0.23",
"@types/react-native": "^0.64.5",
"@types/react-native-sqlite-storage": "^5.0.2",
"@types/react-native-vector-icons": "^6.4.12",
"@types/react-test-renderer": "^16.9.2",
"@types/sqlstring": "^2.3.0",
"@types/uuid": "^8.3.4",
"@typescript-eslint/eslint-plugin": "^5.40.0",
"babel-jest": "^26.6.3",
"eslint": "^7.14.0",
"eslint-config-prettier": "^8.5.0",
"eslint-config-standard-with-typescript": "^23.0.0",
"eslint-import-resolver-typescript": "^3.5.1",
"eslint-plugin-i18next": "^6.0.0-4",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-n": "^15.3.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-promise": "^6.1.0",
"eslint-plugin-react": "^7.31.10",
"eslint-plugin-react-hooks": "^4.6.0",
"jest": "^26.6.3",
"metro-react-native-babel-preset": "^0.64.0",
"prettier": "^2.7.1",
"react-test-renderer": "17.0.1",
"typescript": "^3.8.3"
},
"resolutions": {
"@types/react": "^17"
},
"jest": {
"preset": "react-native",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
]
}
}

7
react-native.config.js Normal file
View File

@ -0,0 +1,7 @@
module.exports = {
project: {
ios: {},
android: {},
},
assets: ['./assets/fonts/'],
};

60
tsconfig.json Normal file
View File

@ -0,0 +1,60 @@
{
"compilerOptions": {
/* Basic Options */
"target": "esnext" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
"lib": ["es2017"] /* Specify library files to be included in the compilation. */,
"allowJs": true /* Allow javascript files to be compiled. */,
// "checkJs": true, /* Report errors in .js files. */
"jsx": "react-native" /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */,
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
// "outDir": "./", /* Redirect output structure to the directory. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "removeComments": true, /* Do not emit comments to output. */
"noEmit": true /* Do not emit outputs. */,
// "incremental": true, /* Enable incremental compilation */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
"isolatedModules": true /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */,
/* Strict Type-Checking Options */
"strict": true /* Enable all strict type-checking options. */,
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
"moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
"allowSyntheticDefaultImports": true /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */,
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
"skipLibCheck": false /* Skip type checking of declaration files. */,
"resolveJsonModule": true
/* Source Map Options */
// "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
},
"exclude": ["node_modules", "babel.config.js", "metro.config.js", "jest.config.js"]
}

7860
yarn.lock Normal file

File diff suppressed because it is too large Load Diff