Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/warm-pillows-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@human-protocol/sdk": patch
"@human-protocol/python-sdk": patch
---

Delete references to totalHMTAmountReceived that was removed from subgraph
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const walletSchema = z.object({
lockedAmount: z.string(),
withdrawableAmount: z.string(),
reputation: reputationSchema,
totalHMTAmountReceived: z.string(),
payoutCount: z.number().or(z.string()),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const WalletAddress: FC<Props> = ({ data }) => {
reputation,
withdrawableAmount,
} = data;
const isWallet = 'totalHMTAmountReceived' in data;
const isWallet = 'payoutCount' in data;

return (
<>
Expand All @@ -51,10 +51,10 @@ const WalletAddress: FC<Props> = ({ data }) => {
</TitleSectionWrapper>
{isWallet && (
<TitleSectionWrapper
title="Earned Payouts"
tooltip="Total amount earned by participating in jobs"
title="Payouts received"
tooltip="Total count of payouts received by participating in jobs"
>
<TokenAmount amount={data?.totalHMTAmountReceived} />
<TokenAmount amount={data?.payoutCount} />
</TitleSectionWrapper>
)}
</Stack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,6 @@ export class DetailsService {
withdrawableAmount: ethers.formatEther(stakingData.withdrawableAmount),
reputation: (await this.fetchOperatorReputation(chainId, address))
.reputation,
totalHMTAmountReceived: ethers.formatEther(
workerData?.totalHMTAmountReceived || 0,
),
payoutCount: workerData?.payoutCount || 0,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
fragment WorkerFields on Worker {
id
address
totalHMTAmountReceived
payoutCount
}
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
WorkerFilter(chain_id=ChainId.POLYGON_AMOY)
)
for worker in workers:
print(f"{worker.address}: {worker.total_amount_received}")
print(f"{worker.address}: {worker.payout_count}")
```
"""

Expand Down Expand Up @@ -37,20 +37,17 @@ class WorkerData:
Attributes:
id (str): Unique worker identifier.
address (str): Worker's Ethereum address.
total_amount_received (int): Total amount of HMT tokens received by the worker.
payout_count (int): Number of payouts the worker has received.
"""

def __init__(
self,
id: str,
address: str,
total_amount_received: str,
payout_count: str,
):
self.id = id
self.address = address
self.total_amount_received = int(total_amount_received)
self.payout_count = int(payout_count)


Expand Down Expand Up @@ -94,7 +91,7 @@ def get_workers(
WorkerFilter(chain_id=ChainId.POLYGON_AMOY)
)
for worker in workers:
print(f"{worker.address}: {worker.total_amount_received} HMT")
print(f"{worker.address}: {worker.payout_count} payouts")

# Get specific worker
workers = WorkerUtils.get_workers(
Expand Down Expand Up @@ -141,7 +138,6 @@ def get_workers(
WorkerData(
id=worker.get("id"),
address=worker.get("address"),
total_amount_received=worker.get("totalHMTAmountReceived"),
payout_count=worker.get("payoutCount"),
)
)
Expand Down Expand Up @@ -180,7 +176,6 @@ def get_worker(
"0x1234567890123456789012345678901234567890",
)
if worker:
print(f"Total received: {worker.total_amount_received} HMT")
print(f"Payout count: {worker.payout_count}")
```
"""
Expand Down Expand Up @@ -215,6 +210,5 @@ def get_worker(
return WorkerData(
id=worker.get("id"),
address=worker.get("address"),
total_amount_received=worker.get("totalHMTAmountReceived"),
payout_count=worker.get("payoutCount"),
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ def test_get_workers(self):
mock_worker_1 = {
"id": "worker1",
"address": "0x1234567890123456789012345678901234567890",
"totalHMTAmountReceived": "1000",
"payoutCount": 5,
}
mock_worker_2 = {
"id": "worker2",
"address": "0x9876543210987654321098765432109876543210",
"totalHMTAmountReceived": "2000",
"payoutCount": 10,
}

Expand All @@ -31,7 +29,7 @@ def test_get_workers(self):

filter = WorkerFilter(
chain_id=ChainId.POLYGON_AMOY,
order_by="totalHMTAmountReceived",
order_by="payoutCount",
order_direction=OrderDirection.ASC,
)

Expand All @@ -44,14 +42,16 @@ def test_get_workers(self):
"address": None,
"first": 10,
"skip": 0,
"orderBy": "totalHMTAmountReceived",
"orderBy": "payoutCount",
"orderDirection": "asc",
},
options=None,
)
self.assertEqual(len(workers), 2)
self.assertEqual(workers[0].id, "worker1")
self.assertEqual(workers[1].id, "worker2")
self.assertEqual(workers[0].payout_count, 5)
self.assertEqual(workers[1].payout_count, 10)

def test_get_workers_empty_response(self):
with patch(
Expand Down Expand Up @@ -93,7 +93,6 @@ def test_get_worker(self):
mock_worker = {
"id": "worker1",
"address": "0x1234567890123456789012345678901234567890",
"totalHMTAmountReceived": "1000",
"payoutCount": 5,
}

Expand All @@ -115,6 +114,7 @@ def test_get_worker(self):
self.assertEqual(
worker.address, "0x1234567890123456789012345678901234567890"
)
self.assertEqual(worker.payout_count, 5)

def test_get_worker_empty_data(self):
with patch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export const GET_WORKER_QUERY = gql`
worker(id: $address) {
id
address
totalHMTAmountReceived
payoutCount
}
}
Expand Down Expand Up @@ -34,7 +33,6 @@ export const GET_WORKERS_QUERY = (filter: IWorkersFilter) => {
) {
id
address
totalHMTAmountReceived
payoutCount
}
}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export type EscrowData = {
export type WorkerData = {
id: string;
address: string;
totalHMTAmountReceived: string;
payoutCount: string;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ export interface IStatusEventFilter extends IPagination {
export interface IWorker {
id: string;
address: string;
totalHMTAmountReceived: bigint;
payoutCount: number;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ export class WorkerUtils {
* type IWorker = {
* id: string;
* address: string;
* totalHMTAmountReceived: bigint;
* payoutCount: number;
* };
* ```
Expand Down Expand Up @@ -162,7 +161,6 @@ function mapWorker(w: WorkerData): IWorker {
return {
id: w.id,
address: w.address,
totalHMTAmountReceived: BigInt(w.totalHMTAmountReceived || 0),
payoutCount: Number(w.payoutCount || 0),
};
}
19 changes: 8 additions & 11 deletions packages/sdk/typescript/human-protocol-sdk/test/worker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ describe('WorkerUtils', () => {
const mockWorker: WorkerData = {
id: workerAddress,
address: workerAddress,
totalHMTAmountReceived: '1000',
payoutCount: 10,
payoutCount: '10',
};

test('should return worker details', async () => {
Expand All @@ -51,7 +50,7 @@ describe('WorkerUtils', () => {
);
const expected: IWorker = {
...mockWorker,
totalHMTAmountReceived: BigInt(mockWorker.totalHMTAmountReceived || 0),
payoutCount: Number(mockWorker.payoutCount || 0),
};
expect(result).toEqual(expected);
});
Expand Down Expand Up @@ -100,14 +99,12 @@ describe('WorkerUtils', () => {
{
id: '0x1234567890abcdef1234567890abcdef12345678',
address: '0x1234567890abcdef1234567890abcdef12345678',
totalHMTAmountReceived: '1000',
payoutCount: 10,
payoutCount: '10',
},
{
id: '0xabcdefabcdefabcdefabcdefabcdefabcdef',
address: '0xabcdefabcdefabcdefabcdefabcdefabcdef',
totalHMTAmountReceived: '2000',
payoutCount: 20,
payoutCount: '20',
},
];

Expand All @@ -120,7 +117,7 @@ describe('WorkerUtils', () => {
chainId: ChainId.LOCALHOST,
first: 10,
skip: 0,
orderBy: 'totalHMTAmountReceived',
orderBy: 'payoutCount',
orderDirection: OrderDirection.ASC,
};

Expand All @@ -133,14 +130,14 @@ describe('WorkerUtils', () => {
address: undefined,
first: 10,
skip: 0,
orderBy: 'totalHMTAmountReceived',
orderBy: 'payoutCount',
orderDirection: 'asc',
},
undefined
);
const expected: IWorker[] = mockWorkers.map((mockWorker) => ({
...mockWorker,
totalHMTAmountReceived: BigInt(mockWorker.totalHMTAmountReceived || 0),
payoutCount: Number(mockWorker.payoutCount || 0),
}));
expect(result).toEqual(expected);
});
Expand Down Expand Up @@ -215,7 +212,7 @@ describe('WorkerUtils', () => {

const expected: IWorker[] = mockWorkers.map((mockWorker) => ({
...mockWorker,
totalHMTAmountReceived: BigInt(mockWorker.totalHMTAmountReceived || 0),
payoutCount: Number(mockWorker.payoutCount || 0),
}));
expect(result).toEqual(expected);
});
Expand Down
Loading