Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link lift n shift #1691

Draft
wants to merge 5 commits into
base: link-migration
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion packages/x-link/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
testEnvironment: 'node',
testEnvironment: 'jsdom',
moduleDirectories: ['node_modules', '<rootDir>/src'],
modulePathIgnorePatterns: ['<rootDir>/dist/', '<rootDir>/backup/'],
testRegex: '^.+\\.test\\.(js|ts|jsx|tsx)$',
Expand Down
4 changes: 3 additions & 1 deletion packages/x-link/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
"author": "Immutable",
"bugs": "https://github.com/immutable/ts-immutable-sdk/issues",
"dependencies": {
"@imtbl/imx-sdk": "^3.8.0"
"qs": "^6.12.1",
"query-string": "^7.1.3"
},
"devDependencies": {
"@rollup/plugin-typescript": "^11.0.0",
"@swc/jest": "^0.2.24",
"@testing-library/jest-dom": "^5.16.5",
"@types/jest": "^29.4.3",
"eslint": "^8.40.0",
"jest": "^29.4.3",
Expand Down
8 changes: 8 additions & 0 deletions packages/x-link/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
export { LinkError } from './sdk-types';
export * from './link';
export {
Params as LinkParams,
Results as LinkResults,
ERC20TokenType,
ERC721TokenType,
ETHTokenType,
} from './types';
5 changes: 5 additions & 0 deletions packages/x-link/src/libs/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum LocalStorageKeys {
WALLET_ADDRESS = 'WALLET_ADDRESS',
STARK_PUBLIC_KEY = 'STARK_PUBLIC_KEY',
PROVIDER_PREFERENCE = 'PROVIDER_PREFERENCE',
}
1 change: 1 addition & 0 deletions packages/x-link/src/libs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './constants';
4 changes: 3 additions & 1 deletion packages/x-link/src/link.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Link as OldLink, ConfigurableIframeOptions } from '@imtbl/imx-sdk';
// import { Link as OldLink, ConfigurableIframeOptions } from '@imtbl/imx-sdk';
import { Link as OldLink } from './sdk';
import { ConfigurableIframeOptions } from './sdk-types';

import { Params, Results } from './types';

Expand Down
26 changes: 26 additions & 0 deletions packages/x-link/src/sdk-types/iframe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export type IframePositionKeys = 'left' | 'right' | 'top' | 'bottom';

export type IframePositionOptions = {
[key in IframePositionKeys]?: string;
};

export type IframeSizeOptions = {
width: number;
height: number;
};

export type FullIframeOptions = {
size: IframeSizeOptions;
position: IframePositionOptions;
className: string;
containerElement: HTMLElement;
protectAgainstGlobalStyleBleed: boolean;
hidden?: boolean;
};

export type ConfigurableIframeOptions = null | {
position?: IframePositionOptions;
className?: string;
containerElement?: HTMLElement;
protectAgainstGlobalStyleBleed?: boolean;
};
6 changes: 6 additions & 0 deletions packages/x-link/src/sdk-types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export * from './iframe';
export * from './runtime';
export * from './messages';
export * from './static';
export * from './routes';
export * from './info-events';
24 changes: 24 additions & 0 deletions packages/x-link/src/sdk-types/info-events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* WT-1001
* These info events are dispatched by the SDK for Marketplaces and other applications which use Link, to listen to.
* This has been designed in conjunction with the postMessage messageType.info that Link can fire to pass
* data back to it's parent window (without closing Link itself).
*/
export const LINK_INFO_MESSAGE_TYPE = 'imx-link-info';

export enum ImxLinkInfoEventType {
WALLET_CONNECTION = 'wallet-connection',
}

export type InfoEvent<T> = {
type: ImxLinkInfoEventType;
payload?: T;
};

export interface WalletConnectionInfoEvent {
walletAddress: string;
starkPublicKey: string;
providerPreference: string;
email: string;
ethNetwork: string;
}
18 changes: 18 additions & 0 deletions packages/x-link/src/sdk-types/messages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export const LINK_MESSAGE_TYPE = 'imx-link';
export const messageTypes = {
inProgress: 'inProgress',
success: 'success',
fail: 'fail',
result: 'result',
close: 'close',
ready: 'ready',
transfer: 'transfer',
batchNftTransfer: 'batchNftTransfer',
sign: 'sign',
getPublicKey: 'getPublicKey',
// Triggered by the parent window for the parent window itself when a new
// subscriber to link events is registered. Used to make sure there's always
// only one subscriber to a Link window.
newSubscriber: 'newSubscriber',
info: 'info',
};
33 changes: 33 additions & 0 deletions packages/x-link/src/sdk-types/routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* eslint-disable @typescript-eslint/naming-convention */
export enum Routes {
'Home' = 'home',
'Setup' = 'setup',
'Buy' = 'buy',
'BuyV2' = 'v2/buy',
'Sell' = 'sell',
'Deposit' = 'deposit',
'History' = 'history',
'PrepareWithdrawal' = 'prepare-withdrawal',
'CompleteWithdrawal' = 'complete-withdrawal',
'Transfer' = 'transfer',
'TransferV2' = 'v2/transfer',
'BatchNftTransfer' = 'batch-nft-transfer',
'Sign' = 'sign',
'GetPublicKey' = 'get-public-key',
'Cancel' = 'cancel',
'Claim' = 'claim',
'ClaimUSInstant' = 'claim-instant',
'ClaimUSOverTime' = 'claim-over-time',
'ClaimUSOverTimeDetails' = 'claim-over-time-details',
'FiatToCrypto' = 'fiat-to-crypto',
'CryptoToFiat' = 'crypto-to-fiat',
'Offramp' = 'offramp',
'Onramp' = 'onramp',
'NFTCheckoutPrimary' = 'nft-checkout-primary',
'NFTCheckoutSecondary' = 'nft-checkout-secondary',
'MakeOffer' = 'make-offer',
'CancelOffer' = 'cancel-offer',
'AcceptOffer' = 'accept-offer',
}

export const messagingUrls = [Routes.BatchNftTransfer, Routes.Sign];
20 changes: 20 additions & 0 deletions packages/x-link/src/sdk-types/runtime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export enum ERC721TokenType {
ERC721 = 'ERC721',
}

export interface FeeType {
recipient: string;
/**
* Percentage truncated to 2 d.p.
* 10.24 = 10.24%
*/
percentage: number;
}

export enum ETHTokenType {
ETH = 'ETH',
}

export enum ERC20TokenType {
ERC20 = 'ERC20',
}
6 changes: 6 additions & 0 deletions packages/x-link/src/sdk-types/static.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export class LinkError extends Error {
constructor(public code: number, message?: string) {
super(message ?? '');
Object.setPrototypeOf(this, LinkError.prototype);
}
}
Loading
Loading