mirror of
https://github.com/RoboSats/robosats.git
synced 2025-01-31 02:21:35 +00:00
Android robohash generator
This commit is contained in:
parent
66e9fc46c5
commit
4b572d0171
@ -3,9 +3,8 @@ import SmoothImage from 'react-smooth-image';
|
||||
import { Avatar, Badge, Tooltip } from '@mui/material';
|
||||
import { SendReceiveIcon } from '../Icons';
|
||||
import placeholder from './placeholder.json';
|
||||
// import { robohash } from './RobohashGenerator';
|
||||
import { AppContext, type UseAppStoreType } from '../../contexts/AppContext';
|
||||
import { roboidentitiesClient } from '../../services/Roboidentities';
|
||||
import { roboidentitiesClient } from '../../services/Roboidentities/Web';
|
||||
|
||||
interface Props {
|
||||
shortAlias?: string | undefined;
|
||||
|
@ -6,12 +6,11 @@ import {
|
||||
type Order,
|
||||
type Garage,
|
||||
} from '.';
|
||||
import { roboidentitiesClient } from '../services/Roboidentities';
|
||||
import { roboidentitiesClient } from '../services/Roboidentities/Web';
|
||||
import { apiClient } from '../services/api';
|
||||
import { validateTokenEntropy } from '../utils';
|
||||
import { compareUpdateLimit } from './Limit.model';
|
||||
import { defaultOrder } from './Order.model';
|
||||
// import { robohash } from '../components/RobotAvatar/RobohashGenerator';
|
||||
|
||||
export interface Contact {
|
||||
nostr?: string | undefined;
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { sha256 } from 'js-sha256';
|
||||
import { Robot, type Order } from '.';
|
||||
// import { robohash } from '../components/RobotAvatar/RobohashGenerator';
|
||||
import { roboidentitiesClient } from '../services/Roboidentities';
|
||||
import { roboidentitiesClient } from '../services/Roboidentities/Web';
|
||||
|
||||
class Slot {
|
||||
constructor(token: string, shortAliases: string[], robotAttributes: Record<any, any>) {
|
||||
|
4
frontend/src/services/Roboidentities/Native.ts
Normal file
4
frontend/src/services/Roboidentities/Native.ts
Normal file
@ -0,0 +1,4 @@
|
||||
import RoboidentitiesClientNativeClient from './RoboidentitiesNativeClient';
|
||||
import { RoboidentitiesClient } from './type';
|
||||
|
||||
export const roboidentitiesClient: RoboidentitiesClient = new RoboidentitiesClientNativeClient();
|
@ -1,4 +1,4 @@
|
||||
import { type RoboidentitiesClient } from '..';
|
||||
import { type RoboidentitiesClient } from '../type';
|
||||
|
||||
class RoboidentitiesNativeClient implements RoboidentitiesClient {
|
||||
private robonames: Record<string, string> = {};
|
||||
@ -19,10 +19,8 @@ class RoboidentitiesNativeClient implements RoboidentitiesClient {
|
||||
}
|
||||
};
|
||||
|
||||
public generateRobohash: (initialString: string, size: string) => Promise<string> = async (
|
||||
initialString,
|
||||
size,
|
||||
) => {
|
||||
public generateRobohash: (initialString: string, size: 'small' | 'large') => Promise<string> =
|
||||
async (initialString, size) => {
|
||||
const key = `${initialString};${size === 'small' ? 80 : 256}`;
|
||||
|
||||
if (this.robohashes[key]) {
|
||||
|
@ -1,20 +1,17 @@
|
||||
import { type RoboidentitiesClient } from '..';
|
||||
// import { generate_roboname } from 'robo-identities-wasm';
|
||||
import { type RoboidentitiesClient } from '../type';
|
||||
import { generate_roboname } from 'robo-identities-wasm';
|
||||
import { robohash } from './RobohashGenerator';
|
||||
|
||||
class RoboidentitiesClientWebClient implements RoboidentitiesClient {
|
||||
public generateRoboname: (initialString: string) => Promise<string> = async (initialString) => {
|
||||
return new Promise<string>(async (resolve, _reject) => {
|
||||
// resolve(generate_roboname(initialString))
|
||||
resolve(generate_roboname(initialString));
|
||||
});
|
||||
};
|
||||
|
||||
public generateRobohash: (initialString: string, size: string) => Promise<string> = async (
|
||||
initialString,
|
||||
size,
|
||||
) => {
|
||||
return new Promise<string>(async (resolve, _reject) => {
|
||||
// resolve(generate_roboname(initialString))
|
||||
});
|
||||
public generateRobohash: (initialString: string, size: 'small' | 'large') => Promise<string> =
|
||||
async (initialString, size) => {
|
||||
return robohash.generate(initialString, size);
|
||||
};
|
||||
}
|
||||
|
||||
|
4
frontend/src/services/Roboidentities/Web.ts
Normal file
4
frontend/src/services/Roboidentities/Web.ts
Normal file
@ -0,0 +1,4 @@
|
||||
import RoboidentitiesClientWebClient from './RoboidentitiesWebClient';
|
||||
import { RoboidentitiesClient } from './type';
|
||||
|
||||
export const roboidentitiesClient: RoboidentitiesClient = new RoboidentitiesClientWebClient();
|
@ -1,14 +0,0 @@
|
||||
import RoboidentitiesClientNativeClient from './RoboidentitiesNativeClient';
|
||||
import RoboidentitiesClientWebClient from './RoboidentitiesWebClient';
|
||||
|
||||
export interface RoboidentitiesClient {
|
||||
generateRoboname: (initialString: string) => Promise<string>;
|
||||
generateRobohash: (initialString: string, size: string) => Promise<string>;
|
||||
}
|
||||
|
||||
export const roboidentitiesClient: RoboidentitiesClient =
|
||||
// If userAgent has "RoboSats", we assume the app is running inside of the
|
||||
// react-native-web view of the RoboSats Android app.
|
||||
window.navigator.userAgent.includes('robosats')
|
||||
? new RoboidentitiesClientNativeClient()
|
||||
: new RoboidentitiesClientWebClient();
|
4
frontend/src/services/Roboidentities/type.ts
Normal file
4
frontend/src/services/Roboidentities/type.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export interface RoboidentitiesClient {
|
||||
generateRoboname: (initialString: string) => Promise<string>;
|
||||
generateRobohash: (initialString: string, size: 'small' | 'large') => Promise<string>;
|
||||
}
|
@ -56,6 +56,15 @@ const configMobile: Configuration = {
|
||||
async: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
test: path.resolve(__dirname, 'src/services/Roboidentities/Web.ts'),
|
||||
loader: 'file-replace-loader',
|
||||
options: {
|
||||
condition: 'if-replacement-exists',
|
||||
replacement: path.resolve(__dirname, 'src/services/Roboidentities/Native.ts'),
|
||||
async: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
test: path.resolve(__dirname, 'src/components/RobotAvatar/placeholder.json'),
|
||||
loader: 'file-replace-loader',
|
||||
|
Loading…
Reference in New Issue
Block a user