Skip to content

Commit

Permalink
feat: WT-1990 Rename contractAddress to tokenAddress (#1285)
Browse files Browse the repository at this point in the history
  • Loading branch information
sharonsheah authored Dec 14, 2023
1 parent da2f3f3 commit ab1736f
Show file tree
Hide file tree
Showing 48 changed files with 183 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface BalanceProps {
}

export default function GetBalance(props: BalanceProps) {
const contractAddress = '0x741185AEFC3E539c1F42c1d6eeE8bFf1c89D70FE';
const tokenAddress = '0x741185AEFC3E539c1F42c1d6eeE8bFf1c89D70FE';

const { provider, checkout } = props;

Expand Down Expand Up @@ -72,7 +72,7 @@ export default function GetBalance(props: BalanceProps) {
const resp = await checkout.getBalance({
provider,
walletAddress,
contractAddress,
tokenAddress,
});
setResultBalance(resp);
setLoadingBalance(false);
Expand Down Expand Up @@ -141,7 +141,7 @@ export default function GetBalance(props: BalanceProps) {
marginBottom: 'base.spacing.x2',
}}
>
Target token: {contractAddress}
Target token: {tokenAddress}
</Box>
<Box>Balance: {resultBalance.balance.toString()}</Box>
<Box>Fromatted Balance: {resultBalance.formattedBalance}</Box>
Expand Down
10 changes: 5 additions & 5 deletions packages/checkout/sdk-sample-app/src/components/Sell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function Sell({ checkout, provider }: SellProps) {
const [listingTypeError, setListingTypeError] = useState<string>('');
const [amount, setAmount] = useState<string>('');
const [amountError, setAmountError] = useState<string>('');
const [contractAddress, setContractAddress] = useState<string>('');
const [tokenAddress, setContractAddress] = useState<string>('');
const [contractAddressError, setContractAddressError] = useState<string>('');
const [error, setError] = useState<any>(null);
const [success, setSuccess] = useState<boolean>(false);
Expand All @@ -37,7 +37,7 @@ export default function Sell({ checkout, provider }: SellProps) {
return {
type: ItemType.ERC20,
amount,
contractAddress,
tokenAddress,
};
}

Expand All @@ -57,14 +57,14 @@ export default function Sell({ checkout, provider }: SellProps) {
if (listingType === ItemType.ERC20 && !amount) {
setAmountError('Please enter the amount of ERC20 tokens to sell the ERC721 for');
}
if (listingType === ItemType.ERC20 && !contractAddress) {
if (listingType === ItemType.ERC20 && !tokenAddress) {
setContractAddressError('Please enter the contract address for the ERC20');
}
if (!id ||
!collectionAddress ||
!amount ||
!listingType ||
(listingType === ItemType.ERC20 && !contractAddress)) {
(listingType === ItemType.ERC20 && !tokenAddress)) {
return;
}
if (!checkout) {
Expand Down Expand Up @@ -191,7 +191,7 @@ export default function Sell({ checkout, provider }: SellProps) {
{listingType === ItemType.ERC20 && <td>
<FormControl validationStatus={contractAddressError ? 'error' : 'success'}>
<TextInput
value={contractAddress}
value={tokenAddress}
disabled={disableContractAddress}
onChange={(event: any) => {
setContractAddress(event.target.value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const SmartCheckoutForm = ({ checkout, provider }: SmartCheckoutProps) =>
const [amountError, setAmountError] = useState<string>('');
const [id, setId] = useState<string>('');
const [idError, setIdError] = useState<string>('');
const [contractAddress, setContractAddress] = useState<string>('');
const [tokenAddress, setContractAddress] = useState<string>('');
const [contractAddressError, setContractAddressError] = useState<string>('');
const [spenderAddress, setSpenderAddress] = useState<string>('');
const [spenderAddressError, setSpenderAddressError] = useState<string>('');
Expand Down Expand Up @@ -121,7 +121,7 @@ export const SmartCheckoutForm = ({ checkout, provider }: SmartCheckoutProps) =>
gasToken: {
type: GasTokenType.ERC20,
limit: BigNumber.from(gasLimit),
contractAddress: gasContractAddress,
tokenAddress: gasContractAddress,
}
});
}
Expand Down Expand Up @@ -174,20 +174,20 @@ export const SmartCheckoutForm = ({ checkout, provider }: SmartCheckoutProps) =>
if (!amount) {
setAmountError('Amount is required for ERC20 token');
}
if (!contractAddress) {
if (!tokenAddress) {
setContractAddressError('Contract address is required for ERC20 token');
}
if (!spenderAddress) {
setSpenderAddressError('Spender address is required for ERC20 token');
}
if (!amount || !contractAddress || !spenderAddress) {
if (!amount || !tokenAddress || !spenderAddress) {
return;
}

updateItemRequirements({
type: ItemType.ERC20,
amount,
contractAddress,
tokenAddress,
spenderAddress,
});
}
Expand All @@ -196,19 +196,19 @@ export const SmartCheckoutForm = ({ checkout, provider }: SmartCheckoutProps) =>
if (!id) {
setIdError('ID is required for ERC721 token');
}
if (!contractAddress) {
if (!tokenAddress) {
setContractAddressError('Contract address is required for ERC721 token');
}
if (!spenderAddress) {
setSpenderAddressError('Spender address is required for ERC721 token');
}
if (!id || !contractAddress || !spenderAddress) {
if (!id || !tokenAddress || !spenderAddress) {
return;
}
updateItemRequirements({
type: ItemType.ERC721,
id,
contractAddress,
tokenAddress,
spenderAddress,
});
}
Expand Down Expand Up @@ -248,7 +248,7 @@ export const SmartCheckoutForm = ({ checkout, provider }: SmartCheckoutProps) =>
<td>{item.type}</td>
<td>{item.amount}</td>
<td></td>
<td>{item.contractAddress}</td>
<td>{item.tokenAddress}</td>
<td>{item.spenderAddress}</td>
</tr>
);
Expand All @@ -258,7 +258,7 @@ export const SmartCheckoutForm = ({ checkout, provider }: SmartCheckoutProps) =>
<td>{item.type}</td>
<td></td>
<td>{item.id}</td>
<td>{item.contractAddress}</td>
<td>{item.tokenAddress}</td>
<td>{item.spenderAddress}</td>
</tr>
)
Expand Down Expand Up @@ -375,7 +375,7 @@ export const SmartCheckoutForm = ({ checkout, provider }: SmartCheckoutProps) =>
<td>
<FormControl validationStatus={contractAddressError ? 'error' : 'success'}>
<TextInput
value={contractAddress}
value={tokenAddress}
disabled={disableContractAddress}
onChange={(event: any) => {
setContractAddress(event.target.value);
Expand Down
6 changes: 3 additions & 3 deletions packages/checkout/sdk/src/balances/balances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ export const getBalance = async (
export async function getERC20Balance(
web3Provider: Web3Provider,
walletAddress: string,
contractAddress: string,
tokenAddress: string,
) {
return await withCheckoutError<GetBalanceResult>(
async () => {
const contract = new Contract(
contractAddress,
tokenAddress,
JSON.stringify(ERC20ABI),
web3Provider,
);
Expand All @@ -81,7 +81,7 @@ export async function getERC20Balance(
name,
symbol,
decimals,
address: contractAddress,
address: tokenAddress,
},
} as GetBalanceResult;
});
Expand Down
2 changes: 1 addition & 1 deletion packages/checkout/sdk/src/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ describe('Connect', () => {
await checkout.getBalance({
provider,
walletAddress: '0x123',
contractAddress: '0x456',
tokenAddress: '0x456',
} as GetBalanceParams);

expect(getBalance).toBeCalledTimes(0);
Expand Down
4 changes: 2 additions & 2 deletions packages/checkout/sdk/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export class Checkout {
params.provider,
);

if (!params.contractAddress || params.contractAddress === '') {
if (!params.tokenAddress || params.tokenAddress === '') {
return await balances.getBalance(
this.config,
web3Provider,
Expand All @@ -239,7 +239,7 @@ export class Checkout {
return await balances.getERC20Balance(
web3Provider,
params.walletAddress,
params.contractAddress,
params.tokenAddress,
);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/checkout/sdk/src/smartCheckout/fees/fees.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { CheckoutErrorType } from '../../errors';
jest.mock('../../instance');
jest.mock('../actions');

describe.only('orderbook fees', () => {
describe('orderbook fees', () => {
it('should calculate the fees as a percentageDecimal', async () => {
const decimals = 18;
const amount = utils.parseUnits('10', 18).toString();
Expand Down
4 changes: 2 additions & 2 deletions packages/checkout/sdk/src/types/balances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import { TokenInfo } from './tokenInfo';
* Interface representing the parameters for {@link Checkout.getBalance}.
* @property {Web3Provider} provider - The provider used to get the balance.
* @property {string} walletAddress - The wallet address.
* @property {string | undefined} contractAddress - The contract address of the token.
* @property {string | undefined} tokenAddress - The contract address of the token.
*/
export interface GetBalanceParams {
provider: Web3Provider;
walletAddress: string;
contractAddress?: string;
tokenAddress?: string;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { WalletProviderName } from '../../../types';

/**
* Bridge Widget parameters
* @property {string | undefined} contractAddress
* @property {string | undefined} tokenAddress
* @property {string | undefined} amount
* @property {WalletProviderName | undefined} walletProviderName
*/
export type BridgeWidgetParams = {
/** The contract address of the token to bridge from, used to populate the bridge form token field */
contractAddress?: string;
tokenAddress?: string;
/** The formatted amount to bridge, used to populate the bridge form amount field */
amount?: string;
/** The wallet provider name to use for the bridge widget */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { WalletProviderName } from '../../../types';
/**
* OnRamp Widget parameters
* @property {string | undefined} contractAddress
* @property {string | undefined} tokenAddress
* @property {string | undefined} amount
* @property {WalletProviderName | undefined} walletProviderName
*/
export type OnRampWidgetParams = {
/** The contract address of the token to onramp */
contractAddress?: string;
tokenAddress?: string;
/** The formatted amount to onramp, used to populate the onramp form amount field */
amount?: string;
/** The wallet provider name to use for the onramp widget */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import { WalletProviderName } from '../../../types';
* Sale Widget parameters
* @property {string} amount
* @property {string} environmentId
* @property {string} fromContractAddress
* @property {string} fromTokenAddress
* @property {SaleItem[]} items
* @property {WalletProviderName | undefined} walletProviderName
*/
export type SaleWidgetParams = {
/** The total price to pay for the items in the sale */
amount?: string;
environmentId?: string;
fromContractAddress?: string;
fromTokenAddress?: string;
/** The list of products to be purchased */
items?: SaleItem[];
/** The wallet provider name to default to if no web3Provider is passed */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import { WalletProviderName } from '../../../types';
/**
* Swap Widget parameters
* @property {string | undefined} amount
* @property {string | undefined} fromContractAddress
* @property {string | undefined} toContractAddress
* @property {string | undefined} fromTokenAddress
* @property {string | undefined} toTokenAddress
* @property {WalletProviderName | undefined} walletProviderName
*/
export type SwapWidgetParams = {
/** The formatted amount to swap, used to populate the swap from amount field */
amount?: string;
/** The contract address of the token to swap from */
fromContractAddress?: string;
fromTokenAddress?: string;
/** The contract address of the token to swap to */
toContractAddress?: string;
toTokenAddress?: string;
/** The wallet provider name to use for the swap widget */
walletProviderName?: WalletProviderName;
};
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ export interface OnRampFailView extends ViewType {
}
interface PrefilledOnRampData {
amount?: string;
contractAddress?: string;
tokenAddress?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ export interface ApproveERC20SwapData {
}
export interface PrefilledSwapForm {
fromAmount: string;
fromContractAddress: string;
toContractAddress: string;
fromTokenAddress: string;
toTokenAddress: string;
}
8 changes: 4 additions & 4 deletions packages/checkout/widgets-lib/src/views/top-up/TopUpView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ export function TopUpView({
const onClickSwap = () => {
if (widgetEvent === IMTBLWidgetEvents.IMTBL_SWAP_WIDGET_EVENT) {
const data = {
toContractAddress: '',
toTokenAddress: '',
fromAmount: '',
fromContractAddress: '',
fromTokenAddress: '',
};

viewDispatch({
Expand Down Expand Up @@ -175,7 +175,7 @@ export function TopUpView({
const onClickBridge = () => {
if (widgetEvent === IMTBLWidgetEvents.IMTBL_BRIDGE_WIDGET_EVENT) {
const data = {
fromContractAddress: '',
fromTokenAddress: '',
fromAmount: '',
};

Expand Down Expand Up @@ -203,7 +203,7 @@ export function TopUpView({
const onClickOnRamp = () => {
if (widgetEvent === IMTBLWidgetEvents.IMTBL_ONRAMP_WIDGET_EVENT) {
const data = {
contractAddress: '',
tokenAddress: '',
amount: '',
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function BridgeWidget({
web3Provider,
config,
amount,
contractAddress,
tokenAddress,
}: BridgeWidgetInputs) {
const {
environment,
Expand Down Expand Up @@ -168,7 +168,7 @@ export function BridgeWidget({
<WalletNetworkSelectionView />
)}
{viewState.view.type === BridgeWidgetViews.BRIDGE_FORM && (
<Bridge amount={amount} contractAddress={contractAddress} />
<Bridge amount={amount} tokenAddress={tokenAddress} />
)}
{viewState.view.type === BridgeWidgetViews.BRIDGE_REVIEW && (
<BridgeReview />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ export class Bridge extends Base<WidgetType.BRIDGE> {
validatedParams.amount = '';
}

if (!isValidAddress(params.contractAddress)) {
if (!isValidAddress(params.tokenAddress)) {
// eslint-disable-next-line no-console
console.warn('[IMTBL]: invalid "contractAddress" widget input');
validatedParams.contractAddress = '';
console.warn('[IMTBL]: invalid "tokenAddress" widget input');
validatedParams.tokenAddress = '';
}

return validatedParams;
Expand All @@ -63,7 +63,7 @@ export class Bridge extends Base<WidgetType.BRIDGE> {
checkout={this.checkout}
config={this.strongConfig()}
web3Provider={this.web3Provider}
contractAddress={this.parameters.contractAddress}
tokenAddress={this.parameters.tokenAddress}
amount={this.parameters.amount}
walletProviderName={this.parameters.walletProviderName}
/>
Expand Down
Loading

0 comments on commit ab1736f

Please sign in to comment.