Skip to content

Commit

Permalink
Fix: Token not showing on proposals with underlying token (#249)
Browse files Browse the repository at this point in the history
* fix parseToken function

* update version

* add parseToken tests

* Updating the changelog

---------

Co-authored-by: Jør∂¡ <[email protected]>
  • Loading branch information
josemarinas and brickpop authored Jul 10, 2023
1 parent a7a6ab7 commit 06de92e
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 4 deletions.
4 changes: 4 additions & 0 deletions modules/client/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ TEMPLATE:

## [UPCOMING]
### Changed
- Amended an issue that would prevent details from the underlying token to be returned in `parseToken()`

## [1.9.5]
### Changed
- Added a timeout to `getDaos()` and `getProposals()`, so that an individual lengthy fetch doesn't block everything indefinitely
- Improve the PR template

Expand Down
2 changes: 1 addition & 1 deletion modules/client/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@aragon/sdk-client",
"author": "Aragon Association",
"version": "1.9.5",
"version": "1.9.6",
"license": "MIT",
"main": "dist/index.js",
"module": "dist/sdk-client.esm.js",
Expand Down
26 changes: 23 additions & 3 deletions modules/client/src/tokenVoting/internal/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from "../../client-common";
import {
Erc20TokenDetails,
Erc20WrapperTokenDetails,
Erc721TokenDetails,
MintTokenParams,
TokenVotingMember,
Expand All @@ -19,6 +20,7 @@ import {
ContractTokenVotingInitParams,
SubgraphContractType,
SubgraphErc20Token,
SubgraphErc20WrapperToken,
SubgraphErc721Token,
SubgraphTokenVotingMember,
SubgraphTokenVotingProposal,
Expand Down Expand Up @@ -213,10 +215,13 @@ export function tokenVotingInitParamsToContract(
];
}

function parseToken(
subgraphToken: SubgraphErc20Token | SubgraphErc721Token,
export function parseToken(
subgraphToken:
| SubgraphErc20Token
| SubgraphErc721Token
| SubgraphErc20WrapperToken,
): Erc20TokenDetails | Erc721TokenDetails | null {
let token: Erc721TokenDetails | Erc20TokenDetails | null = null;
let token: Erc721TokenDetails | Erc20TokenDetails| Erc20WrapperTokenDetails | null = null;
if (subgraphToken.__typename === SubgraphContractType.ERC20) {
token = {
address: subgraphToken.id,
Expand All @@ -232,6 +237,21 @@ function parseToken(
name: subgraphToken.name,
type: TokenType.ERC721,
};
} else if (subgraphToken.__typename === SubgraphContractType.ERC20_WRAPPER) {
token = {
address: subgraphToken.id,
symbol: subgraphToken.symbol,
name: subgraphToken.name,
decimals: subgraphToken.decimals,
type: TokenType.ERC20,
underlyingToken: {
address: subgraphToken.underlyingToken.id,
symbol: subgraphToken.underlyingToken.symbol,
name: subgraphToken.underlyingToken.name,
decimals: subgraphToken.underlyingToken.decimals,
type: TokenType.ERC20,
},
};
}
return token;
}
Expand Down
1 change: 1 addition & 0 deletions modules/client/src/tokenVoting/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export type Erc20TokenDetails = TokenBaseDetails & {
decimals: number;
type: TokenType.ERC20;
};

export type Erc721TokenDetails = TokenBaseDetails & {
type: TokenType.ERC721;
};
Expand Down
78 changes: 78 additions & 0 deletions modules/client/test/unit/tokenVoting-client  /utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { TokenType } from "@aragon/sdk-client-common";
import { SubgraphContractType } from "../../../src/tokenVoting/internal/types";
import { parseToken } from "../../../src/tokenVoting/internal/utils";

describe("tokenVoting-client utils", () => {
describe("parseToken", () => {
it("should return ERC721", () => {
const token = parseToken({
__typename: SubgraphContractType.ERC721,
id: "0x1234567890123456789012345678901234567890",
name: "TestToken",
symbol: "TT",
});
expect(token).toEqual({
address: "0x1234567890123456789012345678901234567890",
name: "TestToken",
symbol: "TT",
type: TokenType.ERC721,
});
});
it("should return ERC20", () => {
const token = parseToken({
__typename: SubgraphContractType.ERC20,
id: "0x1234567890123456789012345678901234567890",
name: "TestToken",
symbol: "TT",
decimals: 18,
});
expect(token).toEqual({
address: "0x1234567890123456789012345678901234567890",
name: "TestToken",
symbol: "TT",
decimals: 18,
type: TokenType.ERC20,
});
});
it("should return ERC20Wrapper", () => {
const token = parseToken({
__typename: SubgraphContractType.ERC20_WRAPPER,
id: "0x1234567890123456789012345678901234567890",
name: "TestToken",
symbol: "TT",
decimals: 18,
underlyingToken: {
__typename: SubgraphContractType.ERC20,
id: "0x1234567890123456789012345678901234567890",
name: "TestToken",
symbol: "TT",
decimals: 18,
},
});
expect(token).toEqual({
address: "0x1234567890123456789012345678901234567890",
name: "TestToken",
symbol: "TT",
decimals: 18,
type: TokenType.ERC20,
underlyingToken: {
address: "0x1234567890123456789012345678901234567890",
name: "TestToken",
symbol: "TT",
decimals: 18,
type: TokenType.ERC20,
},
});
});
it("should return null", () => {
const token = parseToken({
// @ts-ignore
__typename: "Other",
id: "0x1234567890123456789012345678901234567890",
name: "TestToken",
symbol: "TT",
});
expect(token).toEqual(null);
});
});
});

0 comments on commit 06de92e

Please sign in to comment.