Skip to content

Commit

Permalink
Merge pull request #85 from berty/misc-polish
Browse files Browse the repository at this point in the history
fix: misc polish
  • Loading branch information
n0izn0iz authored Mar 1, 2022
2 parents e5756b2 + 5c5400d commit ea45015
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 13 deletions.
1 change: 1 addition & 0 deletions rn/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ module.exports = {
},
},
],
'@babel/plugin-proposal-numeric-separator',
],
}
5 changes: 4 additions & 1 deletion rn/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@react-navigation/native-stack": "^6.5.0",
"@reduxjs/toolkit": "^1.7.2",
"buffer": "^6.0.3",
"color": "^4.2.1",
"expo": "^44.0.6",
"expo-file-system": "^13.1.4",
"google-protobuf": "^3.19.4",
Expand All @@ -36,9 +37,11 @@
"devDependencies": {
"@babel/core": "^7.17.5",
"@babel/plugin-proposal-export-namespace-from": "^7.16.7",
"@babel/plugin-proposal-numeric-separator": "^7.16.7",
"@babel/preset-env": "^7.1.8",
"@babel/runtime": "^7.12.5",
"@react-native-community/eslint-config": "^3.0.1",
"@types/color": "^3.0.3",
"@types/google-protobuf": "^3.15.5",
"@types/jest": "^27.4.0",
"@types/node": "^17.0.17",
Expand Down Expand Up @@ -76,4 +79,4 @@
"node"
]
}
}
}
7 changes: 6 additions & 1 deletion rn/src/components/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
TextInputProps,
PressableProps,
} from 'react-native'
import Color from 'color'

import { defaultColors } from '@berty-labs/styles'

Expand Down Expand Up @@ -102,7 +103,11 @@ export const TextInputCard: React.FC<
return (
<Card style={style}>
<View style={rowStyle}>
<TextInput style={textInputStyle} {...props} />
<TextInput
style={textInputStyle}
placeholderTextColor={Color(defaultColors.text).alpha(0.5).hexa()}
{...props}
/>
{typeof onConfirm === 'function' && (
<Pressable onPress={onConfirm}>
<Text style={textStyle}>{confirmText}</Text>
Expand Down
2 changes: 1 addition & 1 deletion rn/src/reactutil/useAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const useAsyncTransform = <
start()
return () => {
ac.abort()
setResult([undefined, true, undefined])
setResult([undefined, false, undefined])
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [memoizedTransform, ...(args || [])])
Expand Down
12 changes: 11 additions & 1 deletion rn/src/screens/Browser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const URLInput: React.FC<
placeholder='Enter address...'
autoCapitalize='none'
autoCorrect={false}
style={{ marginHorizontal: space, marginBottom: space }}
textSize={20}
{...props}
/>
Expand All @@ -33,14 +34,23 @@ const URLInput: React.FC<

const PageLoader = () => <LoaderScreen text='Rendering page...' />

const uriSchemeRegexp = /$\w+:\/\//

const uriForceHTTPS = (uri: string) => {
if (uri.match(uriSchemeRegexp)) {
return uri
}
return 'https://' + uri
}

export const Browser: ScreenFC<'Browser'> = () => {
const mobileIPFS = useGomobileIPFS()
const [localError, setLocalError] = useState('')
const [entryURI, setEntryURI] = useState('')
const [loaded, setLoaded] = useState(false)
const [uri, setURI] = useState('')
const handleConfirm = React.useCallback(() => {
setURI(entryURI)
setURI(uriForceHTTPS(entryURI))
}, [entryURI])

if (mobileIPFS.status !== 'up') {
Expand Down
18 changes: 10 additions & 8 deletions rn/src/screens/Wikipedia.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,18 @@ const cardStyle = { marginTop: space, marginHorizontal: space }

const ipn = '/ipns/en.wikipedia-on-ipfs.org'

type IPFSResolved = {
Path?: string
}

export const Wikipedia: ScreenFC<'Wikipedia'> = () => {
const mobileIPFS = useGomobileIPFS()
const [localError, setLocalError] = useState('')
const [loaded, setLoaded] = useState(false)
const [showResolveError, setShowResolveError] = useState(false)
const [inputArticle, setInputArticle] = useState('')
const [targetArticle, setTargetArticle] = useState('')
const [resolvedCID, loadedCID, resolveErr] = useAsyncTransform(
const [freshCID, resolving, resolveErr] = useAsyncTransform(
async (ac: AbortController) => {
if (!mobileIPFS.apiURL) {
return
Expand All @@ -64,14 +68,14 @@ export const Wikipedia: ScreenFC<'Wikipedia'> = () => {
if (!reply.ok) {
throw new Error(`Unexpected status: ${reply.status}\n${await reply.text()}`)
}
const text = await reply.text()
console.log('resolved:', text)
return text
const r: IPFSResolved = await reply.json()
console.log('resolved:', r)
return r.Path
},
[mobileIPFS.apiURL],
)

const cid = resolvedCID || fallbackCID
const cid = freshCID || fallbackCID

if (mobileIPFS.status !== 'up') {
return <LoaderScreen text='Waiting for IPFS node...' />
Expand Down Expand Up @@ -105,9 +109,7 @@ export const Wikipedia: ScreenFC<'Wikipedia'> = () => {
<Text style={{ color: defaultColors.text }}>{`${resolveErr}`}</Text>
</Card>
)}
{!loadedCID && !resolveErr && (
<LoaderCard style={cardStyle} text='Resolving content identifier...' />
)}
{resolving && <LoaderCard style={cardStyle} text='Resolving content identifier...' />}
{!loaded && <LoaderCard style={cardStyle} text='Loading page...' />}
<WebView
style={{
Expand Down
49 changes: 48 additions & 1 deletion rn/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2229,6 +2229,25 @@
dependencies:
"@babel/types" "^7.3.0"

"@types/color-convert@*":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@types/color-convert/-/color-convert-2.0.0.tgz#8f5ee6b9e863dcbee5703f5a517ffb13d3ea4e22"
integrity sha512-m7GG7IKKGuJUXvkZ1qqG3ChccdIM/qBBo913z+Xft0nKCX4hAU/IxKwZBU4cpRZ7GS5kV4vOblUkILtSShCPXQ==
dependencies:
"@types/color-name" "*"

"@types/color-name@*":
version "1.1.1"
resolved "https://registry.yarnpkg.com/@types/color-name/-/color-name-1.1.1.tgz#1c1261bbeaa10a8055bbc5d8ab84b7b2afc846a0"
integrity sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==

"@types/color@^3.0.3":
version "3.0.3"
resolved "https://registry.yarnpkg.com/@types/color/-/color-3.0.3.tgz#e6d8d72b7aaef4bb9fe80847c26c7c786191016d"
integrity sha512-X//qzJ3d3Zj82J9sC/C18ZY5f43utPbAJ6PhYt/M7uG6etcF6MRpKdN880KBy43B0BMzSfeT96MzrsNjFI3GbA==
dependencies:
"@types/color-convert" "*"

"@types/google-protobuf@^3.15.5":
version "3.15.5"
resolved "https://registry.yarnpkg.com/@types/google-protobuf/-/google-protobuf-3.15.5.tgz#644b2be0f5613b1f822c70c73c6b0e0b5b5fa2ad"
Expand Down Expand Up @@ -3459,11 +3478,27 @@ [email protected]:
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25"
integrity sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=

color-name@~1.1.4:
color-name@^1.0.0, color-name@~1.1.4:
version "1.1.4"
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2"
integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==

color-string@^1.9.0:
version "1.9.0"
resolved "https://registry.yarnpkg.com/color-string/-/color-string-1.9.0.tgz#63b6ebd1bec11999d1df3a79a7569451ac2be8aa"
integrity sha512-9Mrz2AQLefkH1UvASKj6v6hj/7eWgjnT/cVsR8CumieLoT+g900exWeNogqtweI8dxloXN9BDQTYro1oWu/5CQ==
dependencies:
color-name "^1.0.0"
simple-swizzle "^0.2.2"

color@^4.2.1:
version "4.2.1"
resolved "https://registry.yarnpkg.com/color/-/color-4.2.1.tgz#498aee5fce7fc982606c8875cab080ac0547c884"
integrity sha512-MFJr0uY4RvTQUKvPq7dh9grVOTYSFeXja2mBXioCGjnjJoXrAp9jJ1NQTDR73c9nwBSAQiNKloKl5zq9WB9UPw==
dependencies:
color-convert "^2.0.1"
color-string "^1.9.0"

colorette@^1.0.7:
version "1.4.0"
resolved "https://registry.yarnpkg.com/colorette/-/colorette-1.4.0.tgz#5190fbb87276259a86ad700bff2c6d6faa3fca40"
Expand Down Expand Up @@ -5434,6 +5469,11 @@ is-arrayish@^0.2.1:
resolved "https://registry.yarnpkg.com/is-arrayish/-/is-arrayish-0.2.1.tgz#77c99840527aa8ecb1a8ba697b80645a7a926a9d"
integrity sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0=

is-arrayish@^0.3.1:
version "0.3.2"
resolved "https://registry.yarnpkg.com/is-arrayish/-/is-arrayish-0.3.2.tgz#4574a2ae56f7ab206896fb431eaeed066fdf8f03"
integrity sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ==

is-bigint@^1.0.1:
version "1.0.4"
resolved "https://registry.yarnpkg.com/is-bigint/-/is-bigint-1.0.4.tgz#08147a1875bc2b32005d41ccd8291dffc6691df3"
Expand Down Expand Up @@ -8727,6 +8767,13 @@ simple-plist@^1.0.0, simple-plist@^1.1.0:
bplist-parser "0.3.0"
plist "^3.0.4"

simple-swizzle@^0.2.2:
version "0.2.2"
resolved "https://registry.yarnpkg.com/simple-swizzle/-/simple-swizzle-0.2.2.tgz#a4da6b635ffcccca33f70d17cb92592de95e557a"
integrity sha1-pNprY1/8zMoz9w0Xy5JZLeleVXo=
dependencies:
is-arrayish "^0.3.1"

sisteransi@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/sisteransi/-/sisteransi-1.0.5.tgz#134d681297756437cc05ca01370d3a7a571075ed"
Expand Down

0 comments on commit ea45015

Please sign in to comment.