Skip to content

Commit

Permalink
Merge branch 'main' into feat/tiping
Browse files Browse the repository at this point in the history
  • Loading branch information
MSghais committed Jun 14, 2024
2 parents 06f605a + 9fff77f commit 894b997
Show file tree
Hide file tree
Showing 70 changed files with 2,476 additions and 17,787 deletions.
1 change: 0 additions & 1 deletion JoyboyCommunity/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"@tanstack/react-query": "^5.40.0",
"buffer": "^6.0.3",
"crypto-es": "^2.1.0",
"dayjs": "^1.11.11",
"events": "^3.3.0",
"expo": "~51.0.8",
"expo-clipboard": "~6.0.3",
Expand Down
2 changes: 1 addition & 1 deletion JoyboyCommunity/src/app/Wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const Wrapper: React.FC = () => {
);

useEffect(() => {
// TODO: uncomment when we want to apply themeing
// TODO: uncomment when we want to apply theming
// setTheme(colorScheme === "light" ? lightModeColors : darkModeColors);
}, [colorScheme]);

Expand Down
6 changes: 5 additions & 1 deletion JoyboyCommunity/src/context/NostrContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ export const NostrProvider: React.FC<React.PropsWithChildren> = ({children}) =>

const relays = JOYBOY_RELAYS;
const ndk = useMemo(() => {
return new NDK({
const ndk = new NDK({
explicitRelayUrls: relays,
signer: privateKey ? new NDKPrivateKeySigner(privateKey) : undefined,
});

ndk.connect();

return ndk;
}, [relays, privateKey]);

return <NostrContext.Provider value={{ndk, relays}}>{children}</NostrContext.Provider>;
Expand Down
4 changes: 2 additions & 2 deletions JoyboyCommunity/src/modules/Post/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {CommentIcon, LikeFillIcon, LikeIcon, RepostIcon} from '../../assets/icon
import {Avatar, Text} from '../../components';
import {useProfile, useStyles, useTheme} from '../../hooks';
import {MainStackNavigationProps} from '../../types';
import {timestampToHumanReadable} from '../../utils/common-utils';
import {getElapsedTimeStringFull} from '../../utils/timestamp';
import stylesheet from './styles';

export type PostProps = {
Expand Down Expand Up @@ -130,7 +130,7 @@ export const Post: React.FC<PostProps> = ({asComment, event}) => {
)}

<Text color="textLight" fontSize={11} lineHeight={16}>
{timestampToHumanReadable(event.created_at)}
{getElapsedTimeStringFull(event.created_at * 1000)}
</Text>
</View>
</Pressable>
Expand Down
21 changes: 0 additions & 21 deletions JoyboyCommunity/src/utils/common-utils.ts

This file was deleted.

123 changes: 123 additions & 0 deletions JoyboyCommunity/src/utils/timestamp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
export type ElapsedTime = {
value: number;
unit: 'just_now' | 'seconds' | 'minutes' | 'hours' | 'days' | 'weeks' | 'months' | 'years';
};

/**
* Calculates the elapsed time between a timestamp and the current time.
* @param {number} timestamp The timestamp to calculate the elapsed time from.
* @param {number} currentTimestamp The current timestamp. Defaults to Date.now().
* @returns {ElapsedTime} The elapsed time.
*/
export const getElapsedFromTimestamp = (
timestamp: number,
currentTimestamp = Date.now(),
): ElapsedTime => {
const elapsed = Math.floor((currentTimestamp - timestamp) / 1000);

if (elapsed < 10) {
return {value: 0, unit: 'just_now'};
}

if (elapsed < 60) {
return {value: elapsed, unit: 'seconds'};
}

const minutes = Math.floor(elapsed / 60);
if (minutes < 60) {
return {value: minutes, unit: 'minutes'};
}

const hours = Math.floor(minutes / 60);
if (hours < 24) {
return {value: hours, unit: 'hours'};
}

const days = Math.floor(hours / 24);
if (days < 7) {
return {value: days, unit: 'days'};
}

if (days < 31) {
return {value: Math.floor(days / 7), unit: 'weeks'};
}

const months = Math.floor(days / 30);
if (months < 12) {
return {value: months, unit: 'months'};
}

return {value: Math.floor(months / 12), unit: 'years'};
};

export const getElapsedTimeStringFull = (
timestamp: number,
currentTimestamp = Date.now(),
): string => {
const elapsed = getElapsedFromTimestamp(timestamp, currentTimestamp);

switch (elapsed.unit) {
case 'just_now':
return 'just now';

case 'seconds':
return `${elapsed.value} second${elapsed.value > 1 ? 's' : ''} ago`;

case 'minutes':
return `${elapsed.value} minute${elapsed.value > 1 ? 's' : ''} ago`;

case 'hours':
return `${elapsed.value} hour${elapsed.value > 1 ? 's' : ''} ago`;

case 'days':
return `${elapsed.value} day${elapsed.value > 1 ? 's' : ''} ago`;

case 'weeks':
return `${elapsed.value} week${elapsed.value > 1 ? 's' : ''} ago`;

case 'months':
return `${elapsed.value} month${elapsed.value > 1 ? 's' : ''} ago`;

case 'years':
return `${elapsed.value} year${elapsed.value > 1 ? 's' : ''} ago`;

default:
return '';
}
};

export const getElapsedTimeStringShort = (
timestamp: number,
currentTimestamp = Date.now(),
): string => {
const elapsed = getElapsedFromTimestamp(timestamp, currentTimestamp);

switch (elapsed.unit) {
case 'just_now':
return 'just now';

case 'seconds':
return `${elapsed.value}s`;

case 'minutes':
return `${elapsed.value}m`;

case 'hours':
return `${elapsed.value}h`;

case 'days':
return `${elapsed.value}d`;

case 'weeks':
return `${elapsed.value}w`;

case 'months':
return `${elapsed.value}mo`;

case 'years':
return `${elapsed.value}y`;

default:
return '';
}
};
2 changes: 1 addition & 1 deletion JoyboyCommunity/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3223,7 +3223,7 @@ data-view-byte-offset@^1.0.0:
es-errors "^1.3.0"
is-data-view "^1.0.1"

dayjs@^1.11.11, dayjs@^1.8.15:
dayjs@^1.8.15:
version "1.11.11"
resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.11.11.tgz#dfe0e9d54c5f8b68ccf8ca5f72ac603e7e5ed59e"
integrity sha512-okzr3f11N6WuqYtZSvm+F776mB41wRZMhKP+hc34YdW+KmtYYK9iqvHSwo2k9FEH3fhGXvOPV6yz2IcSrfRUDg==
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,20 @@ Tech stack:
sequenceDiagram
actor Alice
actor Bob
participant SocialPay relay
participant SocialPay gateway
participant Starknet Node
participant Alice Account
participant STRK Token
Alice->>SocialPay relay: @joyboy send 10 STRK to @bob
activate SocialPay relay
SocialPay relay->>Starknet Node: SocialPay transaction
Alice->>SocialPay gateway: @joyboy send 10 STRK to @bob
activate SocialPay gateway
SocialPay gateway->>Starknet Node: SocialPay transaction
Starknet Node->>Alice Account: SocialPay handler
Alice Account->>STRK Token: transfer
Starknet Node->>SocialPay relay: SocialPay transaction complete
SocialPay relay->>Bob: @bob you just received 10 STRK from @alice
SocialPay relay->>Alice: @alice transfer of 10 STRK to @bob is complete
deactivate SocialPay relay
Starknet Node->>SocialPay gateway: SocialPay transaction complete
SocialPay gateway->>Bob: @bob you just received 10 STRK from @alice
SocialPay gateway->>Alice: @alice transfer of 10 STRK to @bob is complete
deactivate SocialPay gateway
```

## Modules
Expand Down
3 changes: 3 additions & 0 deletions website/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
4 changes: 4 additions & 0 deletions website/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# next
.next
next-env.d.ts
4 changes: 4 additions & 0 deletions website/next.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/** @type {import('next').NextConfig} */
const nextConfig = {};

export default nextConfig;
Loading

0 comments on commit 894b997

Please sign in to comment.