Skip to content

Commit

Permalink
graphql stuff on FE
Browse files Browse the repository at this point in the history
  • Loading branch information
Seroxdesign committed Aug 11, 2023
1 parent f728f89 commit 7ae2d38
Show file tree
Hide file tree
Showing 9 changed files with 197 additions and 67 deletions.
32 changes: 32 additions & 0 deletions hasura/metadata/tables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,19 @@
- name: Player
using:
foreign_key_constraint_on: player_id
insert_permissions:
- role: player
permission:
check:
player_id:
_eq: X-Hasura-User-Id
columns: []
backend_only: false
- role: public
permission:
check: {}
columns: []
backend_only: false
select_permissions:
- role: player
permission:
Expand All @@ -658,6 +671,25 @@
- identifier
- type
filter: {}
update_permissions:
- role: player
permission:
columns:
- identifier
- type
filter:
player_id:
_eq: X-Hasura-User-Id
check: null
- role: public
permission:
columns: []
filter: {}
check: null
delete_permissions:
- role: public
permission:
filter: {}
- table:
schema: public
name: player_role
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DELETE FROM "AccountType" WHERE type = 'DEWORK';
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
INSERT INTO "AccountType"
(type) VALUES ('DEWORK')
ON CONFLICT DO NOTHING -- allow multiple runs
;
108 changes: 54 additions & 54 deletions packages/backend/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,64 +33,64 @@ const config = {
immutableTypes: true,
scalars: {
account_type:
"'ETHEREUM' | 'DISCORD' | 'GITHUB' | 'TWITTER' | 'DISCOURSE'",
"'ETHEREUM' | 'DISCORD' | 'GITHUB' | 'TWITTER' | 'DISCOURSE | DEWORK'",
},
dedupeOperationSuffix: true,
},
},
'src/lib/autogen/daohaus-sdk.ts': {
// DAOHaus v3 API Endpoint
// schema: `https://gateway.thegraph.com/api/${process.env.THE_GRAPH_API_TOKEN}/subgraphs/id/GfHFdFmiSwW1PKtnDhhcxhArwtTjVuMnXxQ5XcETF1bP`,
schema: `https://gateway.thegraph.com/api/${process.env.THE_GRAPH_API_TOKEN}/subgraphs/id/9uvKq57ZiNCdT9uZ6xaFhp3yYczTM4Fgr7CJHM6tdX9H`,
documents: [
'src/handlers/remote-schemas/resolvers/daohaus/**/(!(*.d)).ts',
],
plugins: [
'typescript',
'typescript-operations',
'typescript-graphql-request',
'typescript-resolvers',
{ add: { content: '/* eslint-disable */' } },
],
config: {
avoidOptionals: true,
dedupeOperationSuffix: true,
typesPrefix: 'DaoHaus',
},
},
'src/lib/autogen/seedgraph-sdk.ts': {
schema: 'https://api.thegraph.com/subgraphs/name/tenfinney/polygon-seeds',
documents: [
'src/handlers/remote-schemas/resolvers/seedGraph/**/(!(*.d)).ts',
],
plugins: [
'typescript',
'typescript-operations',
'typescript-graphql-request',
{ add: { content: '/* eslint-disable */' } },
],
config: {
avoidOptionals: true,
dedupeOperationSuffix: true,
},
},
'src/lib/autogen/balancerpolygon-sdk.ts': {
schema:
'https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-polygon-v2',
documents: [
'src/handlers/remote-schemas/resolvers/balancerPolygon/**/(!(*.d)).ts',
],
plugins: [
'typescript',
'typescript-operations',
'typescript-graphql-request',
{ add: { content: '/* eslint-disable */' } },
],
config: {
avoidOptionals: true,
dedupeOperationSuffix: true,
},
},
// 'src/lib/autogen/daohaus-sdk.ts': {
// // DAOHaus v3 API Endpoint
// // schema: `https://gateway.thegraph.com/api/${process.env.THE_GRAPH_API_TOKEN}/subgraphs/id/GfHFdFmiSwW1PKtnDhhcxhArwtTjVuMnXxQ5XcETF1bP`,
// schema: `https://gateway.thegraph.com/api/${process.env.THE_GRAPH_API_TOKEN}/subgraphs/id/9uvKq57ZiNCdT9uZ6xaFhp3yYczTM4Fgr7CJHM6tdX9H`,
// documents: [
// 'src/handlers/remote-schemas/resolvers/daohaus/**/(!(*.d)).ts',
// ],
// plugins: [
// 'typescript',
// 'typescript-operations',
// 'typescript-graphql-request',
// 'typescript-resolvers',
// { add: { content: '/* eslint-disable */' } },
// ],
// config: {
// avoidOptionals: true,
// dedupeOperationSuffix: true,
// typesPrefix: 'DaoHaus',
// },
// },
// 'src/lib/autogen/seedgraph-sdk.ts': {
// schema: 'https://api.thegraph.com/subgraphs/name/tenfinney/polygon-seeds',
// documents: [
// 'src/handlers/remote-schemas/resolvers/seedGraph/**/(!(*.d)).ts',
// ],
// plugins: [
// 'typescript',
// 'typescript-operations',
// 'typescript-graphql-request',
// { add: { content: '/* eslint-disable */' } },
// ],
// config: {
// avoidOptionals: true,
// dedupeOperationSuffix: true,
// },
// },
// 'src/lib/autogen/balancerpolygon-sdk.ts': {
// schema:
// 'https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-polygon-v2',
// documents: [
// 'src/handlers/remote-schemas/resolvers/balancerPolygon/**/(!(*.d)).ts',
// ],
// plugins: [
// 'typescript',
// 'typescript-operations',
// 'typescript-graphql-request',
// { add: { content: '/* eslint-disable */' } },
// ],
// config: {
// avoidOptionals: true,
// dedupeOperationSuffix: true,
// },
// },
},
};

Expand Down
2 changes: 1 addition & 1 deletion packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"scripts": {
"start": "node --trace-warnings dist/index.js",
"build": "yarn generate && tsc -b",
"dev": "tsc --build && concurrently 'tsc --watch --preserveWatchOutput' nodemon 'yarn generate # --watch'",
"dev": "tsc --build && concurrently 'tsc --watch --preserveWatchOutput' nodemon",
"typecheck": "yarn generate && tsc --noEmit --pretty",
"precommit": "yarn typecheck && yarn lint-staged",
"generate": "graphql-codegen && export OUT=src/lib/autogen/daohaus-sdk.ts && awk '!/MolochVersion = .molochVersion/' $OUT > $OUT.filtered && mv $OUT.filtered $OUT",
Expand Down
62 changes: 50 additions & 12 deletions packages/web/components/Player/Section/PlayerDework.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import {
InfoIcon,
Input,
Spinner,
Link,
Text,
Tooltip,
VStack,
Wrap,
WrapItem,
} from '@metafam/ds';
import { generateUUID } from '@metafam/utils';
import { to } from '@react-spring/web';
import DeworkLogo from 'assets/integrationLogos/deworkLogo.png';
import { MetaLink } from 'components/Link';
import { ProfileSection } from 'components/Section/ProfileSection';
Expand All @@ -30,6 +30,8 @@ import {
processDeworkData,
} from 'utils/dework';
import { formatAddress } from 'utils/playerHelpers';
import { getPlayerDeworkUsername } from 'graphql/getDeworkUsername';
import { useUpsertDeworkProfileMutation } from 'graphql/autogen/types';

type Props = {
player: Player;
Expand Down Expand Up @@ -85,6 +87,16 @@ export const PlayerDework: React.FC<Props> = ({
const connected = addressMatch && !playerDeworkURL;
const [loading, setLoading] = useState<boolean>(true);
const noticeRef = useRef<HTMLDivElement>(null);

useEffect(() => {
const getDeworkUsername = async () => {
getPlayerDeworkUsername(player.id).then((res) => res && setPlayerDeworkURL(res as string))
}
if (player?.id) {
getDeworkUsername()
}
}, [player?.id])

const getData = useCallback(async (address: string) => {
setLoading(true);
await getDeworkData(address).then((res: any) => {
Expand Down Expand Up @@ -146,6 +158,7 @@ export const PlayerDework: React.FC<Props> = ({
<PlayerDeworkView
role={role}
player={player}
playerDeworkURL={playerDeworkURL}
setPlayerDeworkURL={setPlayerDeworkURL}
profileData={deworkData}
retry={() => retryCall()}
Expand All @@ -167,13 +180,15 @@ export const PlayerDework: React.FC<Props> = ({
);
};

const DeworkProfile: React.FC<{data: any }> = ({ data }) => {
const DeworkProfile: React.FC<{data: any, playerDeworkURL: string }> = ({ data, playerDeworkURL }) => {

const processedData = useMemo(
() => processDeworkData(data),
[data],
);

const deworkURL = `https://app.dework.xyz/` + (playerDeworkURL ? `profile/${playerDeworkURL}` : '')

return (
<Wrap>
<WrapItem
Expand Down Expand Up @@ -260,15 +275,16 @@ const DeworkProfile: React.FC<{data: any }> = ({ data }) => {
</>
)}
{data && (
<MetaLink
href={`https://app.dework.xyz/profile/${data.username}`}
<Link
sx={{ textDecoration: 'underline', color: '#b1fcfe' }}
href={deworkURL}
fontWeight={500}
display="inline-flex"
alignItems="center"
isExternal
>
See <Text as="span" display={{ base: 'none', xl: 'inline' }}>&nbsp;complete&nbsp;</Text> profile on Dework <ExternalLinkIcon mx="2px" />
</MetaLink>
</Link>
)}
</WrapItem>
</Wrap>
Expand All @@ -278,26 +294,48 @@ const DeworkProfile: React.FC<{data: any }> = ({ data }) => {
const PlayerDeworkView: React.FC<{
role: string;
player: Player;
playerDeworkURL: string;
setPlayerDeworkURL: any;
profileData: any;
retry: () => void;
}> = ({ role, player, setPlayerDeworkURL, retry, profileData }) => {
}> = ({ role, player, setPlayerDeworkURL, retry, profileData, playerDeworkURL }) => {

const currentView = {
AddURL: <DeworkLink setPlayerDeworkURL={setPlayerDeworkURL} />,
AddURL: <DeworkLink setPlayerDeworkURL={setPlayerDeworkURL} playerDeworkURL={playerDeworkURL} />,
Loading: <Loading />,
NoMatch: <NoMatch playerAddress={player.ethereumAddress} retry={retry} />,
DeworkProfile: <DeworkProfile data={profileData} />,
DeworkProfile: <DeworkProfile data={profileData} playerDeworkURL={playerDeworkURL} />,
}[role];

return <>{currentView}</>;
};

const DeworkLink: React.FC<{ setPlayerDeworkURL: any }> = ({
const DeworkLink: React.FC<{ setPlayerDeworkURL: any, playerDeworkURL: string }> = ({
setPlayerDeworkURL,
playerDeworkURL,
}) => {
const [deworkURL, setDeworkURL] = useState<string>('');
const [upsertPlayerDeworkState, upsertPlayerDework] = useUpsertDeworkProfileMutation();

const handleSetUserDeworkURL = async (playerId: string, identifier: string) => {
try {
//console.log('in 2')
const response = await upsertPlayerDework({
playerId: 'f0db18b2-4294-4373-a468-f08f53ab4fbc',
identifier: 'Sero',
type: 'DEWORK'
});
//console.log(response)
// Handle the response if necessary.
// For example, you might want to update the UI based on the mutation's result:
if (response && response.data) {
//console.log("Successfully upserted:", response.data);
}
} catch (error) {
//console.error("Error upserting the Dework profile:", error);
}
};

return (
<>
<FormControl id="deworkURL" mb={4}>
Expand Down Expand Up @@ -325,13 +363,13 @@ const DeworkLink: React.FC<{ setPlayerDeworkURL: any }> = ({
<FormHelperText color="white">Enter exactly as written on Dework</FormHelperText>
</FormControl>
<Button
onClick={() => setPlayerDeworkURL(deworkURL)}
isDisabled={!deworkURL}
//onClick={() => setPlayerDeworkURL(deworkURL)}
onClick={() => handleSetUserDeworkURL('', '')}
_disabled={{
cursor: 'not-allowed',
}}
>
{deworkURL ? 'Proceed To Block' : 'Please Enter Dework username'}
{playerDeworkURL ? 'Proceed To Block' : 'Please Enter Dework username'}
</Button>
</>
);
Expand Down
16 changes: 16 additions & 0 deletions packages/web/graphql/getDeworkUsername.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { client } from './client';

const playerDeworkUsernameQuery = /* GraphQL */ `
query GetPlayerDeworkUsername($playerId: uuid!) {
player_account(where: { playerId: {_eq: $playerId}, type: {_eq: DEWORK}}) {
identifier
}
}
`

export const getPlayerDeworkUsername = async (playerId: string): Promise<string> => {
if (!playerId) return ''
let info = await client.query<any>(playerDeworkUsernameQuery, { playerId })
const username = info?.data?.player_account[0]?.identifier
return username
}
13 changes: 13 additions & 0 deletions packages/web/graphql/mutations/dework.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export const UpsertDeworkUsername = /* GraphQL */ `
mutation UpsertDeworkProfile(
$playerId: uuid!,
$identifier: String!,
$type: String!
) {
insert_player_account_one(object: {identifier: $identifier, playerId: $playerId, type: DEWORK}, on_conflict: {constraint: Account_identifier_type_key, update_columns: identifier}) {
identifier
playerId
type
}
}
`
Loading

0 comments on commit 7ae2d38

Please sign in to comment.