Skip to content

Commit

Permalink
fix gitcoin adapter to resubmit passport score
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosQ96 committed Jun 29, 2023
1 parent 6ca67f9 commit fcdc0ec
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 39 deletions.
3 changes: 2 additions & 1 deletion src/adapters/gitcoin/gitcoinAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ export class GitcoinAdapter implements GitcoinAdapterInterface {
const result = await axios.post(
`${GITCOIN_API_BASE_URL}/registry/submit-passport`,
{
variables: params,
address: params.address.toLowerCase(),
scorer_id: this.ScorerID,
},
{
headers: {
Expand Down
3 changes: 0 additions & 3 deletions src/adapters/gitcoin/gitcoinAdapterInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ export interface SigningMessageAndNonceResponse {

export interface SubmitPassportInput {
address: string;
scorer: string;
signature: string;
nonce: string;
}

export interface SubmittedPassportResponse {
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/gitcoin/gitcoinMockAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class GitcoinMockAdapter implements GitcoinAdapterInterface {
}
return Promise.resolve({
address: 'string',
score: 'string',
score: '10',
status: 'string',
last_score_timestamp: 'string',
evidence: undefined,
Expand Down
30 changes: 0 additions & 30 deletions src/resolvers/userResolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ function refreshUserScoresTestCases() {
const user = await User.create(userData).save();
await getGitcoinAdapter().submitPassport({
address: userData.walletAddress,
scorer: '200',
signature: 'any',
nonce: 'any',
});
const result = await axios.post(graphqlUrl, {
query: refreshUserScores,
Expand All @@ -74,9 +71,6 @@ function refreshUserScoresTestCases() {
const user = await User.create(userData).save();
await getGitcoinAdapter().submitPassport({
address: userData.walletAddress,
scorer: '200',
signature: 'any',
nonce: 'any',
});
const result = await axios.post(graphqlUrl, {
query: refreshUserScores,
Expand All @@ -102,30 +96,6 @@ function refreshUserScoresTestCases() {
updatedUser.passportScore,
);
});
it('should not refresh user scores if not registered to gitcoin', async () => {
const userData = {
firstName: 'firstName',
lastName: 'lastName',
email: '[email protected]',
avatar: 'pinata address',
url: 'website url',
loginType: 'wallet',
walletAddress: generateRandomEtheriumAddress(),
};
const user = await User.create(userData).save();
const result = await axios.post(graphqlUrl, {
query: refreshUserScores,
variables: {
address: userData.walletAddress,
},
});

const updatedUser = result.data.data.refreshUserScores;
assert.equal(updatedUser.walletAddress, user.walletAddress);
// if score remains null the user has not registered
assert.equal(updatedUser.passportScore, 0);
assert.equal(updatedUser.passportStamps, 0);
});
}

function userByAddressTestCases() {
Expand Down
8 changes: 4 additions & 4 deletions src/resolvers/userResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ export class UserResolver {
if (!foundUser) return;

try {
const passportScore = await getGitcoinAdapter().getWalletAddressScore(
const passportScore = await getGitcoinAdapter().submitPassport({
address,
);
});
const passportStamps = await getGitcoinAdapter().getPassportStamps(
address,
);

if (passportScore) {
if (passportScore && passportScore?.score) {
const score = Number(passportScore.score);
foundUser.passportScore = isNaN(score) ? 0 : score;
foundUser.passportScore = score;
}
if (passportStamps)
foundUser.passportStamps = passportStamps.items.length;
Expand Down

0 comments on commit fcdc0ec

Please sign in to comment.