Skip to content

Commit ae63f9e

Browse files
committed
Preop bio, add clickable transaction hash
1 parent 6a1552a commit ae63f9e

1 file changed

Lines changed: 28 additions & 2 deletions

File tree

  • packages/mobile/examples/authenticated-writes

packages/mobile/examples/authenticated-writes/App.tsx

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export default function App() {
2727
const [description, setDescription] = useState('')
2828
const [updateLoading, setUpdateLoading] = useState(false)
2929
const [result, setResult] = useState<string | null>(null)
30+
const [txHash, setTxHash] = useState<string | null>(null)
3031
const oauthStateRef = useRef<string | null>(null)
3132

3233
const handleOpenAuth = useCallback(() => {
@@ -65,6 +66,14 @@ export default function App() {
6566
setProfile({ handle: data.handle ?? data.sub ?? 'Unknown' })
6667
setUserId(uid)
6768
setScreen('signed-in')
69+
// Prepopulate bio from current profile
70+
try {
71+
const userRes = await getSDK().users.getUser({ id: uid })
72+
const bio = userRes.data?.bio
73+
setDescription(bio ?? '')
74+
} catch {
75+
setDescription('')
76+
}
6877
} catch (e: unknown) {
6978
if (e && typeof e === 'object' && 'response' in e && e.response && typeof (e.response as Response).text === 'function') {
7079
const res = e.response as Response
@@ -95,6 +104,7 @@ export default function App() {
95104
setProfile(null)
96105
setDescription('')
97106
setResult(null)
107+
setTxHash(null)
98108
setScreen('home')
99109
setError(null)
100110
}, [])
@@ -103,6 +113,7 @@ export default function App() {
103113
if (!config.writeServerUrl || !userId) return
104114
setUpdateLoading(true)
105115
setResult(null)
116+
setTxHash(null)
106117
try {
107118
const res = await fetch(`${config.writeServerUrl}/update-description`, {
108119
method: 'POST',
@@ -113,8 +124,9 @@ export default function App() {
113124
const bodyStr = JSON.stringify(data, null, 2)
114125
console.log('[update-description] response body', bodyStr)
115126
if (res.ok) {
116-
const txHash = data?.transaction_hash ?? data?.transactionHash
117-
setResult(txHash ? `Description updated. Tx: ${txHash}` : 'Description updated.')
127+
const hash = data?.transaction_hash ?? data?.transactionHash
128+
setTxHash(hash ?? null)
129+
setResult(hash ? 'Description updated.' : 'Description updated.')
118130
} else {
119131
setResult(data?.error ?? `Error ${res.status}`)
120132
}
@@ -192,6 +204,18 @@ export default function App() {
192204
)}
193205
</TouchableOpacity>
194206
{result ? <Text style={styles.result}>{result}</Text> : null}
207+
{txHash ? (
208+
<TouchableOpacity
209+
style={styles.txLink}
210+
onPress={() =>
211+
Linking.openURL(
212+
`https://explorer.audius.engineering/transaction/${txHash}`
213+
)
214+
}
215+
>
216+
<Text style={styles.txLinkText}>View transaction</Text>
217+
</TouchableOpacity>
218+
) : null}
195219
</View>
196220
<StatusBar style="auto" />
197221
</View>
@@ -270,6 +294,8 @@ const styles = StyleSheet.create({
270294
buttonDisabled: { opacity: 0.7 },
271295
buttonText: { color: '#fff', fontSize: 16, fontWeight: '600' },
272296
result: { fontSize: 13, color: '#333', marginTop: 12 },
297+
txLink: { marginTop: 8 },
298+
txLinkText: { fontSize: 14, color: '#0066cc', textDecorationLine: 'underline' },
273299
loader: { marginVertical: 16 },
274300
error: { color: '#d32f2f', marginTop: 12, fontSize: 13 },
275301
backBtn: { padding: 16 },

0 commit comments

Comments
 (0)