-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: link twitter feat: binding some data * chore: lingui extract --------- Co-authored-by: swkatmask <[email protected]>
- Loading branch information
Showing
14 changed files
with
442 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,7 +67,8 @@ | |
}, | ||
"pnpm": { | ||
"patchedDependencies": { | ||
"[email protected]": "patches/[email protected]" | ||
"[email protected]": "patches/[email protected]", | ||
"[email protected]": "patches/[email protected]" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
diff --git a/CHANGELOG.md b/CHANGELOG.md | ||
deleted file mode 100644 | ||
index 9b28df0e8aa4734af2c7006fd077ff17e2281db5..0000000000000000000000000000000000000000 | ||
diff --git a/esm/useAsync.js b/esm/useAsync.js | ||
index ddb0bb0370fc30090cf9a0ecc74bc039800a89ed..95a7cb8cc6833790a5aef21a64ee0c5d299723cf 100644 | ||
--- a/esm/useAsync.js | ||
+++ b/esm/useAsync.js | ||
@@ -6,7 +6,11 @@ export default function useAsync(fn, deps) { | ||
loading: true, | ||
}), state = _a[0], callback = _a[1]; | ||
useEffect(function () { | ||
- callback(); | ||
+ try { | ||
+ callback(); | ||
+ } catch (e) { | ||
+ // Do nothing | ||
+ } | ||
}, [callback]); | ||
return state; | ||
} | ||
diff --git a/esm/useAsyncFn.js b/esm/useAsyncFn.js | ||
index 01d7307bd106229f6d791d0c588589235f404d97..89fce78d49b6332a1aa5dcd89e95ccbc0d02bca4 100644 | ||
--- a/esm/useAsyncFn.js | ||
+++ b/esm/useAsyncFn.js | ||
@@ -13,15 +13,16 @@ export default function useAsyncFn(fn, deps, initialState) { | ||
args[_i] = arguments[_i]; | ||
} | ||
var callId = ++lastCallId.current; | ||
- if (!state.loading) { | ||
- set(function (prevState) { return (__assign(__assign({}, prevState), { loading: true })); }); | ||
- } | ||
+ set(function (prevState) { | ||
+ if (prevState.loading) return prevState | ||
+ return (__assign(__assign({}, prevState), { loading: true })); | ||
+ }); | ||
return fn.apply(void 0, args).then(function (value) { | ||
isMounted() && callId === lastCallId.current && set({ value: value, loading: false }); | ||
return value; | ||
}, function (error) { | ||
isMounted() && callId === lastCallId.current && set({ error: error, loading: false }); | ||
- return error; | ||
+ throw error; | ||
}); | ||
}, deps); | ||
return [state, callback]; | ||
diff --git a/lib/useAsync.js b/lib/useAsync.js | ||
index 7f189a49dea552b5b10d7380b982bfe84299a7a2..4d9d33acaad290b54a9ef6e7df0afdba56484972 100644 | ||
--- a/lib/useAsync.js | ||
+++ b/lib/useAsync.js | ||
@@ -9,7 +9,11 @@ function useAsync(fn, deps) { | ||
loading: true, | ||
}), state = _a[0], callback = _a[1]; | ||
react_1.useEffect(function () { | ||
- callback(); | ||
+ try { | ||
+ callback(); | ||
+ } catch (e) { | ||
+ // Do nothing | ||
+ } | ||
}, [callback]); | ||
return state; | ||
} | ||
diff --git a/lib/useAsyncFn.js b/lib/useAsyncFn.js | ||
index e06fd819ccad625d709fa9907e946a9b8bc58543..6950e84a32ca630ec159834a87b4e21a36f4ef97 100644 | ||
--- a/lib/useAsyncFn.js | ||
+++ b/lib/useAsyncFn.js | ||
@@ -15,15 +15,16 @@ function useAsyncFn(fn, deps, initialState) { | ||
args[_i] = arguments[_i]; | ||
} | ||
var callId = ++lastCallId.current; | ||
- if (!state.loading) { | ||
- set(function (prevState) { return (tslib_1.__assign(tslib_1.__assign({}, prevState), { loading: true })); }); | ||
- } | ||
+ set(function (prevState) { | ||
+ if (prevState.loading) return prevState | ||
+ return (tslib_1.__assign(tslib_1.__assign({}, prevState), { loading: true })); | ||
+ }); | ||
return fn.apply(void 0, args).then(function (value) { | ||
isMounted() && callId === lastCallId.current && set({ value: value, loading: false }); | ||
return value; | ||
}, function (error) { | ||
isMounted() && callId === lastCallId.current && set({ error: error, loading: false }); | ||
- return error; | ||
+ throw error; | ||
}); | ||
}, deps); | ||
return [state, callback]; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import dayjs from 'dayjs' | ||
|
||
export function formatSeconds(seconds: number, pattern: string) { | ||
return dayjs(seconds * 1000).format(pattern) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { useAsyncFn } from 'react-use' | ||
import urlcat from 'urlcat' | ||
import { useAccount, useClient } from 'wagmi' | ||
import { signMessage } from 'wagmi/actions' | ||
import { config } from '../configs/wagmiClient' | ||
import { FIREFLY_API_ROOT } from '../constants/api' | ||
import { fetchJSON } from '../helpers/fetchJSON' | ||
import { TwitterAuthorizeResponse } from '../types/api' | ||
import { useToast } from '@chakra-ui/react' | ||
import { UserRejectedRequestError } from 'viem' | ||
|
||
// Any message is ok. | ||
const message = 'Hello, world!' | ||
export function useLinkTwitter() { | ||
const account = useAccount() | ||
const client = useClient() | ||
const toast = useToast() | ||
|
||
return useAsyncFn(async () => { | ||
if (!account.address || !client) return | ||
try { | ||
const signed = await signMessage(config, { | ||
account: account.address, | ||
message: message, | ||
}) | ||
const url = urlcat(FIREFLY_API_ROOT, '/v1/mask_stake/twitter/authorize', { | ||
original_message: message, | ||
signature_message: signed.slice(2), // omit 0x | ||
wallet_address: account.address, | ||
}) | ||
const res = await fetchJSON<TwitterAuthorizeResponse>(url) | ||
if (res.code !== 200) { | ||
console.error('Failed to get twitter authorize', res.message, res.reason) | ||
return | ||
} | ||
location.href = res.data.url | ||
} catch (err) { | ||
if (err instanceof UserRejectedRequestError) { | ||
toast({ | ||
status: 'error', | ||
position: 'top-right', | ||
title: err.details, | ||
}) | ||
return | ||
} | ||
throw err | ||
} | ||
}, [account.address, client]) | ||
} |
Oops, something went wrong.