Skip to content

Commit 5f8462d

Browse files
feat: view wallet rewards (#129)
* feat: view wallet rewards * test: get rewards * feat: list
1 parent 7ac03ec commit 5f8462d

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

src/client/client.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,18 @@ export abstract class BaseTNClient<T extends EnvironmentType> {
285285
return bridgeResult.data.tx_hash;
286286
}
287287

288+
/**
289+
* Lists wallet rewards for a specific wallet address on a blockchain network
290+
* @param chain The chain identifier (e.g., "sepolia", "mainnet", "polygon", etc.)
291+
* @param wallet The wallet address to list rewards for
292+
* @param withPending Whether to include pending rewards
293+
* @returns Promise that resolves to an array of rewards data
294+
*/
295+
async listWalletRewards(chain: string, wallet: string, withPending: boolean): Promise<any[]> {
296+
const action = this.loadAction();
297+
return action.listWalletRewards(chain, wallet, withPending);
298+
}
299+
288300
/**
289301
* Gets taxonomies for specific streams in batch.
290302
* High-level wrapper for ComposedAction.getTaxonomiesForStreams()

src/contracts-api/action.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,4 +1030,35 @@ export class Action {
10301030
$amount: amount
10311031
}]);
10321032
}
1033+
1034+
/**
1035+
* Lists wallet rewards on a blockchain network
1036+
* @param chain The chain identifier (e.g., "sepolia", "mainnet", "polygon", etc.)
1037+
* @param wallet The wallet address to list rewards for
1038+
* @param withPending Whether to include pending rewards
1039+
* @returns Promise that resolves to the rewards data
1040+
*/
1041+
public async listWalletRewards(
1042+
chain: string,
1043+
wallet: string,
1044+
withPending: boolean
1045+
): Promise<any[]> {
1046+
const result = await this.kwilClient.call(
1047+
{
1048+
namespace: `${chain}_bridge`,
1049+
name: "list_wallet_rewards",
1050+
inputs: {
1051+
$param_1: wallet,
1052+
$param_2: withPending,
1053+
},
1054+
},
1055+
this.kwilSigner,
1056+
);
1057+
1058+
if (result.status !== 200) {
1059+
throw new Error(`Failed to list wallet rewards: ${result.status}`);
1060+
}
1061+
1062+
return result.data?.result || [];
1063+
}
10331064
}

tests/integration/erc20Bridge.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,25 @@ describe('ERC20 Bridge Tests', () => {
5858
throw error;
5959
}
6060
}, 60000);
61+
62+
test('get wallet rewards', async () => {
63+
try {
64+
const rewards = await authorizedClient.listWalletRewards(
65+
"sepolia",
66+
"0x041AEfDc96655d3Dbf7788767dcEEB635eCD315C",
67+
true
68+
);
69+
70+
expect(Array.isArray(rewards)).toBe(true);
71+
72+
} catch (error: any) {
73+
// Skip test if backend is unavailable in test environment
74+
if (error.message?.includes("no available backend")) {
75+
console.info("Skipping test: blockchain backend unavailable in test environment");
76+
return;
77+
}
78+
throw error;
79+
}
80+
}, 60000);
81+
6182
});

0 commit comments

Comments
 (0)